Skip to content

Commit 2bddc00

Browse files
committed
Refactoring
1 parent c2fd5c6 commit 2bddc00

21 files changed

+57
-117
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5770,13 +5770,13 @@ def show_file_choosers(self):
57705770
css_selector, timeout=settings.MINI_TIMEOUT
57715771
)
57725772
except Exception:
5773-
pass
5773+
time.sleep(0.14)
57745774
if self.__needs_minimum_wait():
57755775
time.sleep(0.05)
57765776
try:
57775777
self.show_elements(css_selector)
57785778
except Exception:
5779-
pass
5779+
time.sleep(0.16)
57805780
css_selector = re.escape(css_selector) # Add "\\" to special chars
57815781
css_selector = self.__escape_quotes_if_needed(css_selector)
57825782
script = (
@@ -7880,7 +7880,7 @@ def set_messenger_theme(
78807880
Themes: ["flat", "future", "block", "air", "ice"]
78817881
Locations: ["top_left", "top_center", "top_right",
78827882
"bottom_left", "bottom_center", "bottom_right"]
7883-
max_messages is the limit of concurrent messages to display.
7883+
max_messages: The limit of concurrent messages to display.
78847884
"""
78857885
self.__check_scope()
78867886
self.__check_browser()
@@ -8070,7 +8070,6 @@ def generate_referral_chain(self, pages):
80708070
"Exception: At least two website pages required for chaining!"
80718071
)
80728072
for page in pages:
8073-
# Find out if any of the web pages are invalid before continuing
80748073
if not page_utils.is_valid_url(page):
80758074
raise Exception(
80768075
"Exception: Website page {%s} is not a valid URL!" % page
@@ -12003,8 +12002,8 @@ def __click_with_offset(
1200312002
element_rect = element.rect
1200412003
left_offset = element_rect["width"] / 2
1200512004
top_offset = element_rect["height"] / 2
12006-
x = -left_offset + (x or 0)
12007-
y = -top_offset + (y or 0)
12005+
x = -left_offset + (math.ceil(float(x)) or 0)
12006+
y = -top_offset + (math.ceil(float(y)) or 0)
1200812007
elif selenium4_or_newer and center:
1200912008
pass
1201012009
elif not selenium4_or_newer and not center:

seleniumbase/fixtures/css_to_xpath.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Convert CSS selectors into XPath selectors
3-
"""
1+
"""Convert CSS selectors into XPath selectors"""
42
from cssselect.xpath import GenericTranslator
53

64

@@ -12,9 +10,7 @@ class ConvertibleToCssTranslator(GenericTranslator):
1210
"""
1311

1412
def css_to_xpath(self, css, prefix="//"):
15-
return super(ConvertibleToCssTranslator, self).css_to_xpath(
16-
css, prefix
17-
)
13+
return super().css_to_xpath(css, prefix)
1814

1915
def xpath_attrib_equals(self, xpath, name, value):
2016
xpath.add_condition("%s=%s" % (name, self.xpath_literal(value)))

seleniumbase/masterqa/master_qa.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
This tool allows testers to quickly verify pages while assisted by automation.
3-
"""
1+
"""Manually verify pages quickly while assisted by automation."""
42
import os
53
import shutil
64
import sys
@@ -17,7 +15,7 @@ class MasterQA(BaseCase):
1715
def setUp(self):
1816
self.check_count = 0
1917
self.auto_close_results_page = False
20-
super(MasterQA, self).setUp(masterqa_mode=True)
18+
super().setUp(masterqa_mode=True)
2119
self.LATEST_REPORT_DIR = settings.LATEST_REPORT_DIR
2220
self.ARCHIVE_DIR = settings.REPORT_ARCHIVE_DIR
2321
self.RESULTS_PAGE = settings.HTML_REPORT
@@ -67,7 +65,7 @@ def tearDown(self):
6765
if self.__has_exception():
6866
self.__add_failure(sys.exc_info()[1])
6967
self.__process_manual_check_results(self.auto_close_results_page)
70-
super(MasterQA, self).tearDown()
68+
super().tearDown()
7169

7270
####################
7371

seleniumbase/plugins/base_plugin.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
"""
2-
This is the Nosetest plugin for setting base configuration and logging.
3-
"""
4-
1+
"""The Nosetest plugin for setting base configuration and logging."""
52
import ast
63
import sys
74
import time
@@ -37,11 +34,10 @@ class Base(Plugin):
3734
Only use this when running tests locally, as this will
3835
pause the test run until the report window is closed.
3936
"""
40-
4137
name = "testing_base" # Usage: --with-testing_base (Enabled by default)
4238

4339
def options(self, parser, env):
44-
super(Base, self).options(parser, env=env)
40+
super().options(parser, env=env)
4541
parser.add_option(
4642
"--env",
4743
action="store",
@@ -189,7 +185,7 @@ def options(self, parser, env):
189185
)
190186

191187
def configure(self, options, conf):
192-
super(Base, self).configure(options, conf)
188+
super().configure(options, conf)
193189
self.enabled = True # Used if test class inherits BaseCase
194190
self.options = options
195191
self.report_on = options.report

seleniumbase/plugins/basic_test_info.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
"""
2-
The plugin for saving basic test info to the logs for Selenium tests.
3-
The created file will be saved in the default logs folder (in .../logs)
4-
Data to be saved includes:
5-
* Last page url
6-
* Browser
7-
* Server
8-
* Error
9-
* Traceback
10-
"""
11-
1+
"""The plugin for saving basic test info for Selenium tests."""
122
import os
133
import codecs
144
import time
@@ -18,21 +8,15 @@
188

199

2010
class BasicTestInfo(Plugin):
21-
"""
22-
This plugin will capture basic info when a test fails or
23-
raises an error. It will store that basic test info in
24-
the default logs or in the file specified by the user.
25-
"""
26-
11+
"""This plugin captures basic info when a test fails or raises an error."""
2712
name = "basic_test_info" # Usage: --with-basic_test_info
28-
2913
logfile_name = settings.BASIC_INFO_NAME
3014

3115
def options(self, parser, env):
32-
super(BasicTestInfo, self).options(parser, env=env)
16+
super().options(parser, env=env)
3317

3418
def configure(self, options, conf):
35-
super(BasicTestInfo, self).configure(options, conf)
19+
super().configure(options, conf)
3620
if not self.enabled:
3721
return
3822
self.options = options

seleniumbase/plugins/db_reporting_plugin.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
"""
2-
This plugin is for recording test results in the Testcase Database.
3-
"""
4-
1+
"""The plugin for recording test results in the Testcase Database."""
52
import getpass
63
import time
74
import uuid
@@ -16,10 +13,7 @@
1613

1714

1815
class DBReporting(Plugin):
19-
"""
20-
This plugin records test results in the Testcase Database.
21-
"""
22-
16+
"""This plugin records test results in the Testcase Database."""
2317
name = "db_reporting" # Usage: --with-db_reporting
2418

2519
def __init__(self):
@@ -33,7 +27,7 @@ def __init__(self):
3327
self._test = None
3428

3529
def options(self, parser, env):
36-
super(DBReporting, self).options(parser, env=env)
30+
super().options(parser, env=env)
3731
parser.add_option(
3832
"--database_env",
3933
"--database-env",
@@ -57,7 +51,7 @@ def options(self, parser, env):
5751
)
5852

5953
def configure(self, options, conf):
60-
super(DBReporting, self).configure(options, conf)
54+
super().configure(options, conf)
6155
self.options = options
6256
self.testcase_manager = TestcaseManager(self.options.database_env)
6357

seleniumbase/plugins/page_source.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
"""
2-
The plugin for capturing and storing the page source on errors and failures.
3-
"""
4-
1+
"""The plugin for capturing & storing the page source on errors & failures."""
52
import os
63
import codecs
74
from nose.plugins import Plugin
@@ -10,20 +7,15 @@
107

118

129
class PageSource(Plugin):
13-
"""
14-
This plugin will capture the page source when a test fails
15-
or raises an error. It will store the page source in the
16-
logs file specified, along with default test information.
17-
"""
18-
10+
"""Capture the page source when a test fails or raises an error."""
1911
name = "page_source" # Usage: --with-page_source
2012
logfile_name = settings.PAGE_SOURCE_NAME
2113

2214
def options(self, parser, env):
23-
super(PageSource, self).options(parser, env=env)
15+
super().options(parser, env=env)
2416

2517
def configure(self, options, conf):
26-
super(PageSource, self).configure(options, conf)
18+
super().configure(options, conf)
2719
if not self.enabled:
2820
return
2921
self.options = options
@@ -49,7 +41,7 @@ def addFailure(self, test, err, capt=None, tbinfo=None):
4941
try:
5042
page_source = test.driver.page_source
5143
except Exception:
52-
# Since we can't get the page source from here, skip saving it
44+
# Since we can't get the page source from here, don't save it.
5345
return
5446
test_logpath = self.options.log_path + "/" + test.id()
5547
if not os.path.exists(test_logpath):

seleniumbase/plugins/pytest_plugin.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
"""
2-
This is the pytest configuration file for setting test options.
3-
"""
4-
1+
"""This is the pytest configuration file for setting test options."""
52
import colorama
63
import os
74
import pytest
@@ -2072,11 +2069,11 @@ def sb(request):
20722069

20732070
class BaseClass(BaseCase):
20742071
def setUp(self):
2075-
super(BaseClass, self).setUp()
2072+
super().setUp()
20762073

20772074
def tearDown(self):
20782075
self.save_teardown_screenshot()
2079-
super(BaseClass, self).tearDown()
2076+
super().tearDown()
20802077

20812078
def base_method(self):
20822079
pass

seleniumbase/plugins/s3_logging_plugin.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
"""
2-
The S3 Logging Plugin lets you upload test logs to the S3 bucket specified.
3-
"""
4-
1+
"""The S3 Plugin for uploading test logs to the S3 bucket specified."""
52
import uuid
63
import logging
74
import os
@@ -11,12 +8,11 @@
118

129
class S3Logging(Plugin):
1310
"""The plugin for uploading test logs to the S3 bucket specified."""
14-
1511
name = "s3_logging" # Usage: --with-s3-logging
1612

1713
def configure(self, options, conf):
1814
"""Get the options."""
19-
super(S3Logging, self).configure(options, conf)
15+
super().configure(options, conf)
2016
self.options = options
2117

2218
def afterTest(self, test):

seleniumbase/plugins/screen_shots.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
1-
"""
2-
Contains the screenshot plugin for the selenium tests.
3-
"""
4-
1+
"""The screenshot plugin for selenium tests that run with nosetests."""
52
import os
63
from nose.plugins import Plugin
74
from seleniumbase.config import settings
85

96

107
class ScreenShots(Plugin):
11-
"""
12-
This plugin will take a screenshot when either a test fails
13-
or raises an error. It will store that screenshot either in
14-
the default logs file or in another file of the user's specification.
15-
"""
16-
8+
"""This plugin takes a screenshot when a test fails or raises an error."""
179
name = "screen_shots"
1810
logfile_name = settings.SCREENSHOT_NAME
1911

2012
def options(self, parser, env):
21-
super(ScreenShots, self).options(parser, env=env)
13+
super().options(parser, env=env)
2214

2315
def configure(self, options, conf):
24-
super(ScreenShots, self).configure(options, conf)
16+
super().configure(options, conf)
2517
if not self.enabled:
2618
return
2719
self.options = options

0 commit comments

Comments
 (0)