- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathlong_messy_raw.py
97 lines (91 loc) · 3.78 KB
/
long_messy_raw.py
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""Long & Messy Raw Selenium Example - (ONLY Selenium / NO SeleniumBase)"""
importsys
fromseleniumimportwebdriver
fromselenium.webdriver.chrome.serviceimportService
fromselenium.webdriver.common.byimportBy
fromselenium.webdriver.supportimportexpected_conditionsasEC
fromselenium.webdriver.support.uiimportWebDriverWait
fromunittestimportTestCase
classLongMessyRawSelenium(TestCase):
defsetUp(self):
self.driver=None
options=webdriver.ChromeOptions()
options.add_argument("--disable-notifications")
if"linux"insys.platform:
options.add_argument("--headless=new")
options.add_experimental_option(
"excludeSwitches", ["enable-automation", "enable-logging"],
)
prefs= {
"credentials_enable_service": False,
"profile.password_manager_enabled": False,
}
options.add_experimental_option("prefs", prefs)
service=Service(service_args=["--disable-build-check"])
self.driver=webdriver.Chrome(options=options, service=service)
deftearDown(self):
ifself.driver:
try:
ifself.driver.service.process:
self.driver.quit()
exceptException:
pass
deftest_add_item_to_cart(self):
self.driver.get("https://www.saucedemo.com")
by_css=By.CSS_SELECTOR# "css selector"
element=WebDriverWait(self.driver, 10).until(
EC.element_to_be_clickable((by_css, "#user-name"))
)
element.clear()
element.send_keys("standard_user")
element=WebDriverWait(self.driver, 10).until(
EC.element_to_be_clickable((by_css, "#password"))
)
element.clear()
element.send_keys("secret_sauce")
element.submit()
WebDriverWait(self.driver, 10).until(
EC.visibility_of_element_located((by_css, "div.inventory_list"))
)
element=WebDriverWait(self.driver, 10).until(
EC.visibility_of_element_located((by_css, "span.title"))
)
self.assertEqual(element.text, "Products")
element=WebDriverWait(self.driver, 10).until(
EC.element_to_be_clickable((by_css, 'button[name*="backpack"]'))
)
element.click()
element=WebDriverWait(self.driver, 10).until(
EC.element_to_be_clickable((by_css, "#shopping_cart_container a"))
)
element.click()
element=WebDriverWait(self.driver, 10).until(
EC.visibility_of_element_located((by_css, "span.title"))
)
self.assertEqual(element.text, "Your Cart")
element=WebDriverWait(self.driver, 10).until(
EC.visibility_of_element_located((by_css, "div.cart_item"))
)
self.assertIn("Backpack", element.text)
element=WebDriverWait(self.driver, 10).until(
EC.element_to_be_clickable((by_css, "#remove-sauce-labs-backpack"))
)
element.click()
WebDriverWait(self.driver, 10).until(
EC.invisibility_of_element((by_css, "div.cart_item"))
)
element=WebDriverWait(self.driver, 10).until(
EC.element_to_be_clickable((by_css, "#react-burger-menu-btn"))
)
element.click()
element=WebDriverWait(self.driver, 10).until(
EC.element_to_be_clickable((by_css, "a#logout_sidebar_link"))
)
element.click()
WebDriverWait(self.driver, 10).until(
EC.visibility_of_element_located((by_css, "input#login-button"))
)
# When run with "python" instead of "pytest" or "python -m unittest"
if__name__=="__main__":
fromunittestimportmain
main()