@@ -95,6 +95,8 @@ def __init__(self, *args, **kwargs):
95
95
self .__last_page_url = None
96
96
self .__last_page_source = None
97
97
self .__skip_reason = None
98
+ self .__origins_to_save = []
99
+ self .__actions_to_save = []
98
100
self .__dont_record_open = False
99
101
self .__dont_record_js_click = False
100
102
self .__new_window_on_rec_open = True
@@ -2987,6 +2989,15 @@ def save_screenshot_to_logs(
2987
2989
return page_actions .save_screenshot (
2988
2990
self .driver , name , test_logpath , selector , by
2989
2991
)
2992
+ if self .recorder_mode :
2993
+ url = self .get_current_url ()
2994
+ if url and len (url ) > 0 :
2995
+ if ("http:" ) in url or ("https:" ) in url or ("file:" ) in url :
2996
+ if self .get_session_storage_item ("pause_recorder" ) == "no" :
2997
+ time_stamp = self .execute_script ("return Date.now();" )
2998
+ origin = self .get_origin ()
2999
+ action = ["ss_tl" , "" , origin , time_stamp ]
3000
+ self .__extra_actions .append (action )
2990
3001
return page_actions .save_screenshot (self .driver , name , test_logpath )
2991
3002
2992
3003
def save_page_source (self , name , folder = None ):
@@ -3183,6 +3194,22 @@ def activate_recorder(self):
3183
3194
except Exception :
3184
3195
pass
3185
3196
3197
+ def save_recorded_actions (self ):
3198
+ """(When using Recorder Mode, use this method if you plan on
3199
+ navigating to a different domain/origin in the same tab.)
3200
+ This method saves recorded actions from the active tab so that
3201
+ a complete recording can be exported as a SeleniumBase file at the
3202
+ end of the test. This is only needed in special cases because most
3203
+ actions that result in a new origin, (such as clicking on a link),
3204
+ should automatically open a new tab while Recorder Mode is enabled."""
3205
+ url = self .get_current_url ()
3206
+ if url and len (url ) > 0 :
3207
+ if ("http:" ) in url or ("https:" ) in url or ("file:" ) in url :
3208
+ origin = self .get_origin ()
3209
+ self .__origins_to_save .append (origin )
3210
+ tab_actions = self .__get_recorded_actions_on_active_tab ()
3211
+ self .__actions_to_save .append (tab_actions )
3212
+
3186
3213
def __get_recorded_actions_on_active_tab (self ):
3187
3214
url = self .driver .current_url
3188
3215
if (
@@ -3213,6 +3240,11 @@ def __process_recorded_actions(self):
3213
3240
if action not in used_actions :
3214
3241
used_actions .append (action )
3215
3242
raw_actions .append (action )
3243
+ for tab_actions in self .__actions_to_save :
3244
+ for action in tab_actions :
3245
+ if action not in used_actions :
3246
+ used_actions .append (action )
3247
+ raw_actions .append (action )
3216
3248
for action in self .__extra_actions :
3217
3249
if action not in used_actions :
3218
3250
used_actions .append (action )
@@ -3234,6 +3266,15 @@ def __process_recorded_actions(self):
3234
3266
and srt_actions [n - 1 ][0 ] == "sk_op"
3235
3267
):
3236
3268
srt_actions [n ][0 ] = "_skip"
3269
+ for n in range (len (srt_actions )):
3270
+ if (
3271
+ (srt_actions [n ][0 ] == "begin" or srt_actions [n ][0 ] == "_url_" )
3272
+ and n > 1
3273
+ and srt_actions [n - 1 ][0 ] == "_skip"
3274
+ and srt_actions [n - 2 ][0 ] == "sk_op"
3275
+ and srt_actions [n ][2 ] == srt_actions [n - 1 ][2 ]
3276
+ ):
3277
+ srt_actions [n ][0 ] = "_skip"
3237
3278
for n in range (len (srt_actions )):
3238
3279
if (
3239
3280
(srt_actions [n ][0 ] == "begin" or srt_actions [n ][0 ] == "_url_" )
@@ -3325,6 +3366,23 @@ def __process_recorded_actions(self):
3325
3366
):
3326
3367
srt_actions [n - 1 ][0 ] = "_skip"
3327
3368
srt_actions [n ][2 ] = srt_actions [n - 1 ][1 ][1 ]
3369
+ for n in range (len (srt_actions )):
3370
+ if (
3371
+ srt_actions [n ][0 ] == "input"
3372
+ and n > 0
3373
+ and srt_actions [n - 1 ][0 ] == "e_mfa"
3374
+ ):
3375
+ srt_actions [n ][0 ] = "_skip"
3376
+ for n in range (len (srt_actions )):
3377
+ if (
3378
+ (srt_actions [n ][0 ] == "begin" or srt_actions [n ][0 ] == "_url_" )
3379
+ and n > 0
3380
+ and (
3381
+ srt_actions [n - 1 ][0 ] == "submi"
3382
+ or srt_actions [n - 1 ][0 ] == "e_mfa"
3383
+ )
3384
+ ):
3385
+ srt_actions [n ][0 ] = "f_url"
3328
3386
origins = []
3329
3387
for n in range (len (srt_actions )):
3330
3388
if (
@@ -3337,6 +3395,8 @@ def __process_recorded_actions(self):
3337
3395
origin = origin [0 :- 1 ]
3338
3396
if origin not in origins :
3339
3397
origins .append (origin )
3398
+ for origin in self .__origins_to_save :
3399
+ origins .append (origin )
3340
3400
for n in range (len (srt_actions )):
3341
3401
if (
3342
3402
srt_actions [n ][0 ] == "click"
@@ -3382,6 +3442,8 @@ def __process_recorded_actions(self):
3382
3442
ext_actions .append ("s_c_d" )
3383
3443
ext_actions .append ("sh_fc" )
3384
3444
ext_actions .append ("c_l_s" )
3445
+ ext_actions .append ("e_mfa" )
3446
+ ext_actions .append ("ss_tl" )
3385
3447
for n in range (len (srt_actions )):
3386
3448
if srt_actions [n ][0 ] in ext_actions :
3387
3449
origin = srt_actions [n ][2 ]
@@ -3395,6 +3457,9 @@ def __process_recorded_actions(self):
3395
3457
if srt_actions [n ][0 ] == "js_ty" :
3396
3458
srt_actions [n ][2 ] = srt_actions [n ][1 ][1 ]
3397
3459
srt_actions [n ][1 ] = srt_actions [n ][1 ][0 ]
3460
+ if srt_actions [n ][0 ] == "e_mfa" :
3461
+ srt_actions [n ][2 ] = srt_actions [n ][1 ][1 ]
3462
+ srt_actions [n ][1 ] = srt_actions [n ][1 ][0 ]
3398
3463
if srt_actions [n ][0 ] == "_url_" and origin not in origins :
3399
3464
origins .append (origin )
3400
3465
if origin not in origins :
@@ -3449,6 +3514,21 @@ def __process_recorded_actions(self):
3449
3514
elif '"' in action [1 ] and '"' in text :
3450
3515
sb_actions .append ("self.%s('%s', '%s')" % (
3451
3516
method , action [1 ], text ))
3517
+ elif action [0 ] == "e_mfa" :
3518
+ method = "enter_mfa_code"
3519
+ text = action [2 ].replace ("\n " , "\\ n" )
3520
+ if '"' not in action [1 ] and '"' not in text :
3521
+ sb_actions .append ('self.%s("%s", "%s")' % (
3522
+ method , action [1 ], text ))
3523
+ elif '"' not in action [1 ] and '"' in text :
3524
+ sb_actions .append ('self.%s("%s", \' %s\' )' % (
3525
+ method , action [1 ], text ))
3526
+ elif '"' in action [1 ] and '"' not in text :
3527
+ sb_actions .append ('self.%s(\' %s\' , "%s")' % (
3528
+ method , action [1 ], text ))
3529
+ elif '"' in action [1 ] and '"' in text :
3530
+ sb_actions .append ("self.%s('%s', '%s')" % (
3531
+ method , action [1 ], text ))
3452
3532
elif action [0 ] == "h_clk" :
3453
3533
method = "hover_and_click"
3454
3534
if '"' not in action [1 ] and '"' not in action [2 ]:
@@ -3631,19 +3711,22 @@ def __process_recorded_actions(self):
3631
3711
else :
3632
3712
sb_actions .append ("self.%s('%s')" % (
3633
3713
method , action [1 ][0 ]))
3714
+ elif action [0 ] == "ss_tl" :
3715
+ method = "save_screenshot_to_logs"
3716
+ sb_actions .append ('self.%s()' % method )
3634
3717
elif action [0 ] == "sh_fc" :
3635
- cb_method = "show_file_choosers"
3636
- sb_actions .append ('self.%s()' % cb_method )
3718
+ method = "show_file_choosers"
3719
+ sb_actions .append ('self.%s()' % method )
3637
3720
elif action [0 ] == "c_l_s" :
3638
3721
sb_actions .append ("self.clear_local_storage()" )
3639
3722
elif action [0 ] == "c_box" :
3640
- cb_method = "check_if_unchecked"
3723
+ method = "check_if_unchecked"
3641
3724
if action [2 ] == "no" :
3642
- cb_method = "uncheck_if_checked"
3725
+ method = "uncheck_if_checked"
3643
3726
if '"' not in action [1 ]:
3644
- sb_actions .append ('self.%s("%s")' % (cb_method , action [1 ]))
3727
+ sb_actions .append ('self.%s("%s")' % (method , action [1 ]))
3645
3728
else :
3646
- sb_actions .append ("self.%s('%s')" % (cb_method , action [1 ]))
3729
+ sb_actions .append ("self.%s('%s')" % (method , action [1 ]))
3647
3730
3648
3731
filename = self .__get_filename ()
3649
3732
new_file = False
0 commit comments