@@ -97,6 +97,7 @@ def __init__(self, *args, **kwargs):
97
97
self .__last_page_source = None
98
98
self .__skip_reason = None
99
99
self .__dont_record_js_click = False
100
+ self .__new_window_on_rec_open = True
100
101
self .__overrided_default_timeouts = False
101
102
self .__added_pytest_html_extra = None
102
103
self .__deferred_assert_count = 0
@@ -143,6 +144,11 @@ def open(self, url):
143
144
# Convert URLs such as "://google.com" into "https://google.com"
144
145
url = "https" + url
145
146
if self .recorder_mode :
147
+ time_stamp = self .execute_script ("return Date.now();" )
148
+ origin = self .get_origin ()
149
+ action = ["_url_" , origin , url , time_stamp ]
150
+ self .__extra_actions .append (action )
151
+ if self .recorder_mode and self .__new_window_on_rec_open :
146
152
c_url = self .driver .current_url
147
153
if ("http:" ) in c_url or ("https:" ) in c_url or ("file:" ) in c_url :
148
154
if self .get_domain_url (url ) != self .get_domain_url (c_url ):
@@ -3125,6 +3131,12 @@ def install_addon(self, xpi_file):
3125
3131
xpi_path = os .path .abspath (xpi_file )
3126
3132
self .driver .install_addon (xpi_path , temporary = True )
3127
3133
3134
+ def activate_demo_mode (self ):
3135
+ self .demo_mode = True
3136
+
3137
+ def deactivate_demo_mode (self ):
3138
+ self .demo_mode = False
3139
+
3128
3140
def activate_design_mode (self ):
3129
3141
# Activate Chrome's Design Mode, which lets you edit a site directly.
3130
3142
# See: https://twitter.com/sulco/status/1177559150563344384
@@ -3267,6 +3279,16 @@ def __process_recorded_actions(self):
3267
3279
url2 = url2 [:- 1 ]
3268
3280
if url1 == url2 :
3269
3281
srt_actions [n - 1 ][0 ] = "_skip"
3282
+ elif url2 .startswith (url1 ):
3283
+ srt_actions [n ][0 ] = "f_url"
3284
+ for n in range (len (srt_actions )):
3285
+ if (
3286
+ srt_actions [n ][0 ] == "input"
3287
+ and n > 0
3288
+ and srt_actions [n - 1 ][0 ] == "input"
3289
+ and srt_actions [n - 1 ][2 ] == ""
3290
+ ):
3291
+ srt_actions [n - 1 ][0 ] = "_skip"
3270
3292
for n in range (len (srt_actions )):
3271
3293
if (
3272
3294
(srt_actions [n ][0 ] == "begin" or srt_actions [n ][0 ] == "_url_" )
@@ -3336,8 +3358,10 @@ def __process_recorded_actions(self):
3336
3358
):
3337
3359
srt_actions [n - 1 ][0 ] = "_skip"
3338
3360
ext_actions = []
3361
+ ext_actions .append ("_url_" )
3339
3362
ext_actions .append ("js_cl" )
3340
3363
ext_actions .append ("js_ca" )
3364
+ ext_actions .append ("js_ty" )
3341
3365
ext_actions .append ("as_el" )
3342
3366
ext_actions .append ("as_ep" )
3343
3367
ext_actions .append ("asenv" )
@@ -3365,8 +3389,21 @@ def __process_recorded_actions(self):
3365
3389
origin = srt_actions [n ][2 ][1 ]
3366
3390
if origin .endswith ("/" ):
3367
3391
origin = origin [0 :- 1 ]
3392
+ if srt_actions [n ][0 ] == "js_ty" :
3393
+ srt_actions [n ][2 ] = srt_actions [n ][1 ][1 ]
3394
+ srt_actions [n ][1 ] = srt_actions [n ][1 ][0 ]
3395
+ if srt_actions [n ][0 ] == "_url_" and origin not in origins :
3396
+ origins .append (origin )
3368
3397
if origin not in origins :
3369
3398
srt_actions [n ][0 ] = "_skip"
3399
+ for n in range (len (srt_actions )):
3400
+ if (
3401
+ srt_actions [n ][0 ] == "input"
3402
+ and n > 0
3403
+ and srt_actions [n - 1 ][0 ] == "js_ty"
3404
+ and srt_actions [n ][2 ] == srt_actions [n - 1 ][2 ]
3405
+ ):
3406
+ srt_actions [n ][0 ] = "_skip"
3370
3407
for n in range (len (srt_actions )):
3371
3408
cleaned_actions .append (srt_actions [n ])
3372
3409
for action in srt_actions :
@@ -3392,8 +3429,10 @@ def __process_recorded_actions(self):
3392
3429
sb_actions .append ('self.%s("%s")' % (method , action [1 ]))
3393
3430
else :
3394
3431
sb_actions .append ("self.%s('%s')" % (method , action [1 ]))
3395
- elif action [0 ] == "input" :
3432
+ elif action [0 ] == "input" or action [ 0 ] == "js_ty" :
3396
3433
method = "type"
3434
+ if action [0 ] == "js_ty" :
3435
+ method = "js_type"
3397
3436
text = action [2 ].replace ("\n " , "\\ n" )
3398
3437
if '"' not in action [1 ] and '"' not in text :
3399
3438
sb_actions .append ('self.%s("%s", "%s")' % (
@@ -5233,6 +5272,7 @@ def set_value(
5233
5272
text = str (text )
5234
5273
value = re .escape (text )
5235
5274
value = self .__escape_quotes_if_needed (value )
5275
+ pre_escape_css_selector = css_selector
5236
5276
css_selector = re .escape (css_selector ) # Add "\\" to special chars
5237
5277
css_selector = self .__escape_quotes_if_needed (css_selector )
5238
5278
the_type = None
@@ -5247,6 +5287,12 @@ def set_value(
5247
5287
value ,
5248
5288
)
5249
5289
self .execute_script (script )
5290
+ if self .recorder_mode :
5291
+ time_stamp = self .execute_script ("return Date.now();" )
5292
+ origin = self .get_origin ()
5293
+ sel_tex = [pre_escape_css_selector , text ]
5294
+ action = ["js_ty" , sel_tex , origin , time_stamp ]
5295
+ self .__extra_actions .append (action )
5250
5296
else :
5251
5297
script = """jQuery('%s')[0].value='%s';""" % (css_selector , value )
5252
5298
self .safe_execute_script (script )
@@ -10336,6 +10382,11 @@ def setUp(self, masterqa_mode=False):
10336
10382
self ._dash_initialized = True
10337
10383
self .__process_dashboard (False , init = True )
10338
10384
10385
+ # Set the JS start time for Recorder Mode if reusing the session.
10386
+ # Use this to skip saving recorded actions from previous tests.
10387
+ if self .recorder_mode and self ._reuse_session :
10388
+ self .__js_start_time = int (time .time () * 1000.0 )
10389
+
10339
10390
has_url = False
10340
10391
if self ._reuse_session :
10341
10392
if not hasattr (sb_config , "shared_driver" ):
@@ -10360,18 +10411,27 @@ def setUp(self, masterqa_mode=False):
10360
10411
except Exception :
10361
10412
pass
10362
10413
if self ._reuse_session and sb_config .shared_driver and has_url :
10414
+ good_start_page = False
10415
+ if self .recorder_ext :
10416
+ self .__js_start_time = int (time .time () * 1000.0 )
10363
10417
if self .start_page and len (self .start_page ) >= 4 :
10364
10418
if page_utils .is_valid_url (self .start_page ):
10419
+ good_start_page = True
10420
+ self .__new_window_on_rec_open = False
10365
10421
self .open (self .start_page )
10422
+ self .__new_window_on_rec_open = True
10366
10423
else :
10367
10424
new_start_page = "http://" + self .start_page
10368
10425
if page_utils .is_valid_url (new_start_page ):
10426
+ good_start_page = True
10369
10427
self .open (new_start_page )
10370
- elif self ._crumbs :
10428
+ if self .recorder_ext or ( self . _crumbs and not good_start_page ) :
10371
10429
if self .get_current_url () != "data:," :
10430
+ self .__new_window_on_rec_open = False
10372
10431
self .open ("data:," )
10373
- else :
10374
- pass
10432
+ self .__new_window_on_rec_open = True
10433
+ if self .recorder_ext :
10434
+ self .__js_start_time = int (time .time () * 1000.0 )
10375
10435
else :
10376
10436
# Launch WebDriver for both Pytest and Nosetests
10377
10437
self .driver = self .get_new_driver (
@@ -10431,11 +10491,6 @@ def setUp(self, masterqa_mode=False):
10431
10491
# Call this once in case of multiple setUp() calls in the same test
10432
10492
self .__start_time_ms = sb_config .start_time_ms
10433
10493
10434
- # Set the JS start time for Recorder Mode if reusing the session.
10435
- # Use this to skip saving recorded actions from previous tests.
10436
- if self .recorder_mode and self ._reuse_session :
10437
- self .__js_start_time = self .execute_script ("return Date.now();" )
10438
-
10439
10494
def __set_last_page_screenshot (self ):
10440
10495
"""self.__last_page_screenshot is only for pytest html report logs.
10441
10496
self.__last_page_screenshot_png is for all screenshot log files."""
0 commit comments