- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathflaky_messy_raw.py
73 lines (66 loc) · 2.94 KB
/
flaky_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
"""Flaky Raw Selenium Example - (ONLY Selenium / NO SeleniumBase)"""
importsys
fromseleniumimportwebdriver
fromselenium.webdriver.chrome.serviceimportService
fromselenium.webdriver.common.byimportBy
fromunittestimportTestCase
classFlakyMessyRawSelenium(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
defis_element_visible(self, selector, by="css selector"):
try:
element=self.driver.find_element(by, selector)
ifelement.is_displayed():
returnTrue
exceptException:
pass
returnFalse
deftest_add_item_to_cart(self):
self.driver.get("https://www.saucedemo.com")
by_css=By.CSS_SELECTOR# "css selector"
element=self.driver.find_element(by_css, "#user-name")
element.clear()
element.send_keys("standard_user")
element=self.driver.find_element(by_css, "#password")
element.clear()
element.send_keys("secret_sauce")
element.submit()
self.driver.find_element(by_css, "div.inventory_list")
element=self.driver.find_element(by_css, "span.title")
self.assertEqual(element.text, "Products")
self.driver.find_element(by_css, 'button[name*="backpack"]').click()
self.driver.find_element(by_css, "#shopping_cart_container a").click()
element=self.driver.find_element(by_css, "span.title")
self.assertEqual(element.text, "Your Cart")
element=self.driver.find_element(by_css, "div.cart_item")
self.assertIn("Backpack", element.text)
self.driver.find_element(by_css, "#remove-sauce-labs-backpack").click()
self.assertFalse(self.is_element_visible("div.cart_item"))
self.driver.find_element(by_css, "#react-burger-menu-btn").click()
self.driver.find_element(by_css, "a#logout_sidebar_link").click()
self.driver.find_element(by_css, "input#login-button")
# When run with "python" instead of "pytest" or "python -m unittest"
if__name__=="__main__":
fromunittestimportmain
main()