Steps to recreate:
1.Go to http://practice.automationtesting.in/
2.Click on add to basket
3.Then view basket
4.Change the quantity to 2
5.Click on Update Basket
6.Save price before coupon
6.Use coupon code "krishnasakinala"
7.Click on Apply Coupon button
8.save price after coupon is applied
9. strip both before and after coupon price of rupee symbol
10.convert to float and assert pricebeforecoupon > priceaftercoupon
Code:
from selenium import webdriver
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as W
from selenium.webdriver.support import expected_conditions as E
driver: WebDriver = webdriver.Chrome(executable_path=r"C:\Users\Ratna
Sinha\Downloads\chromedriver_win32\Chromedriver.exe")
driver.maximize_window()
url= "http://practice.automationtesting.in"
driver.get(url)
wait_timeout = 20
wait_variable = W(driver,wait_timeout)
driver.find_element_by_xpath("//a[@data-product_id='160']").click()
wait_variable.until(E.presence_of_element_located((By.XPATH,"//a[@class = 'added_to_cart wc-forward']"))).click()
wait_variable.until(E.presence_of_element_located((By.XPATH,"//input[@type='number']"))).clear()
wait_variable.until(E.presence_of_element_located((By.XPATH,"//input[@type='number']"))).send_keys(2)
wait_variable.until(E.element_to_be_clickable((By.NAME, "update_cart"))).click()
wait_variable.until(E.presence_of_element_located((By.CSS_SELECTOR,'[class="blockUI blockOverlay"]')))
wait_variable.until(E.staleness_of( driver.find_element_by_css_selector('[class="blockUI blockOverlay"]')))
pricebefcoupon = driver.find_element_by_xpath("//strong/span").text
driver.find_element_by_name("coupon_code").send_keys("krishnasakinala")
driver.find_element_by_name("apply_coupon").click()
wait_variable.until(E.presence_of_element_located((By.XPATH,"//div[@class='cart-collaterals']/div/div[@class ='blockUI blockOverlay']")))
wait_variable.until(E.staleness_of(driver.find_element_by_xpath("//div[@class='cart-collaterals']/div/div[@class ='blockUI blockOverlay']")))
priceafcoupon = driver.find_element_by_xpath("//strong/span").text
str = pricebefcoupon
str = str.strip('₹')
print(str)
str1 = priceafcoupon
str1 = str1.strip('₹')
print(str1)
assert float(str1) < float(str)
But If Im not updating the cart by commenting out the following code its working fine.
wait_variable.until(E.presence_of_element_located((By.XPATH,"//input[@type='number']"))).clear()
wait_variable.until(E.presence_of_element_located((By.XPATH,"//input[@type='number']"))).send_keys(2)
wait_variable.until(E.element_to_be_clickable((By.NAME, "update_cart"))).click()
wait_variable.until(E.presence_of_element_located((By.CSS_SELECTOR,'[class="blockUI
blockOverlay"]')))
wait_variable.until(E.staleness_of( driver.find_element_by_css_selector('[class="blockUI
blockOverlay"]')))