-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
51 lines (37 loc) · 1.47 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
import os
import pathlib
import unittest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
def file_uri(filename):
return pathlib.Path(os.path.abspath(filename)).as_uri()
# driver = webdriver.Firefox()
class WebpageTests(unittest.TestCase):
def setUp(self):
chrome_options = Options()
chrome_options.add_argument("--headless")
self.driver = webdriver.Chrome(options=chrome_options)
def test_title(self):
self.driver.get(file_uri("counter.html"))
self.assertEqual(self.driver.title, "Counter")
def test_increase(self):
self.driver.get(file_uri("counter.html"))
increase = self.driver.find_element_by_id("increase")
increase.click()
self.assertEqual(self.driver.find_element_by_tag_name("h1").text, "1")
def test_decrease(self):
self.driver.get(file_uri("counter.html"))
decrease = self.driver.find_element_by_id("decrease")
decrease.click()
self.assertEqual(self.driver.find_element_by_tag_name("h1").text, "-1")
def test_multiple_increase(self):
self.driver.get(file_uri("counter.html"))
increase = self.driver.find_element_by_id("increase")
for i in range(3):
increase.click()
self.assertEqual(self.driver.find_element_by_tag_name("h1").text, "3")
def tearDown(self):
self.driver.stop_client()
self.driver.quit()
if __name__ == "__main__":
unittest.main()