Skip to content

Commit 3d25e5a

Browse files
committed
Update plugins
1 parent 6c86e89 commit 3d25e5a

File tree

5 files changed

+44
-98
lines changed

5 files changed

+44
-98
lines changed

seleniumbase/plugins/base_plugin.py

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717

1818
class Base(Plugin):
19-
"""
20-
This plugin adds the following command-line options to nosetests:
19+
"""This plugin adds the following command-line options to nosetests:
2120
--env=ENV (Set the test env. Access with "self.env" in tests.)
2221
--account=STR (Set account. Access with "self.account" in tests.)
2322
--data=STRING (Extra test data. Access with "self.data" in tests.)
@@ -160,12 +159,9 @@ def options(self, parser, env):
160159
help="If true when using report, will display it after tests run.",
161160
)
162161
found_processes_arg = False
163-
found_timeout_arg = False
164162
for arg in sys.argv:
165-
if "--processes=" in arg:
163+
if "--processes=" in arg or "--processes" in arg:
166164
found_processes_arg = True
167-
if "--timeout=" in arg:
168-
found_timeout_arg = True
169165
if found_processes_arg:
170166
print("* WARNING: Don't use multi-threading with nosetests! *")
171167
parser.addoption(
@@ -174,16 +170,6 @@ def options(self, parser, env):
174170
default=0,
175171
help="WARNING: Don't use multi-threading with nosetests!",
176172
)
177-
if found_timeout_arg:
178-
print("\n WARNING: Don't use --timeout=s from pytest-timeout!")
179-
print(" It's not thread-safe for WebDriver processes!")
180-
print(" Use --time-limit=s from SeleniumBase instead!\n")
181-
parser.addoption(
182-
"--timeout",
183-
dest="timeout",
184-
default=0,
185-
help="Don't use --timeout=s! Use --time-limit=s instead!",
186-
)
187173

188174
def configure(self, options, conf):
189175
super().configure(options, conf)
@@ -262,24 +248,6 @@ def finalize(self, result):
262248
self.show_report,
263249
)
264250

265-
def __log_all_options_if_none_specified(self, test):
266-
"""
267-
When testing_base is specified, but none of the log options to save are
268-
specified (basic_test_info, screen_shots, page_source), then save them
269-
all by default. Otherwise, save only selected ones from their plugins.
270-
"""
271-
if (
272-
(not self.options.enable_plugin_basic_test_info)
273-
and (not self.options.enable_plugin_screen_shots)
274-
and (not self.options.enable_plugin_page_source)
275-
):
276-
test_logpath = self.options.log_path + "/" + test.id()
277-
log_helper.log_screenshot(test_logpath, test.driver)
278-
log_helper.log_test_failure_data(
279-
test, test_logpath, test.driver, test.browser
280-
)
281-
log_helper.log_page_source(test_logpath, test.driver)
282-
283251
def addSuccess(self, test, capt):
284252
if self.report_on:
285253
self.duration = str(
@@ -336,15 +304,12 @@ def add_fails_or_errors(self, test, err):
336304
)
337305

338306
def addFailure(self, test, err, capt=None, tbinfo=None):
339-
# self.__log_all_options_if_none_specified(test)
340307
self.add_fails_or_errors(test, err)
341308

342309
def addError(self, test, err, capt=None):
343-
"""
344-
Since Skip, Blocked, and Deprecated are all technically errors, but not
345-
error states, we want to make sure that they don't show up in
346-
the nose output as errors.
347-
"""
310+
"""Since Skip, Blocked, and Deprecated are all technically errors,
311+
but not error states, we want to make sure that they
312+
don't show up in the nose output as errors."""
348313
from seleniumbase.fixtures import errors
349314

350315
if (
@@ -363,27 +328,19 @@ def addError(self, test, err, capt=None):
363328
)[0]
364329
)
365330
else:
366-
# self.__log_all_options_if_none_specified(test)
367331
pass
368332
self.add_fails_or_errors(test, err)
369333

370334
def handleError(self, test, err, capt=None):
371-
"""
372-
If the database plugin is not present, we have to handle capturing
373-
"errors" that shouldn't be reported as such in base.
374-
"""
335+
"""After each test error, record testcase run information.
336+
"Error" also encompasses any states other than Pass or Fail."""
375337
from nose.exc import SkipTest
376338
from seleniumbase.fixtures import errors
377339

378340
if not hasattr(test.test, "testcase_guid"):
379341
if err[0] == errors.BlockedTest:
380342
raise SkipTest(err[1])
381-
return True
382-
383343
elif err[0] == errors.DeprecatedTest:
384344
raise SkipTest(err[1])
385-
return True
386-
387345
elif err[0] == errors.SkipTest:
388346
raise SkipTest(err[1])
389-
return True

seleniumbase/plugins/db_reporting_plugin.py

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
"""The plugin for recording test results in the Testcase Database."""
2-
import getpass
32
import time
43
import uuid
54
from nose.plugins import Plugin
6-
from nose.exc import SkipTest
7-
from seleniumbase.core.application_manager import ApplicationManager
8-
from seleniumbase.core.testcase_manager import ExecutionQueryPayload
9-
from seleniumbase.core.testcase_manager import TestcaseDataPayload
10-
from seleniumbase.core.testcase_manager import TestcaseManager
115
from seleniumbase.fixtures import constants
12-
from seleniumbase.fixtures import errors
136

147

158
class DBReporting(Plugin):
@@ -51,13 +44,18 @@ def options(self, parser, env):
5144
)
5245

5346
def configure(self, options, conf):
47+
from seleniumbase.core.testcase_manager import TestcaseManager
48+
5449
super().configure(options, conf)
5550
self.options = options
5651
self.testcase_manager = TestcaseManager(self.options.database_env)
5752

5853
def begin(self):
5954
"""At the start of the run, we want to record the test
6055
execution information in the database."""
56+
import getpass
57+
from seleniumbase.core.testcase_manager import ExecutionQueryPayload
58+
6159
exec_payload = ExecutionQueryPayload()
6260
exec_payload.execution_start_time = int(time.time() * 1000)
6361
self.execution_start_time = exec_payload.execution_start_time
@@ -67,6 +65,9 @@ def begin(self):
6765

6866
def startTest(self, test):
6967
"""At the start of the test, set the testcase details."""
68+
from seleniumbase.core.application_manager import ApplicationManager
69+
from seleniumbase.core.testcase_manager import TestcaseDataPayload
70+
7071
data_payload = TestcaseDataPayload()
7172
self.testcase_guid = str(uuid.uuid4())
7273
data_payload.guid = self.testcase_guid
@@ -111,52 +112,43 @@ def afterTest(self, test):
111112
self.__insert_test_result(constants.State.SKIPPED, self._test, err)
112113

113114
def addSuccess(self, test, capt):
114-
"""
115-
After each test success, record testcase run information.
116-
"""
115+
"""After each test success, record testcase run information."""
117116
self.__insert_test_result(constants.State.PASSED, test)
118117
self._result_set = True
119118

120119
def addFailure(self, test, err, capt=None, tbinfo=None):
121-
"""
122-
After each test failure, record testcase run information.
123-
"""
120+
"""After each test failure, record testcase run information."""
124121
self.__insert_test_result(constants.State.FAILED, test, err)
125122
self._result_set = True
126123

127124
def addError(self, test, err, capt=None):
128-
"""
129-
After each test error, record testcase run information.
130-
(Test errors should be treated the same as test failures.)
131-
"""
125+
"""After each test error, record testcase run information.
126+
(Test errors should be treated the same as test failures.)"""
132127
self.__insert_test_result(constants.State.FAILED, test, err)
133128
self._result_set = True
134129

135130
def handleError(self, test, err, capt=None):
136-
"""
137-
After each test error, record testcase run information.
138-
"Error" also encompasses any states other than Pass or Fail, so we
139-
check for those first.
140-
"""
131+
"""After each test error, record testcase run information.
132+
"Error" also encompasses any states other than Pass or Fail."""
133+
from nose.exc import SkipTest
134+
from seleniumbase.fixtures import errors
135+
141136
if err[0] == errors.BlockedTest:
142137
self.__insert_test_result(constants.State.BLOCKED, test, err)
143138
self._result_set = True
144139
raise SkipTest(err[1])
145-
return True
146-
147140
elif err[0] == errors.DeprecatedTest:
148141
self.__insert_test_result(constants.State.DEPRECATED, test, err)
149142
self._result_set = True
150143
raise SkipTest(err[1])
151-
return True
152-
153144
elif err[0] == errors.SkipTest:
154145
self.__insert_test_result(constants.State.SKIPPED, test, err)
155146
self._result_set = True
156147
raise SkipTest(err[1])
157-
return True
158148

159149
def __insert_test_result(self, state, test, err=None):
150+
from seleniumbase.core.testcase_manager import TestcaseDataPayload
151+
160152
data_payload = TestcaseDataPayload()
161153
data_payload.runtime = int(time.time() * 1000) - self.case_start_time
162154
data_payload.guid = self.testcase_guid

seleniumbase/plugins/pytest_plugin.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121

2222
def pytest_addoption(parser):
23-
"""
24-
This plugin adds the following command-line options to pytest:
23+
"""This plugin adds the following command-line options to pytest:
2524
--browser=BROWSER (The web browser to use. Default: "chrome".)
2625
--chrome (Shortcut for "--browser=chrome". Default.)
2726
--edge (Shortcut for "--browser=edge".)
@@ -1616,6 +1615,9 @@ def pytest_configure(config):
16161615
else:
16171616
pass # Use the browser specified by "--browser=BROWSER"
16181617

1618+
if sb_config.browser == "safari" and sb_config.headless:
1619+
sb_config.headless = False # Safari doesn't support headless mode
1620+
16191621
if sb_config.dash_title:
16201622
constants.Dashboard.TITLE = sb_config.dash_title.replace("_", " ")
16211623

@@ -1659,8 +1661,7 @@ def _get_test_ids_(the_item):
16591661
test_id = "unidentified_TestCase"
16601662
display_id = test_id
16611663
r"""
1662-
# Due to changes in SeleniumBase 1.66.0, we're now using the
1663-
# item's original nodeid for both the test_id and display_id.
1664+
# Now using the nodeid for both the test_id and display_id.
16641665
# (This only impacts tests using The Dashboard.)
16651666
# If there are any issues, we'll revert back to the old code.
16661667
test_id = the_item.nodeid.split("/")[-1].replace(" ", "_")
@@ -1739,8 +1740,7 @@ def pytest_deselected(items):
17391740

17401741
def pytest_collection_finish(session):
17411742
"""This runs after item collection is finalized.
1742-
https://docs.pytest.org/en/stable/reference.html
1743-
"""
1743+
https://docs.pytest.org/en/stable/reference.html """
17441744
sb_config._context_of_runner = False # Context Manager Compatibility
17451745
if "--co" in sys_argv or "--collect-only" in sys_argv:
17461746
return
@@ -2234,8 +2234,7 @@ def pytest_runtest_makereport(item, call):
22342234
if not test_id:
22352235
test_id = "unidentified_TestCase"
22362236
r"""
2237-
# Due to changes in SeleniumBase 1.66.0, we're now using the
2238-
# item's original nodeid for both the test_id and display_id.
2237+
# Now using the nodeid for both the test_id and display_id.
22392238
# (This only impacts tests using The Dashboard.)
22402239
# If there are any issues, we'll revert back to the old code.
22412240
test_id = test_id.split("/")[-1].replace(" ", "_")
@@ -2258,8 +2257,8 @@ def pytest_runtest_makereport(item, call):
22582257
if len(extra_report) > 1 and extra_report[1]["content"]:
22592258
report.extra = extra + extra_report
22602259
if sb_config._dash_is_html_report:
2261-
# (If the Dashboard URL is the same as the HTML Report URL:)
2262-
# Have the html report refresh back to a dashboard on update
2260+
# If the Dashboard URL is the same as the HTML Report URL,
2261+
# have the html report refresh back to a dashboard on update.
22632262
refresh_updates = (
22642263
'<script type="text/javascript" src="%s">'
22652264
"</script>" % constants.Dashboard.LIVE_JS

seleniumbase/plugins/sb_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,8 @@ def SB(
495495
no_screenshot = False
496496
if save_screenshot and no_screenshot:
497497
save_screenshot = False # "no_screenshot" has priority
498+
if browser == "safari" and headless:
499+
headless = False # Safari doesn't support headless mode
498500
if js_checking_on is None:
499501
if "--check-js" in sys_argv:
500502
js_checking_on = True

seleniumbase/plugins/selenium_plugin.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313

1414
class SeleniumBrowser(Plugin):
15-
"""
16-
This plugin adds the following command-line options to nosetests:
15+
"""This plugin adds the following command-line options to nosetests:
1716
--browser=BROWSER (The web browser to use. Default: "chrome".)
1817
--chrome (Shortcut for "--browser=chrome". Default.)
1918
--edge (Shortcut for "--browser=edge".)
@@ -1025,6 +1024,8 @@ def beforeTest(self, test):
10251024
test.test.cap_string = self.options.cap_string
10261025
test.test.headless = self.options.headless
10271026
test.test.headless2 = self.options.headless2
1027+
if test.test.headless and test.test.browser == "safari":
1028+
test.test.headless = False # Safari doesn't use headless
10281029
if test.test.headless2 and test.test.browser == "firefox":
10291030
test.test.headless2 = False # Only for Chromium browsers
10301031
test.test.headless = True # Firefox has regular headless
@@ -1174,23 +1175,18 @@ def beforeTest(self, test):
11741175
sb_config._virtual_display = None
11751176
sb_config.headless_active = False
11761177
self.headless_active = False
1177-
if (
1178-
self.options.headless
1179-
or self.options.headless2
1180-
or self.options.xvfb
1181-
):
1178+
if "linux" in sys.platform:
1179+
width = settings.HEADLESS_START_WIDTH
1180+
height = settings.HEADLESS_START_HEIGHT
11821181
try:
1183-
# from pyvirtualdisplay import Display # Skip for own lib
11841182
from sbvirtualdisplay import Display
11851183

1186-
self._xvfb_display = Display(visible=0, size=(1440, 1880))
1184+
self._xvfb_display = Display(visible=0, size=(width, height))
11871185
self._xvfb_display.start()
11881186
sb_config._virtual_display = self._xvfb_display
11891187
self.headless_active = True
11901188
sb_config.headless_active = True
11911189
except Exception:
1192-
# pyvirtualdisplay might not be necessary anymore because
1193-
# Chrome and Firefox now have built-in headless displays
11941190
pass
11951191
sb_config._is_timeout_changed = False
11961192
sb_config._SMALL_TIMEOUT = settings.SMALL_TIMEOUT

0 commit comments

Comments
 (0)