Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pytest
- from selenium import webdriver
- expected_title = 'Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more'
- base_url = 'https://www.amazon.com'
- search_title = 'Amazon.com: nike air max'
- @pytest.fixture()
- def env_setup():
- global driver
- global baseUrl
- # we will use Google Chrome in this test. Specify the location of your chromedriver.exe
- driver = webdriver.Chrome("C:\\Users\\yivanov\\Downloads\\chromedriver_win32_76\\chromedriver.exe")
- # maximize browser window to full screen
- driver.maximize_window()
- # wait for 10 seconds till the web page will load
- driver.implicitly_wait(10)
- yield
- # when test is done, close ALL windows of the browser
- driver.quit()
- def test_empty_cart(env_setup):
- # navigate to Amazon.com home page
- driver.get(base_url)
- # verify that website title is Amazon.com
- assert expected_title == driver.title
- # locate search field element
- search_field = driver.find_element_by_id("twotabsearchtextbox")
- # enter "nike air max" in the search field
- search_field.send_keys("nike air max")
- # locate search button
- search_button = driver.find_element_by_xpath("//input[@value='Go']")
- # click on 'Search' icon
- search_button.click()
- # verify the page title
- assert search_title == driver.title
- # verify the cart is empty. the number of items is 0
- assert "0" == driver.find_element_by_id("nav-cart-count").text
- # select Nike Air Max 270
- select_nike_air_max_270 = driver.find_element_by_xpath(".//span[contains(text(), 'Nike Air Max 270')]").click()
- # click on size Drop Down menu
- size_dropdown = driver.find_element_by_xpath("//span[@class='a-dropdown-prompt'][contains(text(),'Select')]").click()
- # select '11' size
- select_size = driver.find_element_by_xpath("//a[@id='native_dropdown_selected_size_name_8']").click()
- # click on 'add to cart'
- click_add_to_cart = driver.find_element_by_xpath("//input[@id='add-to-cart-button']").click()
- # verify the number of items is changed from 0 to 1 in the cart
- assert "1" == driver.find_element_by_id("nav-cart-count").text
- # verify "Added to Cart" message is displayed on the screen
- assert "Added to Cart" == driver.find_element_by_xpath("//h1[@class='a-size-medium a-text-bold']").text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement