0

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"]')))
furas
  • 134,197
  • 12
  • 106
  • 148

1 Answers1

0

The problem is that your number contains a comma, as well as a decimal dot. Python can't parse it that easily.

As suggested in this Thread you can either replace the comma hard with str = str.replace(',','') or you handle your localization correctly via locale (example)

If you comment out your lines you don't get as high a price, that's why the problem seems to disappear, but it doesn't have anything to do with the code of those lines

As others have pointed out: Please don't use predefined symbols as variable names. You are currently overwriting the str function with your code. If you use more speaking variables it will also be easier to understand what your code is supposed to do.

NationBoneless
  • 308
  • 2
  • 12