Skip to content

Commit e7f76f1

Browse files
committed
Refactoring
1 parent b8a0463 commit e7f76f1

File tree

4 files changed

+33
-49
lines changed

4 files changed

+33
-49
lines changed

seleniumbase/core/application_manager.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
"""
2-
Method for generating application strings used in the Testcase Database.
3-
"""
4-
51
import time
62

73

84
class ApplicationManager:
9-
"""
10-
This class contains methods to generate application strings.
11-
"""
5+
"""Generating application strings for the Testcase Database."""
126

137
@classmethod
148
def generate_application_string(cls, test):

seleniumbase/core/proxy_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def create_proxy_ext(proxy_string, proxy_user, proxy_pass, zip_it=True):
1313
"""Implementation of https://stackoverflow.com/a/35293284 for
1414
https://stackoverflow.com/questions/12848327/
1515
(Run Selenium on a proxy server that requires authentication.)
16-
Solution involves creating & adding a Chromium extension on the fly.
16+
Solution involves creating & adding a Chromium extension at runtime.
1717
CHROMIUM-ONLY! *** Only Chrome and Edge browsers are supported. ***
1818
"""
1919
background_js = None
@@ -94,7 +94,7 @@ def create_proxy_ext(proxy_string, proxy_user, proxy_pass, zip_it=True):
9494
)
9595
import threading
9696

97-
lock = threading.RLock() # Support multi-threaded test runs with Pytest
97+
lock = threading.RLock() # Support multi-threaded tests. Eg. "pytest -n=4"
9898
with lock:
9999
abs_path = os.path.abspath(".")
100100
downloads_path = os.path.join(abs_path, DOWNLOADS_DIR)

seleniumbase/fixtures/base_case.py

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def test_anything(self):
6161
from selenium.webdriver.remote.remote_connection import LOGGER
6262
from seleniumbase import config as sb_config
6363
from seleniumbase.__version__ import __version__
64+
from seleniumbase.common import decorators
6465
from seleniumbase.config import settings
6566
from seleniumbase.core import download_helper
6667
from seleniumbase.core import log_helper
@@ -170,9 +171,9 @@ def open(self, url):
170171
self.__check_scope()
171172
self.__check_browser()
172173
if self.__needs_minimum_wait():
173-
time.sleep(0.01)
174+
time.sleep(0.025)
174175
if self.undetectable:
175-
time.sleep(0.02)
176+
time.sleep(0.025)
176177
pre_action_url = None
177178
try:
178179
pre_action_url = self.driver.current_url
@@ -3851,6 +3852,13 @@ def install_addon(self, xpi_file):
38513852
xpi_path = os.path.abspath(xpi_file)
38523853
self.driver.install_addon(xpi_path, temporary=True)
38533854

3855+
def activate_jquery(self):
3856+
"""If "jQuery is not defined", use this method to activate it for use.
3857+
This happens because jQuery is not always defined on web sites."""
3858+
self.wait_for_ready_state_complete()
3859+
js_utils.activate_jquery(self.driver)
3860+
self.wait_for_ready_state_complete()
3861+
38543862
def activate_demo_mode(self):
38553863
self.demo_mode = True
38563864

@@ -4945,22 +4953,6 @@ def __process_recorded_behave_actions(self, srt_actions, colorama):
49454953
out_file.close()
49464954
print("Created recordings/features/steps/imported.py")
49474955

4948-
def activate_jquery(self):
4949-
"""If "jQuery is not defined", use this method to activate it for use.
4950-
This happens because jQuery is not always defined on web sites."""
4951-
self.wait_for_ready_state_complete()
4952-
js_utils.activate_jquery(self.driver)
4953-
self.wait_for_ready_state_complete()
4954-
4955-
def __are_quotes_escaped(self, string):
4956-
return js_utils.are_quotes_escaped(string)
4957-
4958-
def __escape_quotes_if_needed(self, string):
4959-
return js_utils.escape_quotes_if_needed(string)
4960-
4961-
def __is_in_frame(self):
4962-
return js_utils.is_in_frame(self.driver)
4963-
49644956
def bring_active_window_to_front(self):
49654957
"""Brings the active browser window to the front.
49664958
This is useful when multiple drivers are being used."""
@@ -6813,16 +6805,8 @@ def get_chromedriver_version(self):
68136805
return chromedriver_version
68146806

68156807
def is_chromedriver_too_old(self):
6816-
"""There are known issues with chromedriver versions below 73.
6817-
This can impact tests that need to hover over an element, or ones
6818-
that require a custom downloads folder ("./downloaded_files").
6819-
Due to the situation that newer versions of chromedriver require
6820-
an exact match to the version of Chrome, an "old" version of
6821-
chromedriver is installed by default. It is then up to the user
6822-
to upgrade to the correct version of chromedriver from there.
6823-
This method can be used to change test behavior when trying
6824-
to perform an action that is impacted by having an old version
6825-
of chromedriver installed."""
6808+
"""Before chromedriver 73, there was no version check, which
6809+
means it's possible to run a new Chrome with old drivers."""
68266810
self.__check_scope()
68276811
self.__fail_if_not_using_chrome("is_chromedriver_too_old()")
68286812
if int(self.get_chromedriver_version().split(".")[0]) < 73:
@@ -8189,9 +8173,6 @@ def _print(self, msg):
81898173
else:
81908174
print(msg)
81918175

8192-
def start_tour(self, name=None, interval=0):
8193-
self.play_tour(name=name, interval=interval)
8194-
81958176
############
81968177

81978178
def add_css_link(self, css_link):
@@ -9960,7 +9941,6 @@ def play_tour(self, name=None, interval=0):
99609941
interval=interval,
99619942
)
99629943
else:
9963-
# "Shepherd"
99649944
tour_helper.play_shepherd_tour(
99659945
self.driver,
99669946
self._tour_steps,
@@ -9969,6 +9949,10 @@ def play_tour(self, name=None, interval=0):
99699949
interval=interval,
99709950
)
99719951

9952+
def start_tour(self, name=None, interval=0):
9953+
"""Same as self.play_tour()"""
9954+
self.play_tour(name=name, interval=interval)
9955+
99729956
def export_tour(self, name=None, filename="my_tour.js", url=None):
99739957
"""Exports a tour as a JS file.
99749958
You can call self.export_tour() anywhere where you would
@@ -11425,6 +11409,17 @@ def quit_extra_driver(self, driver=None):
1142511409

1142611410
############
1142711411

11412+
def __are_quotes_escaped(self, string):
11413+
return js_utils.are_quotes_escaped(string)
11414+
11415+
def __escape_quotes_if_needed(self, string):
11416+
return js_utils.escape_quotes_if_needed(string)
11417+
11418+
def __is_in_frame(self):
11419+
return js_utils.is_in_frame(self.driver)
11420+
11421+
############
11422+
1142811423
def __assert_eq(self, *args, **kwargs):
1142911424
"""Minified assert_equal() using only the list diff."""
1143011425
minified_exception = None
@@ -12826,8 +12821,6 @@ def __activate_virtual_display_as_needed(self):
1282612821

1282712822
############
1282812823

12829-
from seleniumbase.common import decorators
12830-
1283112824
@decorators.deprecated("You should use re.escape() instead.")
1283212825
def jq_format(self, code):
1283312826
# DEPRECATED - re.escape() already performs the intended action.

seleniumbase/fixtures/shared_utils.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
"""
2-
This module contains shared utility methods.
3-
"""
1+
"""Shared utility methods."""
2+
43
import subprocess
54
import sys
65
from seleniumbase.fixtures import constants
@@ -50,9 +49,7 @@ def get_terminal_width():
5049

5150

5251
def format_exc(exception, message):
53-
"""
54-
Formats an exception message to make the output cleaner.
55-
"""
52+
"""Formats an exception message to make the output cleaner."""
5653
from selenium.common.exceptions import ElementNotVisibleException
5754
from selenium.common.exceptions import NoAlertPresentException
5855
from selenium.common.exceptions import NoSuchAttributeException

0 commit comments

Comments
 (0)