|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | """ baseclass to manage selenium UI tests """ |
3 | 3 |
|
4 | | -import time |
5 | | - |
6 | | -from selenium import webdriver |
7 | | -from selenium.common.exceptions import SessionNotCreatedException |
8 | | - |
9 | 4 | from arangodb.starter.deployments import RunnerType |
| 5 | +from arangodb.starter.deployments.runner import RunnerProperties |
| 6 | + |
10 | 7 | from arangodb.starter.deployments.selenium_deployments.sbase import SeleniumRunner, cleanup_temp_files |
11 | 8 |
|
12 | | -# pylint: disable=import-outside-toplevel disable=too-many-locals disable=too-many-branches disable=too-many-statements |
| 9 | +# pylint: disable=import-outside-toplevel disable=too-many-locals |
| 10 | +# pylint: disable=too-many-branches disable=too-many-statements |
| 11 | +# pylint: disable=too-many-return-statements disable=too-many-arguments |
13 | 12 | def init( |
14 | 13 | runner_type: RunnerType, |
| 14 | + properties: RunnerProperties, |
15 | 15 | selenium_worker: str, |
16 | 16 | selenium_driver_args: list, |
17 | 17 | selenium_include_suites: list, |
18 | 18 | testrun_name: str, |
19 | 19 | ssl: bool, |
20 | 20 | ) -> SeleniumRunner: |
21 | 21 | """build selenium testcase for runner_type""" |
22 | | - if "_" in selenium_worker: |
23 | | - sw_split = selenium_worker.split("_") |
24 | | - driver_func = getattr(webdriver, sw_split[0]) |
25 | | - selenium_worker = sw_split[1].lower() |
26 | | - worker_options = "" |
27 | | - else: |
28 | | - driver_func = getattr(webdriver, selenium_worker) |
29 | | - worker_options = selenium_worker = selenium_worker.lower() + "_" |
30 | | - if driver_func is None: |
31 | | - raise Exception("webdriver " + selenium_worker + "unknown") |
32 | | - |
33 | | - kwargs = {} |
34 | | - is_headless = False |
35 | | - if len(selenium_driver_args) > 0: |
36 | | - opts_func = getattr(webdriver, selenium_worker) |
37 | | - opts_func = getattr(opts_func, "options") |
38 | | - opts_func = getattr(opts_func, "Options") |
39 | | - options = opts_func() |
40 | | - kwargs[worker_options + "options"] = options |
41 | | - for opt in selenium_driver_args: |
42 | | - split_opts = opt.split("=") |
43 | | - if opt == "headless": |
44 | | - is_headless = True |
45 | | - elif len(split_opts) == 2: |
46 | | - if split_opts[0] == "command_executor": |
47 | | - is_headless = True |
48 | | - kwargs["command_executor"] = split_opts[1] |
49 | | - continue |
50 | | - elif len(split_opts) >= 3: |
51 | | - key = split_opts.pop(0) |
52 | | - where_to_put = {} |
53 | | - while len(split_opts) > 2: |
54 | | - if split_opts[0] not in where_to_put: |
55 | | - where_to_put[split_opts[0]] = {} |
56 | | - where_to_put = where_to_put[split_opts[0]] |
57 | | - if len(split_opts) == 2: |
58 | | - val = split_opts[1] |
59 | | - if val == "True": |
60 | | - val = True |
61 | | - elif val == "False": |
62 | | - val = False |
63 | | - where_to_put[split_opts[0]] = val |
64 | | - options.set_capability(key, where_to_put) |
65 | | - split_opts = [] |
66 | | - continue |
67 | | - options.add_argument("--" + opt) |
68 | | - |
69 | | - cleanup_temp_files(is_headless) |
70 | | - driver = None |
71 | | - count = 0 |
72 | | - while driver is None and count < 10: |
73 | | - count += 1 |
74 | | - try: |
75 | | - driver = driver_func(**kwargs) |
76 | | - except TypeError: |
77 | | - try: |
78 | | - driver = driver_func.webdriver.WebDriver(**kwargs) |
79 | | - except SessionNotCreatedException as ex: |
80 | | - if count == 10: |
81 | | - raise ex |
82 | | - print("S: retrying to launch browser") |
83 | | - cleanup_temp_files(is_headless) |
84 | | - time.sleep(2) |
85 | | - except SessionNotCreatedException as ex: |
86 | | - if count == 10: |
87 | | - raise ex |
88 | | - print("S: retrying to launch browser") |
89 | | - cleanup_temp_files(is_headless) |
90 | | - time.sleep(2) |
91 | | - if selenium_worker.lower() == "chrome": |
92 | | - required_width = driver.execute_script("return document.body.parentNode.scrollWidth") |
93 | | - required_height = driver.execute_script("return document.body.parentNode.scrollHeight") |
94 | | - driver.set_window_size(required_width, required_height) |
95 | | - |
| 22 | + selenium_args = { |
| 23 | + "selenium_worker": selenium_worker, |
| 24 | + "selenium_driver_args": selenium_driver_args, |
| 25 | + } |
96 | 26 | if runner_type == RunnerType.SINGLE: |
97 | 27 | from arangodb.starter.deployments.selenium_deployments.single import ( |
98 | 28 | Single, |
99 | 29 | ) |
100 | 30 |
|
101 | | - return Single(driver, is_headless, testrun_name, ssl, selenium_include_suites) |
| 31 | + return Single(selenium_args, properties, testrun_name, ssl, selenium_include_suites) |
102 | 32 |
|
103 | 33 | if runner_type == RunnerType.LEADER_FOLLOWER: |
104 | 34 | from arangodb.starter.deployments.selenium_deployments.leaderfollower import ( |
105 | 35 | LeaderFollower, |
106 | 36 | ) |
107 | 37 |
|
108 | | - return LeaderFollower(driver, is_headless, testrun_name, ssl, selenium_include_suites) |
| 38 | + return LeaderFollower(selenium_args, properties, testrun_name, ssl, selenium_include_suites) |
109 | 39 |
|
110 | 40 | if runner_type == RunnerType.ACTIVE_FAILOVER: |
111 | 41 | from arangodb.starter.deployments.selenium_deployments.activefailover import ( |
112 | 42 | ActiveFailover, |
113 | 43 | ) |
114 | 44 |
|
115 | | - return ActiveFailover(driver, is_headless, testrun_name, ssl, selenium_include_suites) |
| 45 | + return ActiveFailover(selenium_args, properties, testrun_name, ssl, selenium_include_suites) |
116 | 46 |
|
117 | 47 | if runner_type == RunnerType.CLUSTER: |
118 | 48 | from arangodb.starter.deployments.selenium_deployments.cluster import Cluster |
119 | 49 |
|
120 | | - return Cluster(driver, is_headless, testrun_name, ssl, selenium_include_suites) |
| 50 | + return Cluster(selenium_args, properties, testrun_name, ssl, selenium_include_suites) |
121 | 51 |
|
122 | 52 | if runner_type == RunnerType.DC2DC: |
123 | 53 | from arangodb.starter.deployments.selenium_deployments.dc2dc import Dc2Dc |
124 | 54 |
|
125 | | - return Dc2Dc(driver, is_headless, testrun_name, ssl, selenium_include_suites) |
| 55 | + return Dc2Dc(selenium_args, properties, testrun_name, ssl, selenium_include_suites) |
126 | 56 |
|
127 | 57 | if runner_type == RunnerType.DC2DCENDURANCE: |
128 | 58 | from arangodb.starter.deployments.selenium_deployments.dc2dc_endurance import ( |
129 | 59 | Dc2DcEndurance, |
130 | 60 | ) |
131 | 61 |
|
132 | | - return Dc2DcEndurance(driver, is_headless, testrun_name, ssl, selenium_include_suites) |
| 62 | + return Dc2DcEndurance(selenium_args, properties, testrun_name, ssl, selenium_include_suites) |
133 | 63 |
|
134 | 64 | if runner_type == RunnerType.NONE: |
135 | 65 | from arangodb.starter.deployments.selenium_deployments.none import NoStarter |
136 | 66 |
|
137 | | - return NoStarter(driver, is_headless, testrun_name, ssl, selenium_include_suites) |
| 67 | + return NoStarter(selenium_args, properties, testrun_name, ssl, selenium_include_suites) |
138 | 68 |
|
139 | 69 | raise Exception("unknown starter type") |
0 commit comments