-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui-test.py
64 lines (55 loc) · 2.3 KB
/
ui-test.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
"""
A simple selenium test example demonstrating docker container usage.
Thanks to @joyzoursky for the test script https://github.com/joyzoursky/docker-python-chromedriver
"""
import unittest
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.common.exceptions import NoSuchElementException
import os.path
import subprocess
from subprocess import PIPE
import time
class TestTemplate(unittest.TestCase):
@classmethod
def setUpClass(self):
"""Start web driver and start the docker container"""
p = subprocess.Popen(['docker-compose', '-p ui_test', 'up', '-d'])
time.sleep(5)
p.wait()
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument("--disable-setuid-sandbox")
"""uncomment below for running in headless mode"""
"""chrome_options.add_argument('--headless')"""
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument("--disable-extensions")
"""selenium docker container is set to run on port 1111"""
self.driver = webdriver.Remote(desired_capabilities=chrome_options.to_capabilities(), command_executor='http://localhost:1111/wd/hub')
self.driver.implicitly_wait(10)
@classmethod
def tearDownClass(self):
"""Stop web driver and remove the docker container"""
self.driver.quit()
p = subprocess.Popen(['sh', './clean.sh'])
time.sleep(5)
p.wait()
def test_case_1(self):
"""Find and click top-right button"""
try:
self.driver.get('https://www.oursky.com/')
el = self.driver.find_element_by_class_name('btn-header')
el.click()
except NoSuchElementException as ex:
self.fail(ex.msg)
def test_case_2(self):
"""Find and click Learn more button"""
try:
self.driver.get('https://www.oursky.com/')
el = self.driver.find_element_by_xpath(".//*[@id='tag-line-wrap']/span/a")
el.click()
except NoSuchElementException as ex:
self.fail(ex.msg)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestTemplate)
unittest.TextTestRunner(verbosity=2).run(suite)