Skip to content

Commit c3ce0b0

Browse files
committed
Make the Recorder stealthier
1 parent 4c455c4 commit c3ce0b0

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

seleniumbase/console_scripts/sb_mkrec.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,28 @@ def main():
181181
data.append("")
182182
data.append("class RecorderTest(BaseCase):")
183183
data.append(" def test_recording(self):")
184+
if use_uc:
185+
data.append(" if self.undetectable:")
186+
if (
187+
start_page
188+
and (
189+
start_page.startswith("http:")
190+
or start_page.startswith("https:")
191+
or start_page.startswith("file:")
192+
)
193+
):
194+
used_sp = start_page
195+
if '"' not in start_page:
196+
used_sp = '"%s"' % start_page
197+
elif "'" not in start_page:
198+
used_sp = "'%s'" % start_page
199+
data.append(
200+
" self.uc_open_with_disconnect(\n"
201+
" %s\n"
202+
" )" % used_sp
203+
)
204+
else:
205+
data.append(" self.disconnect()")
184206
data.append(" if self.recorder_ext:")
185207
data.append(" # When done recording actions,")
186208
data.append(' # type "c", and press [Enter].')
@@ -231,7 +253,18 @@ def main():
231253
)
232254
print(success)
233255
run_cmd = None
234-
if not start_page:
256+
if (
257+
not start_page
258+
or (
259+
use_uc
260+
and (
261+
start_page.startswith("http:")
262+
or start_page.startswith("https:")
263+
or start_page.startswith("file:")
264+
)
265+
and not esc_end
266+
)
267+
):
235268
run_cmd = "%s -m pytest %s --rec -q -s" % (sys_executable, file_name)
236269
else:
237270
run_cmd = "%s -m pytest %s --rec -q -s --url=%s" % (

seleniumbase/console_scripts/sb_recorder.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ def do_playback(file_name, use_chrome, window, demo_mode=False):
197197
command += " --edge"
198198
if demo_mode:
199199
command += " --demo"
200+
command_args = sys.argv[2:]
201+
if (
202+
"--uc" in command_args
203+
or "--undetected" in command_args
204+
or "--undetectable" in command_args
205+
):
206+
command += " --uc"
200207
poll = None
201208
if sb_config.rec_subprocess_used:
202209
poll = sb_config.rec_subprocess_p.poll()

seleniumbase/fixtures/base_case.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16029,6 +16029,11 @@ def tearDown(self):
1602916029
# This test already called tearDown()
1603016030
return
1603116031
if hasattr(self, "recorder_mode") and self.recorder_mode:
16032+
if self.undetectable:
16033+
try:
16034+
self.driver.window_handles
16035+
except Exception:
16036+
self.driver.connect()
1603216037
self.__process_recorded_actions()
1603316038
self.__called_teardown = True
1603416039
self.__called_setup = False

0 commit comments

Comments
 (0)