Skip to content

Commit 69ae9f3

Browse files
committed
Refactoring and other updates
1 parent 3a9b5f3 commit 69ae9f3

File tree

6 files changed

+68
-24
lines changed

6 files changed

+68
-24
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,7 @@ def hover_and_click(
20042004
)
20052005
hover_selector = self.convert_to_css_selector(hover_selector, hover_by)
20062006
hover_by = By.CSS_SELECTOR
2007+
original_click_selector = click_selector
20072008
click_selector, click_by = self.__recalculate_selector(
20082009
click_selector, click_by
20092010
)
@@ -2019,6 +2020,10 @@ def hover_and_click(
20192020
if url and len(url) > 0:
20202021
if ("http:") in url or ("https:") in url or ("file:") in url:
20212022
if self.get_session_storage_item("pause_recorder") == "no":
2023+
if hover_by == By.XPATH:
2024+
hover_selector = original_selector
2025+
if click_by == By.XPATH:
2026+
click_selector = original_click_selector
20222027
time_stamp = self.execute_script("return Date.now();")
20232028
origin = self.get_origin()
20242029
the_selectors = [hover_selector, click_selector]
@@ -9506,6 +9511,7 @@ def assert_element(self, selector, by=By.CSS_SELECTOR, timeout=None):
95069511
self.__assert_shadow_element_visible(selector)
95079512
return True
95089513
self.wait_for_element_visible(selector, by=by, timeout=timeout)
9514+
original_selector = selector
95099515
if self.demo_mode:
95109516
selector, by = self.__recalculate_selector(
95119517
selector, by, xp_ok=False
@@ -9522,6 +9528,8 @@ def assert_element(self, selector, by=By.CSS_SELECTOR, timeout=None):
95229528
if url and len(url) > 0:
95239529
if ("http:") in url or ("https:") in url or ("file:") in url:
95249530
if self.get_session_storage_item("pause_recorder") == "no":
9531+
if by == By.XPATH:
9532+
selector = original_selector
95259533
time_stamp = self.execute_script("return Date.now();")
95269534
origin = self.get_origin()
95279535
action = ["as_el", selector, origin, time_stamp]
@@ -9689,6 +9697,7 @@ def assert_text(
96899697
timeout = settings.SMALL_TIMEOUT
96909698
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
96919699
timeout = self.__get_new_timeout(timeout)
9700+
original_selector = selector
96929701
selector, by = self.__recalculate_selector(selector, by)
96939702
if self.__is_shadow_selector(selector):
96949703
self.__assert_shadow_text_visible(text, selector, timeout)
@@ -9715,6 +9724,8 @@ def assert_text(
97159724
if url and len(url) > 0:
97169725
if ("http:") in url or ("https:") in url or ("file:") in url:
97179726
if self.get_session_storage_item("pause_recorder") == "no":
9727+
if by == By.XPATH:
9728+
selector = original_selector
97189729
time_stamp = self.execute_script("return Date.now();")
97199730
origin = self.get_origin()
97209731
text_selector = [text, selector]
@@ -9735,6 +9746,7 @@ def assert_exact_text(
97359746
timeout = settings.SMALL_TIMEOUT
97369747
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
97379748
timeout = self.__get_new_timeout(timeout)
9749+
original_selector = selector
97389750
selector, by = self.__recalculate_selector(selector, by)
97399751
if self.__is_shadow_selector(selector):
97409752
self.__assert_exact_shadow_text_visible(text, selector, timeout)
@@ -9763,6 +9775,8 @@ def assert_exact_text(
97639775
if url and len(url) > 0:
97649776
if ("http:") in url or ("https:") in url or ("file:") in url:
97659777
if self.get_session_storage_item("pause_recorder") == "no":
9778+
if by == By.XPATH:
9779+
selector = original_selector
97669780
time_stamp = self.execute_script("return Date.now();")
97679781
origin = self.get_origin()
97689782
text_selector = [text, selector]
@@ -10001,12 +10015,16 @@ def assert_element_not_visible(
1000110015
timeout = settings.SMALL_TIMEOUT
1000210016
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
1000310017
timeout = self.__get_new_timeout(timeout)
10018+
original_selector = selector
10019+
selector, by = self.__recalculate_selector(selector, by)
1000410020
self.wait_for_element_not_visible(selector, by=by, timeout=timeout)
1000510021
if self.recorder_mode:
1000610022
url = self.get_current_url()
1000710023
if url and len(url) > 0:
1000810024
if ("http:") in url or ("https:") in url or ("file:") in url:
1000910025
if self.get_session_storage_item("pause_recorder") == "no":
10026+
if by == By.XPATH:
10027+
selector = original_selector
1001010028
time_stamp = self.execute_script("return Date.now();")
1001110029
origin = self.get_origin()
1001210030
action = ["asenv", selector, origin, time_stamp]
@@ -11437,12 +11455,13 @@ def setUp(self, masterqa_mode=False):
1143711455
# This raises an exception if the test is not coming from pytest
1143811456
self.is_pytest = sb_config.is_pytest
1143911457
except Exception:
11440-
# Not using pytest (probably nosetests)
11458+
# Not using pytest (could be nosetests, behave, or raw Python)
1144111459
self.is_pytest = False
1144211460
if self.is_pytest:
1144311461
# pytest-specific code
1144411462
test_id = self.__get_test_id()
1144511463
self.test_id = test_id
11464+
self.is_behave = False
1144611465
if hasattr(self, "_using_sb_fixture"):
1144711466
self.test_id = sb_config._test_id
1144811467
if hasattr(sb_config, "_sb_pdb_driver"):
@@ -11589,7 +11608,7 @@ def setUp(self, masterqa_mode=False):
1158911608
self.testcase_manager = TestcaseManager(self.database_env)
1159011609
#
1159111610
exec_payload = ExecutionQueryPayload()
11592-
exec_payload.execution_start_time = int(time.time() * 1000)
11611+
exec_payload.execution_start_time = int(time.time() * 1000.0)
1159311612
self.execution_start_time = exec_payload.execution_start_time
1159411613
exec_payload.guid = self.execution_guid
1159511614
exec_payload.username = getpass.getuser()
@@ -11833,9 +11852,7 @@ def setUp(self, masterqa_mode=False):
1183311852
# Although the pytest clock starts before setUp() begins,
1183411853
# the time-limit clock starts at the end of the setUp() method.
1183511854
sb_config.start_time_ms = int(time.time() * 1000.0)
11836-
if not self.__start_time_ms:
11837-
# Call this once in case of multiple setUp() calls in the same test
11838-
self.__start_time_ms = sb_config.start_time_ms
11855+
self.__start_time_ms = sb_config.start_time_ms
1183911856

1184011857
def __set_last_page_screenshot(self):
1184111858
"""self.__last_page_screenshot is only for pytest html report logs.
@@ -11917,7 +11934,7 @@ def __insert_test_result(self, state, err):
1191711934
from seleniumbase.core.testcase_manager import TestcaseDataPayload
1191811935

1191911936
data_payload = TestcaseDataPayload()
11920-
data_payload.runtime = int(time.time() * 1000) - self.case_start_time
11937+
data_payload.runtime = int(time.time() * 1000.0) - self.case_start_time
1192111938
data_payload.guid = self.testcase_guid
1192211939
data_payload.execution_guid = self.execution_guid
1192311940
data_payload.state = state
@@ -12186,7 +12203,7 @@ def __process_dashboard(self, has_exception, init=False):
1218612203
if hasattr(self, "_using_sb_fixture") and self.__will_be_skipped:
1218712204
test_id = sb_config._test_id
1218812205
if not init:
12189-
duration_ms = int(time.time() * 1000) - self.__start_time_ms
12206+
duration_ms = int(time.time() * 1000.0) - self.__start_time_ms
1219012207
duration = float(duration_ms) / 1000.0
1219112208
duration = "{:.2f}".format(duration)
1219212209
sb_config._duration[test_id] = duration
@@ -12707,7 +12724,7 @@ def tearDown(self):
1270712724
self.__insert_test_result(
1270812725
constants.State.PASSED, False
1270912726
)
12710-
runtime = int(time.time() * 1000) - self.execution_start_time
12727+
runtime = int(time.time() * 1000.0) - self.execution_start_time
1271112728
self.testcase_manager.update_execution_data(
1271212729
self.execution_guid, runtime
1271312730
)

seleniumbase/fixtures/constants.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
"""
23
SeleniumBase constants are stored in this file.
34
"""
@@ -20,6 +21,22 @@ class Environment:
2021
TEST = "test"
2122

2223

24+
class ValidEnvs:
25+
valid_envs = [
26+
"qa",
27+
"staging",
28+
"develop",
29+
"production",
30+
"master",
31+
"remote",
32+
"local",
33+
"alpha",
34+
"beta",
35+
"main",
36+
"test",
37+
]
38+
39+
2340
class Files:
2441
DOWNLOADS_FOLDER = "downloaded_files"
2542
ARCHIVED_DOWNLOADS_FOLDER = "archived_files"
@@ -38,7 +55,7 @@ class Recordings:
3855

3956

4057
class Dashboard:
41-
TITLE = "SeleniumBase Test Results Dashboard"
58+
TITLE = "SeleniumBase Dashboard ⚪"
4259
# STYLE_CSS = "https://seleniumbase.io/cdn/css/pytest_style.css"
4360
STYLE_CSS = "assets/pytest_style.css" # Generated before tests
4461
META_REFRESH_HTML = '<meta http-equiv="refresh" content="12">'

seleniumbase/fixtures/page_actions.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ def hover_element(driver, element):
158158

159159

160160
def timeout_exception(exception, message):
161-
exception, message = s_utils.format_exc(exception, message)
162-
raise exception(message)
161+
exc, msg = shared_utils.format_exc(exception, message)
162+
raise exc(msg)
163163

164164

165165
def hover_and_click(
@@ -302,7 +302,7 @@ def wait_for_element_present(
302302
start_ms = time.time() * 1000.0
303303
stop_ms = start_ms + (timeout * 1000.0)
304304
for x in range(int(timeout * 10)):
305-
s_utils.check_if_time_limit_exceeded()
305+
shared_utils.check_if_time_limit_exceeded()
306306
try:
307307
element = driver.find_element(by=by, value=selector)
308308
return element
@@ -359,7 +359,7 @@ def wait_for_element_visible(
359359
start_ms = time.time() * 1000.0
360360
stop_ms = start_ms + (timeout * 1000.0)
361361
for x in range(int(timeout * 10)):
362-
s_utils.check_if_time_limit_exceeded()
362+
shared_utils.check_if_time_limit_exceeded()
363363
try:
364364
element = driver.find_element(by=by, value=selector)
365365
is_present = True
@@ -652,7 +652,7 @@ def wait_for_attribute(
652652
start_ms = time.time() * 1000.0
653653
stop_ms = start_ms + (timeout * 1000.0)
654654
for x in range(int(timeout * 10)):
655-
s_utils.check_if_time_limit_exceeded()
655+
shared_utils.check_if_time_limit_exceeded()
656656
try:
657657
element = driver.find_element(by=by, value=selector)
658658
element_present = True
@@ -728,7 +728,7 @@ def wait_for_element_absent(
728728
start_ms = time.time() * 1000.0
729729
stop_ms = start_ms + (timeout * 1000.0)
730730
for x in range(int(timeout * 10)):
731-
s_utils.check_if_time_limit_exceeded()
731+
shared_utils.check_if_time_limit_exceeded()
732732
try:
733733
driver.find_element(by=by, value=selector)
734734
now_ms = time.time() * 1000.0
@@ -775,7 +775,7 @@ def wait_for_element_not_visible(
775775
start_ms = time.time() * 1000.0
776776
stop_ms = start_ms + (timeout * 1000.0)
777777
for x in range(int(timeout * 10)):
778-
s_utils.check_if_time_limit_exceeded()
778+
shared_utils.check_if_time_limit_exceeded()
779779
try:
780780
element = driver.find_element(by=by, value=selector)
781781
if element.is_displayed():
@@ -823,7 +823,7 @@ def wait_for_text_not_visible(
823823
start_ms = time.time() * 1000.0
824824
stop_ms = start_ms + (timeout * 1000.0)
825825
for x in range(int(timeout * 10)):
826-
s_utils.check_if_time_limit_exceeded()
826+
shared_utils.check_if_time_limit_exceeded()
827827
if not is_text_visible(driver, text, selector, by=by):
828828
return True
829829
now_ms = time.time() * 1000.0
@@ -866,7 +866,7 @@ def wait_for_attribute_not_present(
866866
start_ms = time.time() * 1000.0
867867
stop_ms = start_ms + (timeout * 1000.0)
868868
for x in range(int(timeout * 10)):
869-
s_utils.check_if_time_limit_exceeded()
869+
shared_utils.check_if_time_limit_exceeded()
870870
if not is_attribute_present(
871871
driver, selector, attribute, value=value, by=by
872872
):
@@ -1067,7 +1067,7 @@ def wait_for_and_switch_to_alert(driver, timeout=settings.LARGE_TIMEOUT):
10671067
start_ms = time.time() * 1000.0
10681068
stop_ms = start_ms + (timeout * 1000.0)
10691069
for x in range(int(timeout * 10)):
1070-
s_utils.check_if_time_limit_exceeded()
1070+
shared_utils.check_if_time_limit_exceeded()
10711071
try:
10721072
alert = driver.switch_to.alert
10731073
# Raises exception if no alert present
@@ -1096,11 +1096,11 @@ def switch_to_frame(driver, frame, timeout=settings.SMALL_TIMEOUT):
10961096
start_ms = time.time() * 1000.0
10971097
stop_ms = start_ms + (timeout * 1000.0)
10981098
for x in range(int(timeout * 10)):
1099-
s_utils.check_if_time_limit_exceeded()
1099+
shared_utils.check_if_time_limit_exceeded()
11001100
try:
11011101
driver.switch_to.frame(frame)
11021102
return True
1103-
except (NoSuchFrameException, TimeoutException):
1103+
except Exception:
11041104
if type(frame) is str:
11051105
by = None
11061106
if page_utils.is_xpath_selector(frame):
@@ -1142,7 +1142,7 @@ def switch_to_window(driver, window, timeout=settings.SMALL_TIMEOUT):
11421142
stop_ms = start_ms + (timeout * 1000.0)
11431143
if isinstance(window, int):
11441144
for x in range(int(timeout * 10)):
1145-
s_utils.check_if_time_limit_exceeded()
1145+
shared_utils.check_if_time_limit_exceeded()
11461146
try:
11471147
window_handle = driver.window_handles[window]
11481148
driver.switch_to.window(window_handle)
@@ -1164,7 +1164,7 @@ def switch_to_window(driver, window, timeout=settings.SMALL_TIMEOUT):
11641164
else:
11651165
window_handle = window
11661166
for x in range(int(timeout * 10)):
1167-
s_utils.check_if_time_limit_exceeded()
1167+
shared_utils.check_if_time_limit_exceeded()
11681168
try:
11691169
driver.switch_to.window(window_handle)
11701170
return True

seleniumbase/plugins/db_reporting_plugin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ def options(self, parser, env):
4747
constants.Environment.DEVELOP,
4848
constants.Environment.PRODUCTION,
4949
constants.Environment.MASTER,
50+
constants.Environment.REMOTE,
5051
constants.Environment.LOCAL,
52+
constants.Environment.ALPHA,
53+
constants.Environment.BETA,
54+
constants.Environment.MAIN,
5155
constants.Environment.TEST,
5256
),
5357
default=constants.Environment.TEST,

seleniumbase/plugins/pytest_plugin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ def pytest_addoption(parser):
313313
)
314314
parser.addoption(
315315
"--database_env",
316+
"--database-env",
316317
action="store",
317318
dest="database_env",
318319
choices=(
@@ -321,7 +322,11 @@ def pytest_addoption(parser):
321322
constants.Environment.DEVELOP,
322323
constants.Environment.PRODUCTION,
323324
constants.Environment.MASTER,
325+
constants.Environment.REMOTE,
324326
constants.Environment.LOCAL,
327+
constants.Environment.ALPHA,
328+
constants.Environment.BETA,
329+
constants.Environment.MAIN,
325330
constants.Environment.TEST,
326331
),
327332
default=constants.Environment.TEST,
@@ -913,6 +918,7 @@ def pytest_addoption(parser):
913918
)
914919

915920
sys_argv = sys.argv
921+
arg_join = " ".join(sys.argv)
916922
sb_config._browser_shortcut = None
917923

918924
# SeleniumBase does not support pytest-timeout due to hanging browsers.
@@ -946,7 +952,6 @@ def pytest_addoption(parser):
946952
or "--record" in sys_argv
947953
or "--rec" in sys_argv
948954
):
949-
arg_join = " ".join(sys.argv)
950955
if ("-n" in sys_argv) or (" -n=" in arg_join) or ("-c" in sys_argv):
951956
raise Exception(
952957
"\n\n Recorder Mode does NOT support multi-process mode (-n)!"

seleniumbase/plugins/selenium_plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ def beforeTest(self, test):
642642
'\n (Your browser choice was: "%s")\n' % browser
643643
)
644644
raise Exception(message)
645+
test.test.is_nosetest = True
645646
test.test.browser = self.options.browser
646647
test.test.cap_file = self.options.cap_file
647648
test.test.cap_string = self.options.cap_string

0 commit comments

Comments
 (0)