Skip to content

Commit afc8002

Browse files
authored
Merge pull request #1037 from seleniumbase/mostly-recorder-mode-updates
Mostly Recorder Mode updates
2 parents 2913f31 + ac34d59 commit afc8002

File tree

12 files changed

+213
-107
lines changed

12 files changed

+213
-107
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ COMMANDS:
108108
options (List common pytest options)
109109
mkdir [DIRECTORY] [OPTIONS]
110110
mkfile [FILE.py] [OPTIONS]
111-
mkrec / codegen [FILE.py]
111+
mkrec / codegen [FILE.py] [OPTIONS]
112112
mkpres [FILE.py] [LANG]
113113
mkchart [FILE.py] [LANG]
114114
print [FILE] [OPTIONS]

help_docs/recorder_mode.md

Lines changed: 58 additions & 42 deletions
Large diffs are not rendered by default.

mkdocs_build/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
regex>=2021.10.23
22
tqdm>=4.62.3
3-
docutils==0.17.1
3+
docutils==0.18
44
python-dateutil==2.8.2
55
livereload==2.6.3;python_version>="3.6"
66
joblib==1.1.0;python_version>="3.6"
77
Markdown==3.3.4;python_version>="3.6"
88
MarkupSafe==2.0.1;python_version>="3.6"
9-
pyparsing==3.0.1;python_version>="3.6"
9+
pyparsing==3.0.3;python_version>="3.6"
1010
keyring==23.2.1;python_version>="3.6"
1111
pkginfo==1.7.1;python_version>="3.6"
1212
Jinja2==3.0.2;python_version>="3.6"
@@ -21,7 +21,7 @@ lunr==0.6.1;python_version>="3.6"
2121
nltk==3.6.5;python_version>="3.6"
2222
watchdog==2.1.6;python_version>="3.6"
2323
mkdocs==1.2.3;python_version>="3.6"
24-
mkdocs-material==7.3.4;python_version>="3.6"
24+
mkdocs-material==7.3.5;python_version>="3.6"
2525
mkdocs-exclude-search==0.5.2;python_version>="3.6"
2626
mkdocs-simple-hooks==0.1.3
2727
mkdocs-material-extensions==1.0.3;python_version>="3.6"

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "2.0.7"
2+
__version__ = "2.0.8"

seleniumbase/console_scripts/ReadMe.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ COMMANDS:
1919
options (List common pytest options)
2020
mkdir [DIRECTORY] [OPTIONS]
2121
mkfile [FILE.py] [OPTIONS]
22-
mkrec / codegen [FILE.py]
22+
mkrec / codegen [FILE.py] [OPTIONS]
2323
mkpres [FILE.py] [LANG]
2424
mkchart [FILE.py] [LANG]
2525
print [FILE] [OPTIONS]
@@ -225,12 +225,18 @@ is included.
225225
<h3>mkrec / codegen</h3>
226226

227227
* Usage:
228-
``sbase mkrec [FILE.py]``
229-
``sbase codegen [FILE.py]``
228+
``sbase mkrec [FILE.py] [OPTIONS]``
229+
``sbase codegen [FILE.py] [OPTIONS]``
230230

231231
* Examples:
232232
``sbase mkrec new_test.py``
233+
``sbase mkrec new_test.py --url=seleniumbase.io``
233234
``sbase codegen new_test.py``
235+
``sbase codegen new_test.py --url=wikipedia.org``
236+
237+
* Options:
238+
``--url=URL`` (Sets the initial start page URL.)
239+
``--edge`` (Use Edge browser instead of Chrome.)
234240

235241
* Output:
236242
Creates a new SeleniumBase test using the Recorder.

seleniumbase/console_scripts/run.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
sbase options
1212
sbase mkdir ui_tests
1313
sbase mkfile new_test.py
14-
sbase mkrec new_test.py # Same as "sbase codegen new_test.py"
14+
sbase mkrec new_test.py
15+
sbase mkrec new_test.py --url=wikipedia.org
16+
sbase codegen new_test.py --url=wikipedia.org
1517
sbase mkpres new_presentation.py
1618
sbase mkchart new_chart.py
1719
sbase convert webdriver_unittest_file.py
@@ -75,7 +77,7 @@ def show_basic_usage():
7577
sc += " options (List common pytest options)\n"
7678
sc += " mkdir [DIRECTORY] [OPTIONS]\n"
7779
sc += " mkfile [FILE.py] [OPTIONS]\n"
78-
sc += " mkrec / codegen [FILE.py]\n"
80+
sc += " mkrec / codegen [FILE.py] [OPTIONS]\n"
7981
sc += " mkpres [FILE.py] [LANG]\n"
8082
sc += " mkchart [FILE.py] [LANG]\n"
8183
sc += " print [FILE] [OPTIONS]\n"
@@ -203,10 +205,14 @@ def show_mkrec_usage():
203205
print(sc)
204206
print("")
205207
print(" Usage:")
206-
print(" seleniumbase mkrec [FILE.py]")
207-
print(" OR: sbase mkrec [FILE.py]")
208-
print(" Example:")
208+
print(" seleniumbase mkrec [FILE.py] [OPTIONS]")
209+
print(" OR: sbase mkrec [FILE.py] [OPTIONS]")
210+
print(" Examples:")
209211
print(" sbase mkrec new_test.py")
212+
print(" sbase mkrec new_test.py --url=wikipedia.org")
213+
print(" Options:")
214+
print(" --url=URL (Sets the initial start page URL.)")
215+
print(" --edge (Use Edge browser instead of Chrome.)")
210216
print(" Output:")
211217
print(" Creates a new SeleniumBase test using the Recorder.")
212218
print(" If the filename already exists, an error is raised.")
@@ -221,10 +227,14 @@ def show_codegen_usage():
221227
print(sc)
222228
print("")
223229
print(" Usage:")
224-
print(" seleniumbase codegen [FILE.py]")
225-
print(" OR: sbase codegen [FILE.py]")
226-
print(" Example:")
230+
print(" seleniumbase codegen [FILE.py] [OPTIONS]")
231+
print(" OR: sbase codegen [FILE.py] [OPTIONS]")
232+
print(" Examples:")
227233
print(" sbase codegen new_test.py")
234+
print(" sbase codegen new_test.py --url=wikipedia.org")
235+
print(" Options:")
236+
print(" --url=URL (Sets the initial start page URL.)")
237+
print(" --edge (Use Edge browser instead of Chrome.)")
228238
print(" Output:")
229239
print(" Creates a new SeleniumBase test using the Recorder.")
230240
print(" If the filename already exists, an error is raised.")

seleniumbase/console_scripts/sb_mkrec.py

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
Creates a new SeleniumBase test file using the Recorder.
44
55
Usage:
6-
seleniumbase mkrec [FILE.py]
7-
sbase mkrec [FILE.py]
8-
seleniumbase codegen [FILE.py]
9-
sbase codegen [FILE.py]
6+
seleniumbase mkrec [FILE.py] [OPTIONS]
7+
sbase mkrec [FILE.py] [OPTIONS]
8+
seleniumbase codegen [FILE.py] [OPTIONS]
9+
sbase codegen [FILE.py] [OPTIONS]
1010
1111
Examples:
1212
sbase mkrec new_test.py
13+
sbase mkrec new_test.py --url=seleniumbase.io
1314
sbase codegen new_test.py
15+
sbase codegen new_test.py --url=wikipedia.org
16+
17+
Options:
18+
--url=URL (Sets the initial start page URL.)
19+
--edge (Use Edge browser instead of Chrome.)
1420
1521
Output:
1622
Creates a new SeleniumBase test using the Recorder.
@@ -34,6 +40,9 @@ def invalid_run_command(msg=None):
3440
exp += " Examples:\n"
3541
exp += " sbase mkrec new_test.py\n"
3642
exp += " sbase codegen new_test.py\n"
43+
exp += " Options:\n"
44+
exp += " --url=URL (Sets the initial start page URL.)\n"
45+
exp += " --edge (Use Edge browser instead of Chrome.)\n"
3746
exp += " Output:\n"
3847
exp += " Creates a new SeleniumBase test using the Recorder.\n"
3948
exp += " If the filename already exists, an error is raised.\n"
@@ -65,6 +74,9 @@ def main():
6574
help_me = False
6675
error_msg = None
6776
invalid_cmd = None
77+
use_edge = False
78+
start_page = None
79+
next_is_url = False
6880

6981
command_args = sys.argv[2:]
7082
file_name = command_args[0]
@@ -87,9 +99,17 @@ def main():
8799
if len(command_args) >= 2:
88100
options = command_args[1:]
89101
for option in options:
90-
option = option.lower()
91-
if option == "-h" or option == "--help":
102+
if option.lower() == "-h" or option.lower() == "--help":
92103
help_me = True
104+
elif option.lower() == "--edge":
105+
use_edge = True
106+
elif option.lower().startswith("--url="):
107+
start_page = option[len("--url="):]
108+
elif option.lower() == "--url":
109+
next_is_url = True
110+
elif next_is_url:
111+
start_page = option
112+
next_is_url = False
93113
else:
94114
invalid_cmd = "\n===> INVALID OPTION: >> %s <<\n" % option
95115
invalid_cmd = invalid_cmd.replace(">> ", ">>" + c5 + " ")
@@ -121,8 +141,18 @@ def main():
121141
"" + c1 + file_name + "" + cr + "\n"
122142
)
123143
print(success)
124-
print("pytest %s --rec -q -s" % file_name)
125-
os.system("pytest %s --rec -q -s" % file_name)
144+
if not start_page:
145+
run_cmd = "pytest %s --rec -q -s" % file_name
146+
if use_edge:
147+
run_cmd += " --edge"
148+
print(run_cmd)
149+
os.system(run_cmd)
150+
else:
151+
run_cmd = "pytest %s --rec -q -s --url=%s" % (file_name, start_page)
152+
if use_edge:
153+
run_cmd += " --edge"
154+
print(run_cmd)
155+
os.system(run_cmd)
126156
if os.path.exists(file_path):
127157
os.remove(file_path)
128158
recorded_filename = file_name[:-3] + "_rec.py"

seleniumbase/extensions/recorder.zip

222 Bytes
Binary file not shown.

seleniumbase/fixtures/base_case.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def __init__(self, *args, **kwargs):
9595
self.__last_page_url = None
9696
self.__last_page_source = None
9797
self.__skip_reason = None
98+
self.__dont_record_open = False
9899
self.__dont_record_js_click = False
99100
self.__new_window_on_rec_open = True
100101
self.__overrided_default_timeouts = False
@@ -142,7 +143,7 @@ def open(self, url):
142143
if url.startswith("://"):
143144
# Convert URLs such as "://google.com" into "https://google.com"
144145
url = "https" + url
145-
if self.recorder_mode:
146+
if self.recorder_mode and not self.__dont_record_open:
146147
time_stamp = self.execute_script("return Date.now();")
147148
origin = self.get_origin()
148149
action = ["_url_", origin, url, time_stamp]
@@ -774,9 +775,11 @@ def open_start_page(self):
774775
if page_utils.is_valid_url(start_page):
775776
self.open(start_page)
776777
else:
777-
new_start_page = "http://" + start_page
778+
new_start_page = "https://" + start_page
778779
if page_utils.is_valid_url(new_start_page):
780+
self.__dont_record_open = True
779781
self.open(new_start_page)
782+
self.__dont_record_open = False
780783
else:
781784
logging.info('Invalid URL: "%s"!' % start_page)
782785
self.open("data:,")
@@ -2905,9 +2908,11 @@ def get_new_driver(
29052908
if page_utils.is_valid_url(self.start_page):
29062909
self.open(self.start_page)
29072910
else:
2908-
new_start_page = "http://" + self.start_page
2911+
new_start_page = "https://" + self.start_page
29092912
if page_utils.is_valid_url(new_start_page):
2913+
self.__dont_record_open = True
29102914
self.open(new_start_page)
2915+
self.__dont_record_open = False
29112916
return new_driver
29122917

29132918
def switch_to_driver(self, driver):
@@ -10494,10 +10499,12 @@ def setUp(self, masterqa_mode=False):
1049410499
self.open(self.start_page)
1049510500
self.__new_window_on_rec_open = True
1049610501
else:
10497-
new_start_page = "http://" + self.start_page
10502+
new_start_page = "https://" + self.start_page
1049810503
if page_utils.is_valid_url(new_start_page):
1049910504
good_start_page = True
10505+
self.__dont_record_open = True
1050010506
self.open(new_start_page)
10507+
self.__dont_record_open = False
1050110508
if self.recorder_ext or (self._crumbs and not good_start_page):
1050210509
if self.get_current_url() != "data:,":
1050310510
self.__new_window_on_rec_open = False
@@ -10822,6 +10829,7 @@ def __create_log_path_as_needed(self, test_logpath):
1082210829
def __process_dashboard(self, has_exception, init=False):
1082310830
""" SeleniumBase Dashboard Processing """
1082410831
if self._multithreaded:
10832+
existing_res = sb_config._results # For recording "Skipped" tests
1082510833
abs_path = os.path.abspath(".")
1082610834
dash_json_loc = constants.Dashboard.DASH_JSON
1082710835
dash_jsonpath = os.path.join(abs_path, dash_json_loc)
@@ -10908,8 +10916,8 @@ def __process_dashboard(self, has_exception, init=False):
1090810916
sb_config.item_count_untested -= 1
1090910917
elif (
1091010918
self._multithreaded
10911-
and test_id in sb_config._results.keys()
10912-
and sb_config._results[test_id] == "Skipped"
10919+
and test_id in existing_res.keys()
10920+
and existing_res[test_id] == "Skipped"
1091310921
):
1091410922
sb_config._results[test_id] = "Skipped"
1091510923
sb_config.item_count_skipped += 1

seleniumbase/fixtures/shared_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
from selenium.common.exceptions import NoSuchElementException
99
from selenium.common.exceptions import NoSuchFrameException
1010
from selenium.common.exceptions import NoSuchWindowException
11-
from seleniumbase.common.exceptions import NoSuchFileException
12-
from seleniumbase.common.exceptions import TimeLimitExceededException
1311
from seleniumbase import config as sb_config
1412

1513

1614
def format_exc(exception, message):
1715
"""
1816
Formats an exception message to make the output cleaner.
1917
"""
18+
from seleniumbase.common.exceptions import NoSuchFileException
19+
2020
if exception == Exception:
2121
exc = Exception
2222
return exc, message
@@ -65,6 +65,8 @@ def _format_message(message):
6565

6666

6767
def __time_limit_exceeded(message):
68+
from seleniumbase.common.exceptions import TimeLimitExceededException
69+
6870
raise TimeLimitExceededException(message)
6971

7072

0 commit comments

Comments
 (0)