forked from vstconsulting/vstutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselenium_tests.py
67 lines (62 loc) · 2.4 KB
/
selenium_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from time import sleep
from django.test import LiveServerTestCase
from django.contrib.auth import get_user_model
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common import exceptions
class SeleniumTestCase(LiveServerTestCase):
host = 'localhost'
port = 8888
def setUp(self):
options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-gpu")
options.add_argument("--incognito")
options.add_argument("--disable-extensions")
self.selenium = webdriver.Chrome(options=options)
self.selenium.set_window_size(1280, 3240)
User = get_user_model()
self.user = User.objects.create_superuser('admin', '[email protected]', 'admin')
super(SeleniumTestCase, self).setUp()
def tearDown(self):
self.selenium.save_screenshot('test_screenshot.png')
self.selenium.quit()
super(SeleniumTestCase, self).tearDown()
def test_qunit(self):
selenium = self.selenium
# Opening the link we want to test
selenium.get('http://localhost:8888/')
login = selenium.find_element_by_name('username')
login.send_keys('admin')
password = selenium.find_element_by_name('password')
password.send_keys('admin')
submit = selenium.find_element_by_id('login_button')
submit.send_keys(Keys.RETURN)
trys = 40
for i in range(trys):
try:
selenium.execute_script('window.loadQUnitTests()')
trys = 300
break
except exceptions.WebDriverException:
log_data = selenium.get_log('browser')
if log_data:
print(log_data)
sleep(1)
trys -= 1
finally:
self.assertTrue(trys > 0, trys)
saveReportObj = None
for _ in range(900):
try:
saveReportObj = selenium.find_element_by_id('qunit-saveReport')
except exceptions.NoSuchElementException:
log_data = selenium.get_log('browser')
if log_data:
print(log_data)
sleep(1)
else:
break
self.assertNotEqual(saveReportObj, None)