Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.33 KB | None | 0 0
  1. import pytest
  2. from selenium import webdriver
  3.  
  4. expected_title = 'Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more'
  5. base_url = 'https://www.amazon.com'
  6. search_title = 'Amazon.com: nike air max'
  7.  
  8. @pytest.fixture()
  9. def env_setup():
  10.     global driver
  11.     global baseUrl
  12.     # we will use Google Chrome in this test. Specify the location of your chromedriver.exe
  13.     driver = webdriver.Chrome("C:\\Users\\yivanov\\Downloads\\chromedriver_win32_76\\chromedriver.exe")
  14.     # maximize browser window to full screen
  15.     driver.maximize_window()
  16.     # wait for 10 seconds till the web page will load
  17.     driver.implicitly_wait(10)
  18.     yield
  19.     # when test is done, close ALL windows of the browser
  20.     driver.quit()
  21.  
  22. def test_empty_cart(env_setup):
  23.     # navigate to Amazon.com home page
  24.     driver.get(base_url)
  25.     # verify that website title is Amazon.com
  26.     assert expected_title == driver.title
  27.     # locate search field element
  28.     search_field = driver.find_element_by_id("twotabsearchtextbox")
  29.     # enter "nike air max" in the search field
  30.     search_field.send_keys("nike air max")
  31.     # locate search button
  32.     search_button = driver.find_element_by_xpath("//input[@value='Go']")
  33.     # click on 'Search' icon
  34.     search_button.click()
  35.     # verify the page title
  36.     assert search_title == driver.title
  37.     # verify the cart is empty. the number of items is 0
  38.     assert "0" == driver.find_element_by_id("nav-cart-count").text
  39.  
  40.     # select Nike Air Max 270
  41.     select_nike_air_max_270 = driver.find_element_by_xpath(".//span[contains(text(), 'Nike Air Max 270')]").click()
  42.     # click on size Drop Down menu
  43.     size_dropdown = driver.find_element_by_xpath("//span[@class='a-dropdown-prompt'][contains(text(),'Select')]").click()
  44.     # select '11' size
  45.     select_size = driver.find_element_by_xpath("//a[@id='native_dropdown_selected_size_name_8']").click()
  46.     # click on 'add to cart'
  47.     click_add_to_cart = driver.find_element_by_xpath("//input[@id='add-to-cart-button']").click()
  48.  
  49.     # verify the number of items is changed from 0 to 1 in the cart
  50.     assert "1" == driver.find_element_by_id("nav-cart-count").text
  51.     # verify "Added to Cart" message is displayed on the screen
  52.     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