diff options
Diffstat (limited to 'bitbake/lib/toaster/tests/functional/functional_helpers.py')
-rw-r--r-- | bitbake/lib/toaster/tests/functional/functional_helpers.py | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/tests/functional/functional_helpers.py b/bitbake/lib/toaster/tests/functional/functional_helpers.py new file mode 100644 index 0000000000..486078a615 --- /dev/null +++ b/bitbake/lib/toaster/tests/functional/functional_helpers.py | |||
@@ -0,0 +1,122 @@ | |||
1 | #! /usr/bin/env python | ||
2 | # ex:ts=4:sw=4:sts=4:et | ||
3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
4 | # | ||
5 | # BitBake Toaster functional tests implementation | ||
6 | # | ||
7 | # Copyright (C) 2017 Intel Corporation | ||
8 | # | ||
9 | # This program is free software; you can redistribute it and/or modify | ||
10 | # it under the terms of the GNU General Public License version 2 as | ||
11 | # published by the Free Software Foundation. | ||
12 | # | ||
13 | # This program is distributed in the hope that it will be useful, | ||
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | # GNU General Public License for more details. | ||
17 | # | ||
18 | # You should have received a copy of the GNU General Public License along | ||
19 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
21 | |||
22 | import os | ||
23 | import logging | ||
24 | import subprocess | ||
25 | import signal | ||
26 | import time | ||
27 | import re | ||
28 | |||
29 | from tests.browser.selenium_helpers_base import SeleniumTestCaseBase | ||
30 | from tests.builds.buildtest import load_build_environment | ||
31 | |||
32 | logger = logging.getLogger("toaster") | ||
33 | |||
34 | class SeleniumFunctionalTestCase(SeleniumTestCaseBase): | ||
35 | wait_toaster_time = 5 | ||
36 | |||
37 | @classmethod | ||
38 | def setUpClass(cls): | ||
39 | # So that the buildinfo helper uses the test database' | ||
40 | if os.environ.get('DJANGO_SETTINGS_MODULE', '') != \ | ||
41 | 'toastermain.settings_test': | ||
42 | raise RuntimeError("Please initialise django with the tests settings: " \ | ||
43 | "DJANGO_SETTINGS_MODULE='toastermain.settings_test'") | ||
44 | |||
45 | load_build_environment() | ||
46 | |||
47 | # start toaster | ||
48 | cmd = "bash -c 'source toaster start'" | ||
49 | p = subprocess.Popen( | ||
50 | cmd, | ||
51 | cwd=os.environ.get("BUILDDIR"), | ||
52 | shell=True) | ||
53 | if p.wait() != 0: | ||
54 | raise RuntimeError("Can't initialize toaster") | ||
55 | |||
56 | super(SeleniumFunctionalTestCase, cls).setUpClass() | ||
57 | cls.live_server_url = 'http://localhost:8000/' | ||
58 | |||
59 | @classmethod | ||
60 | def tearDownClass(cls): | ||
61 | super(SeleniumFunctionalTestCase, cls).tearDownClass() | ||
62 | |||
63 | # XXX: source toaster stop gets blocked, to review why? | ||
64 | # from now send SIGTERM by hand | ||
65 | time.sleep(cls.wait_toaster_time) | ||
66 | builddir = os.environ.get("BUILDDIR") | ||
67 | |||
68 | with open(os.path.join(builddir, '.toastermain.pid'), 'r') as f: | ||
69 | toastermain_pid = int(f.read()) | ||
70 | os.kill(toastermain_pid, signal.SIGTERM) | ||
71 | with open(os.path.join(builddir, '.runbuilds.pid'), 'r') as f: | ||
72 | runbuilds_pid = int(f.read()) | ||
73 | os.kill(runbuilds_pid, signal.SIGTERM) | ||
74 | |||
75 | |||
76 | def get_URL(self): | ||
77 | rc=self.get_page_source() | ||
78 | project_url=re.search("(projectPageUrl\s:\s\")(.*)(\",)",rc) | ||
79 | return project_url.group(2) | ||
80 | |||
81 | |||
82 | def find_element_by_link_text_in_table(self, table_id, link_text): | ||
83 | """ | ||
84 | Assume there're multiple suitable "find_element_by_link_text". | ||
85 | In this circumstance we need to specify "table". | ||
86 | """ | ||
87 | try: | ||
88 | table_element = self.get_table_element(table_id) | ||
89 | element = table_element.find_element_by_link_text(link_text) | ||
90 | except NoSuchElementException as e: | ||
91 | print('no element found') | ||
92 | raise | ||
93 | return element | ||
94 | |||
95 | def get_table_element(self, table_id, *coordinate): | ||
96 | if len(coordinate) == 0: | ||
97 | #return whole-table element | ||
98 | element_xpath = "//*[@id='" + table_id + "']" | ||
99 | try: | ||
100 | element = self.driver.find_element_by_xpath(element_xpath) | ||
101 | except NoSuchElementException as e: | ||
102 | raise | ||
103 | return element | ||
104 | row = coordinate[0] | ||
105 | |||
106 | if len(coordinate) == 1: | ||
107 | #return whole-row element | ||
108 | element_xpath = "//*[@id='" + table_id + "']/tbody/tr[" + str(row) + "]" | ||
109 | try: | ||
110 | element = self.driver.find_element_by_xpath(element_xpath) | ||
111 | except NoSuchElementException as e: | ||
112 | return False | ||
113 | return element | ||
114 | #now we are looking for an element with specified X and Y | ||
115 | column = coordinate[1] | ||
116 | |||
117 | element_xpath = "//*[@id='" + table_id + "']/tbody/tr[" + str(row) + "]/td[" + str(column) + "]" | ||
118 | try: | ||
119 | element = self.driver.find_element_by_xpath(element_xpath) | ||
120 | except NoSuchElementException as e: | ||
121 | return False | ||
122 | return element | ||