1 | #!/usr/bin/python3 |
---|
2 | try: |
---|
3 | import unittest2 as unittest #for Python <= 2.6 |
---|
4 | except: |
---|
5 | import unittest |
---|
6 | |
---|
7 | import urllib3 |
---|
8 | import subprocess |
---|
9 | import os.path |
---|
10 | import os |
---|
11 | |
---|
12 | from selenium import webdriver |
---|
13 | |
---|
14 | URL_ROOT = 'http://127.0.0.1:8000' |
---|
15 | #URL_APP = os.path.basename(os.getcwd()) |
---|
16 | #URL_ROOT = 'https://tkdgescamp.com' |
---|
17 | URL_APP = 'rlabs' |
---|
18 | |
---|
19 | |
---|
20 | class BaseTest(unittest.TestCase): |
---|
21 | |
---|
22 | @classmethod |
---|
23 | def setUpClass(self): |
---|
24 | #self.web2py = start_web2py_server() |
---|
25 | print("set driver") |
---|
26 | self.browser = webdriver.Firefox() |
---|
27 | print('setting driver ok') |
---|
28 | self.ou_not_setup = "2" |
---|
29 | self.ou = "4" |
---|
30 | self.lab = "19" |
---|
31 | self.time_to_wait = 100 |
---|
32 | self.browser. |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | |
---|
37 | |
---|
38 | def setUp(self): |
---|
39 | # User enter email and passwd |
---|
40 | pass |
---|
41 | |
---|
42 | @classmethod |
---|
43 | def tearDownClass(self): |
---|
44 | self.browser.quit() |
---|
45 | #self.web2py.kill() |
---|
46 | os.system('pkill geckodriver') |
---|
47 | |
---|
48 | |
---|
49 | def get_response_code(self, url): |
---|
50 | """Returns the response code of the given url |
---|
51 | |
---|
52 | url the url to check for |
---|
53 | return the response code of the given url |
---|
54 | """ |
---|
55 | handler = urllib3.urlopen(url) |
---|
56 | return handler.getcode() |
---|
57 | |
---|
58 | def doLogin(self): |
---|
59 | print(URL_ROOT + '/' + URL_APP) |
---|
60 | ## go to login web page |
---|
61 | self.browser.get(URL_ROOT + '/' + URL_APP) |
---|
62 | |
---|
63 | #User is invited to enter mail |
---|
64 | inputboxMail = self.browser.find_element_by_name('username') |
---|
65 | |
---|
66 | #User is invited to enter passwdl |
---|
67 | inputboxPasswd = self.browser.find_element_by_name('password') |
---|
68 | |
---|
69 | #User write mail and passwd and pulse Enter on login buttom |
---|
70 | inputboxMail.send_keys('admin') |
---|
71 | inputboxPasswd.send_keys('admin') |
---|
72 | |
---|
73 | self.browser.find_element_by_xpath("//input[@type='submit']").click() |
---|
74 | |
---|
75 | def get_ou(self): |
---|
76 | return self.browser.find_element_by_xpath("//span[@data-ou='" + self.ou + "']") |
---|
77 | |
---|
78 | def get_ou_not_setup(self): |
---|
79 | return self.browser.find_element_by_xpath("//span[@data-ou='" + self.ou_not_setup + "']") |
---|
80 | |
---|
81 | def get_lab(self): |
---|
82 | return self.browser.find_element_by_xpath("//span[@data-lab_id='" + self.lab + "']") |
---|
83 | |
---|
84 | def get_some_client(self): |
---|
85 | return self.browser.find_element_by_xpath("//tr[@class='pc']") |
---|
86 | |
---|
87 | def get_button_reserve(self): |
---|
88 | return self.browser.find_element_by_xpath("//button[@data-ou_id='" + self.ou + "' and @data-lab_id='" + self.lab + "']") |
---|
89 | |
---|
90 | def get_button_select_broser(self): |
---|
91 | return self.browser.find_element_by_xpath("//button[@data-client='browser']") |
---|
92 | |
---|
93 | def get_console_log(self): |
---|
94 | return self.browser.find_element_by_xpath("//textarea[@id='text_consolelog']") |
---|
95 | |
---|
96 | def get_button_connect(self): |
---|
97 | return self.browser.find_element_by_xpath("//button[contains(text(),'Conectar')]") |
---|
98 | |
---|
99 | def get_button_cancel(self): |
---|
100 | return self.browser.find_element_by_xpath("//button[contains(text(),'Cancelar')]") |
---|
101 | |
---|
102 | |
---|
103 | def get_img_status_ready(self): |
---|
104 | try: |
---|
105 | return self.browser.find_element_by_xpath("//img[@data-status!='busy']") |
---|
106 | except: |
---|
107 | return None |
---|
108 | |
---|
109 | def get_canvas(self): |
---|
110 | return self.browser.find_element_by_xpath("//canvas") |
---|
111 | |
---|
112 | def start_web2py_server(): |
---|
113 | #noreload ensures single process |
---|
114 | |
---|
115 | print(os.path.curdir) |
---|
116 | |
---|
117 | return subprocess.Popen([ |
---|
118 | 'python', '../../web2py.py', 'runserver', '-a "passwd"', '-p 8001' |
---|
119 | |
---|
120 | ]) |
---|