My whole script works until the last 2 lines where it fails.
# Your shopping cart is empty banner
emptyBanner = driver.find_element_by_xpath("/html/body/div/div[2]/div/div[3]/div/p").text
self.assertEqual(emptyBanner, "Your shopping cart is empty.", "The basket is not empty")
when stepping through the code while debugging, I can see a variable 'emptyBanner' of type String is created and 'Your shopping cart is empty.' is stored within it.
Then on the last line comparing the variable and then the string, it fails.
On the exception error, the expected result is blank, I don't understand where the string stored in the variable went?
Ran 1 test in 14.127s
FAILED (failures=1)
The basket is not empty
Your shopping cart is empty. !=
Expected :
Actual :Your shopping cart is empty.
I'm at a complete loss.
Here's the full code (im very new to coding/selenium):
from selenium import webdriver
from selenium.webdriver import ActionChains
import unittest
class Test(unittest.TestCase):
def testShoppingCart(self):
driver = webdriver.Chrome()
driver.get("http://automationpractice.com/index.php")
driver.maximize_window()
actions = ActionChains(driver)
# locators for Women and Summer Dresses in Nav Menu
Women = driver.find_element_by_xpath("/html/body/div/div[1]/header/div[3]/div/div/div[6]/ul/li[1]/a")
summerDresses = driver.find_element_by_xpath(
"/html/body/div/div[1]/header/div[3]/div/div/div[6]/ul/li[1]/ul/li[2]/ul/li[3]/a")
# select Summer Dresses from Nav Menu
actions.move_to_element(Women).move_to_element(summerDresses).click().perform()
driver.find_element_by_xpath("/html/body/div/div[2]/div/div[3]/div[2]/ul/li[1]").click() #click dress
driver.find_element_by_id("add_to_cart").click() #add dress to cart
driver.implicitly_wait(2)
driver.find_element_by_xpath("/html/body/div/div[1]/header/div[3]/div/div/div[4]/div[1]/div[2]/div[4]/a").click() #click proceed to checkout button
#checkout
driver.find_element_by_xpath("/html/body/div/div[2]/div/div[3]/div/p").is_displayed() #check to see if dress is in checkout
trashIcon = driver.find_element_by_class_name("icon-trash")
trashIcon.is_displayed() #check to see if delete button is displayed
trashIcon.click() #click delete icon
# Your shopping cart is empty banner
emptyBanner = driver.find_element_by_xpath("/html/body/div/div[2]/div/div[3]/div/p").text
self.assertEqual(emptyBanner, "Your shopping cart is empty.", "The basket is not empty")
if __name__ == '__main__':
unittest.main()
Aucun commentaire:
Enregistrer un commentaire