forked from careerist-qa/python-selenium-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathamazon_locators_XPATH_L02.py
More file actions
75 lines (67 loc) · 2.89 KB
/
amazon_locators_XPATH_L02.py
File metadata and controls
75 lines (67 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from time import sleep
# get the path to the ChromeDriver executable
driver_path = ChromeDriverManager().install()
# create a new Chrome browser instance
service = Service(driver_path)
driver = webdriver.Chrome()
driver.maximize_window()
# open the url
#driver.get('https://www.amazon.com/')
#Amazon Logo
#driver.find_element("//a[@class='nav-logo-link nav-progressive-attribute']")
##Email Field
#driver.find_element("//input[@type='email' and @id='ap_email']")
##Continue Button
#driver.find_element("//input[@type='submit' and @id='continue']")
##Conditions of Use link
#driver.find_element("//*[@id='legalTextRow']/a[1]")
#driver.find_element("//a[contains(@href, 'ap_signin_notification_condition_of_use')]")
#driver.find_element("//div[@id='legalTextRow']//a[text()='Conditions of Use']")
##Privacy Notice Link
#driver.find_element("//*[@id='legalTextRow']/a[2]")
#driver.find_element("//a[contains@href, 'ap-signin-notification_privacy_notice']")
#driver.find_element("//div[@id='legalTextRow']//a[text()='Privacy Notice']")
##Need Help Link
#driver.find_element("//span[@class='a-expander-prompt']")
##Forgot Your Password Link
#driver.find_element("//a[@id='auth-fpp-link-bottom']")
##Other Issues With Sign-In Link
#driver.find_element("//a[@id='ap-other-signin-issues-link']")
##Create Your Amazon Account Button
#driver.find_element("//a[@id='createAccountSubmit']")
###
#Create Test Case for Sign-In Page
driver.get('https://www.target.com/')
#Click top right sign-in icon)
driver.find_element(By.XPATH, "//*[@data-test='@web/AccountLink']").click()
#driver.find_element(By.XPATH, "//span[@class='sc-58ad44c0-3 cOUViz h-margin-r-x3']").click()
sleep(2)
#Open Side Navigation (Sign-In Button)
driver.find_element(By.XPATH, "//*[@data-test='accountNav-signIn']").click()
sleep(2)
#Go to login page
driver.find_element(By.XPATH, "//span[text()='Sign into your Target account']")
#Validate successful login
expected = 'Sign into your Target account'
actual = driver.find_element(By.XPATH, "//h1[contains(@class, 'styles_ndsHeading')]").text
assert expected == actual, f'Expected {expected} did not match actual {actual}'
print('Test Case Passed')
###
##Create Test Case to Search for Product on Target
# open the url
driver.get('https://www.target.com/')
driver.find_element(By.ID, 'search').send_keys('umbrella')
driver.find_element(By.XPATH, "//button[@data-test='@web/Search/SearchButton']").click()
sleep(5)
# verification
driver.find_element(By.XPATH, "//div[@data-test='lp-resultsCount']")
# by checking text
actual_text = driver.find_element(By.XPATH, "//div[@data-test='lp-resultsCount']").text
expected_text = 'umbrella'
assert expected_text in actual_text, f'Error. Text {expected_text} not in {actual_text}'
print('test case passed')
driver.quit()