-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtests.py
53 lines (40 loc) · 1.76 KB
/
tests.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
import os
from channels.testing import ChannelsLiveServerTestCase
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.ui import WebDriverWait
class TestIdomCapabilities(ChannelsLiveServerTestCase):
def setUp(self):
self.driver = make_driver(5, 5)
self.driver.get(self.live_server_url)
def tearDown(self) -> None:
self.driver.quit()
def wait(self, timeout=10):
return WebDriverWait(self.driver, timeout)
def wait_until(self, condition, timeout=10):
return self.wait(timeout).until(lambda driver: condition())
def test_hello_world(self):
self.driver.find_element_by_id("hello-world")
def test_counter(self):
button = self.driver.find_element_by_id("counter-inc")
count = self.driver.find_element_by_id("counter-num")
for i in range(5):
self.wait_until(lambda: count.get_attribute("data-count") == str(i))
button.click()
def test_parametrized_component(self):
element = self.driver.find_element_by_id("parametrized-component")
self.assertEqual(element.get_attribute("data-value"), "579")
def test_component_from_web_module(self):
self.wait(20).until(
expected_conditions.visibility_of_element_located(
(By.CLASS_NAME, "VictoryContainer")
)
)
def make_driver(page_load_timeout, implicit_wait_timeout):
options = webdriver.ChromeOptions()
options.headless = bool(int(os.environ.get("SELENIUM_HEADLESS", 0)))
driver = webdriver.Chrome(options=options)
driver.set_page_load_timeout(page_load_timeout)
driver.implicitly_wait(implicit_wait_timeout)
return driver