Assertion to check whether the discount has applied or not
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
chrome_options = Options()
#chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-web-security')
chrome_options.add_experimental_option("detach", True)
service_obj= Service("C://Users//ancha//chromedriver_win32(4)//chromedriver.exe")
driver = webdriver.Chrome(service=service_obj, options=chrome_options)
driver.implicitly_wait(2)
driver.get("https://www.rahulshettyacademy.com/seleniumPractise")
driver.find_element(By.CSS_SELECTOR, ".search-keyword").send_keys("ber")
time.sleep(2)
products = driver.find_elements(By.XPATH, "//div[@class='products']/div")
count = len(products)
for product in products:
product.find_element(By.XPATH, "div/button").click()
driver.find_element(By.CSS_SELECTOR, "img[alt='Cart']").click()
driver.find_element(By.XPATH, "//button[text()='PROCEED TO CHECKOUT']").click()
# Sum validation
prices=driver.find_elements(By.XPATH,"//tr/td[5]/p")
sum=0
for price in prices:
sum=sum+ int(price.text)
print(sum)
totalAmount = int(driver.find_element(By.CSS_SELECTOR,".totAmt").text)
print(totalAmount)
assert sum == totalAmount
#with CSS SELECTOR it can be written as
#tr td:nth-child(5) p
driver.find_element(By.CSS_SELECTOR, ".promoCode").send_keys("rahulshettyacademy")
driver.find_element(By.CSS_SELECTOR, ".promoBtn").click()
wait= WebDriverWait(driver,10)
wait.until(expected_conditions.presence_of_element_located((By.CSS_SELECTOR,".promoinfo")))
print(driver.find_element(By.CLASS_NAME, "promoInfo").text)
disctdAmt = float(driver.find_element(By.CSS_SELECTOR, ".discountAmt").text)
assert totalAmount >disctdAmt
Comments
Post a Comment