Skip to content

Commit 8f46524

Browse files
committed
More refactoring
1 parent b2fe300 commit 8f46524

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ def __init__(self, *args, **kwargs):
7676
self.environment = None
7777
self.__last_url_of_delayed_assert = "data:,"
7878
self.__last_page_load_url = "data:,"
79-
self._page_check_count = 0
80-
self._page_check_failures = []
81-
self._html_report_extra = []
79+
self.__page_check_count = 0
80+
self.__page_check_failures = []
81+
self._html_report_extra = [] # (Used by pytest_plugin.py)
8282
self._default_driver = None
8383
self._drivers_list = []
84-
self._tutorials = {}
84+
self._tour_steps = {}
8585

8686
def open(self, url):
8787
self.__last_page_load_url = None
@@ -951,11 +951,11 @@ def is_shepherd_activated(self):
951951
return False
952952

953953
def create_tour(self, name=None, theme=None):
954-
""" Creates a tutorial tour for a website.
954+
""" Creates a tour for a website.
955955
@Params
956956
name - If creating multiple tours, use this to select the
957957
tour you wish to add steps to.
958-
theme - Sets the default theme for the tutorial tour.
958+
theme - Sets the default theme for the tour.
959959
Choose from "arrows", "dark", "default", "square", and
960960
"square-dark". ("arrows" is used if None is selected.)
961961
"""
@@ -975,19 +975,19 @@ def create_tour(self, name=None, theme=None):
975975
elif theme == "square-dark":
976976
shepherd_theme = "shepherd-theme-square-dark"
977977

978-
tutorial = ("""let tour = new Shepherd.Tour({
978+
new_tour = ("""let tour = new Shepherd.Tour({
979979
defaults: {
980980
classes: '%s',
981981
scrollTo: true
982982
}
983983
});""" % shepherd_theme)
984984

985-
self._tutorials[name] = []
986-
self._tutorials[name].append(tutorial)
985+
self._tour_steps[name] = []
986+
self._tour_steps[name].append(new_tour)
987987

988988
def add_tour_step(self, message, selector=None, name=None,
989989
title=None, theme=None, alignment=None):
990-
""" Allows the user to add tutorial tour steps for a website.
990+
""" Allows the user to add tour steps for a website.
991991
@Params
992992
message - The message to display.
993993
selector - The CSS Selector of the Element to attach to.
@@ -1005,7 +1005,7 @@ def add_tour_step(self, message, selector=None, name=None,
10051005

10061006
if not name:
10071007
name = "default"
1008-
if name not in self._tutorials:
1008+
if name not in self._tour_steps:
10091009
self.create_tour(name=name)
10101010

10111011
if not title:
@@ -1030,7 +1030,7 @@ def add_tour_step(self, message, selector=None, name=None,
10301030
else:
10311031
shepherd_base_theme = re.search(
10321032
"[\S\s]+classes: '([\S\s]+)',[\S\s]+",
1033-
self._tutorials[name][0]).group(1)
1033+
self._tour_steps[name][0]).group(1)
10341034
shepherd_theme = shepherd_base_theme
10351035

10361036
if not alignment or (
@@ -1050,35 +1050,35 @@ def add_tour_step(self, message, selector=None, name=None,
10501050
});""" % (
10511051
name, title, shepherd_classes, message, selector, alignment))
10521052

1053-
self._tutorials[name].append(step)
1053+
self._tour_steps[name].append(step)
10541054

10551055
def play_tour(self, name=None):
1056-
""" Plays a tutorial tour on the current website.
1056+
""" Plays a tour on the current website.
10571057
@Params
10581058
name - If creating multiple tours, use this to select the
10591059
tour you wish to play.
10601060
"""
10611061
if self.headless:
1062-
return # Tutorial tours should not run in headless mode.
1062+
return # Tours should not run in headless mode.
10631063

10641064
if not name:
10651065
name = "default"
1066-
if name not in self._tutorials:
1066+
if name not in self._tour_steps:
10671067
raise Exception("Tour {%s} does not exist!" % name)
10681068

10691069
instructions = ""
1070-
for tutorial_step in self._tutorials[name]:
1071-
instructions += tutorial_step
1070+
for tour_step in self._tour_steps[name]:
1071+
instructions += tour_step
10721072
instructions += "tour.start();"
10731073

10741074
if not self.is_shepherd_activated():
10751075
self.activate_shepherd()
10761076

1077-
if len(self._tutorials[name]) > 1:
1077+
if len(self._tour_steps[name]) > 1:
10781078
try:
10791079
selector = re.search(
10801080
"[\S\s]+{element: '([\S\s]+)', on: [\S\s]+",
1081-
self._tutorials[name][1]).group(1)
1081+
self._tour_steps[name][1]).group(1)
10821082
self.__wait_for_css_query_selector(selector)
10831083
except Exception:
10841084
self.__post_messenger_error_message(
@@ -1091,17 +1091,17 @@ def play_tour(self, name=None):
10911091
"" % selector)
10921092

10931093
self.execute_script(instructions)
1094-
tutorial_on = True
1095-
while tutorial_on:
1094+
tour_on = True
1095+
while tour_on:
10961096
try:
10971097
time.sleep(0.01)
10981098
result = self.execute_script(
10991099
"return Shepherd.activeTour.currentStep.isOpen()")
11001100
except Exception:
1101-
tutorial_on = False
1101+
tour_on = False
11021102
result = None
11031103
if result:
1104-
tutorial_on = True
1104+
tour_on = True
11051105
else:
11061106
try:
11071107
time.sleep(0.01)
@@ -1119,9 +1119,9 @@ def play_tour(self, name=None):
11191119
duration=settings.SMALL_TIMEOUT)
11201120
time.sleep(0.1)
11211121
self.execute_script("Shepherd.activeTour.next()")
1122-
tutorial_on = True
1122+
tour_on = True
11231123
except Exception:
1124-
tutorial_on = False
1124+
tour_on = False
11251125
time.sleep(0.1)
11261126

11271127
def __wait_for_css_query_selector(
@@ -1828,8 +1828,8 @@ def pick_select_option_by_text(self, dropdown_selector, option,
18281828
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
18291829
timeout = self.__get_new_timeout(timeout)
18301830
self.__pick_select_option(dropdown_selector, option,
1831-
dropdown_by=dropdown_by, option_by="text",
1832-
timeout=timeout)
1831+
dropdown_by=dropdown_by, option_by="text",
1832+
timeout=timeout)
18331833

18341834
def pick_select_option_by_index(self, dropdown_selector, option,
18351835
dropdown_by=By.CSS_SELECTOR,
@@ -1838,8 +1838,8 @@ def pick_select_option_by_index(self, dropdown_selector, option,
18381838
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
18391839
timeout = self.__get_new_timeout(timeout)
18401840
self.__pick_select_option(dropdown_selector, option,
1841-
dropdown_by=dropdown_by, option_by="index",
1842-
timeout=timeout)
1841+
dropdown_by=dropdown_by, option_by="index",
1842+
timeout=timeout)
18431843

18441844
def pick_select_option_by_value(self, dropdown_selector, option,
18451845
dropdown_by=By.CSS_SELECTOR,
@@ -1848,8 +1848,8 @@ def pick_select_option_by_value(self, dropdown_selector, option,
18481848
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
18491849
timeout = self.__get_new_timeout(timeout)
18501850
self.__pick_select_option(dropdown_selector, option,
1851-
dropdown_by=dropdown_by, option_by="value",
1852-
timeout=timeout)
1851+
dropdown_by=dropdown_by, option_by="value",
1852+
timeout=timeout)
18531853

18541854
def generate_referral(self, start_page, destination_page):
18551855
""" This method opens the start_page, creates a referral link there,
@@ -2348,16 +2348,16 @@ def __add_delayed_assert_failure(self):
23482348
""" Add a delayed_assert failure into a list for future processing. """
23492349
current_url = self.driver.current_url
23502350
message = self.__get_exception_message()
2351-
self._page_check_failures.append(
2351+
self.__page_check_failures.append(
23522352
"CHECK #%s: (%s)\n %s" % (
2353-
self._page_check_count, current_url, message))
2353+
self.__page_check_count, current_url, message))
23542354

23552355
def delayed_assert_element(self, selector, by=By.CSS_SELECTOR,
23562356
timeout=settings.MINI_TIMEOUT):
23572357
""" A non-terminating assertion for an element on a page.
23582358
Failures will be saved until the process_delayed_asserts()
23592359
method is called from inside a test, likely at the end of it. """
2360-
self._page_check_count += 1
2360+
self.__page_check_count += 1
23612361
try:
23622362
url = self.get_current_url()
23632363
if url == self.__last_url_of_delayed_assert:
@@ -2384,7 +2384,7 @@ def delayed_assert_text(self, text, selector, by=By.CSS_SELECTOR,
23842384
""" A non-terminating assertion for text from an element on a page.
23852385
Failures will be saved until the process_delayed_asserts()
23862386
method is called from inside a test, likely at the end of it. """
2387-
self._page_check_count += 1
2387+
self.__page_check_count += 1
23882388
try:
23892389
url = self.get_current_url()
23902390
if url == self.__last_url_of_delayed_assert:
@@ -2417,12 +2417,12 @@ def process_delayed_asserts(self, print_only=False):
24172417
the delayed asserts on a single html page so that the failure
24182418
screenshot matches the location of the delayed asserts.
24192419
If "print_only" is set to True, the exception won't get raised. """
2420-
if self._page_check_failures:
2420+
if self.__page_check_failures:
24212421
exception_output = ''
24222422
exception_output += "\n*** DELAYED ASSERTION FAILURES FOR: "
24232423
exception_output += "%s\n" % self.id()
2424-
all_failing_checks = self._page_check_failures
2425-
self._page_check_failures = []
2424+
all_failing_checks = self.__page_check_failures
2425+
self.__page_check_failures = []
24262426
for tb in all_failing_checks:
24272427
exception_output += "%s\n" % tb
24282428
if print_only:
@@ -2495,8 +2495,8 @@ def __click_dropdown_link_text(self, link_text, link_css):
24952495
return False
24962496

24972497
def __pick_select_option(self, dropdown_selector, option,
2498-
dropdown_by=By.CSS_SELECTOR, option_by="text",
2499-
timeout=settings.SMALL_TIMEOUT):
2498+
dropdown_by=By.CSS_SELECTOR, option_by="text",
2499+
timeout=settings.SMALL_TIMEOUT):
25002500
""" Picks an HTML <select> option by specification.
25012501
Option specifications are by "text", "index", or "value".
25022502
Defaults to "text" if option_by is unspecified or unknown. """
@@ -2888,7 +2888,7 @@ def tearDown(self):
28882888
has_exception = True
28892889
else:
28902890
has_exception = sys.exc_info()[1] is not None
2891-
if self._page_check_failures:
2891+
if self.__page_check_failures:
28922892
print(
28932893
"\nWhen using self.delayed_assert_*() methods in your tests, "
28942894
"remember to call self.process_delayed_asserts() afterwards. "

0 commit comments

Comments
 (0)