Skip to content

Commit 8cf2648

Browse files
committed
Update Recorder Mode
1 parent 9a37df3 commit 8cf2648

File tree

3 files changed

+53
-38
lines changed

3 files changed

+53
-38
lines changed

seleniumbase/extensions/recorder.zip

-10 Bytes
Binary file not shown.

seleniumbase/fixtures/base_case.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3391,7 +3391,7 @@ def __process_recorded_actions(self):
33913391
url2 = url1[:-3]
33923392
elif url2.endswith("/"):
33933393
url2 = url2[:-1]
3394-
if url1 == url2:
3394+
if url1.replace("www.", "") == url2.replace("www.", ""):
33953395
srt_actions[n-1][0] = "_skip"
33963396
elif url2.startswith(url1):
33973397
srt_actions[n][0] = "f_url"
@@ -3546,8 +3546,22 @@ def __process_recorded_actions(self):
35463546
cleaned_actions.append(srt_actions[n])
35473547
for action in srt_actions:
35483548
if action[0] == "begin" or action[0] == "_url_":
3549+
if "%" in action[2] and sys.version_info[0] >= 3:
3550+
try:
3551+
from urllib.parse import unquote
3552+
3553+
action[2] = unquote(action[2], errors="strict")
3554+
except Exception:
3555+
pass
35493556
sb_actions.append('self.open("%s")' % action[2])
35503557
elif action[0] == "f_url":
3558+
if "%" in action[2] and sys.version_info[0] >= 3:
3559+
try:
3560+
from urllib.parse import unquote
3561+
3562+
action[2] = unquote(action[2], errors="strict")
3563+
except Exception:
3564+
pass
35513565
sb_actions.append('self.open_if_not_url("%s")' % action[2])
35523566
elif action[0] == "click":
35533567
method = "click"
@@ -3759,7 +3773,7 @@ def __process_recorded_actions(self):
37593773
method, action[1][0], action[1][1]))
37603774
elif action[0] == "as_te" or action[0] == "as_et":
37613775
import unicodedata
3762-
action[1][0] = unicodedata.normalize("NFKD", action[1][0])
3776+
action[1][0] = unicodedata.normalize("NFKC", action[1][0])
37633777
method = "assert_text"
37643778
if action[0] == "as_et":
37653779
method = "assert_exact_text"

seleniumbase/js_code/recorder_js.py

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
var selector = el.nodeName.toLowerCase();
1212
if (el.id) {
1313
elid = el.id;
14-
if (elid.includes('.') || elid.includes('(') || elid.includes(')'))
14+
if (elid.includes(',') || elid.includes('.') ||
15+
elid.includes('(') || elid.includes(')'))
1516
return cssPathByAttribute(el, 'id');
1617
selector += '#' + elid;
1718
path.unshift(selector);
@@ -107,10 +108,10 @@
107108
return n;
108109
};
109110
function hasNumber(str) {
110-
return /\d/.test(str);
111+
return /\d/.test(str);
111112
};
112113
function tagName(el) {
113-
return el.tagName.toLowerCase();
114+
return el.tagName.toLowerCase();
114115
};
115116
function turnIntoParentAsNeeded(el) {
116117
if (tagName(el) == 'span') {
@@ -402,6 +403,9 @@
402403
const el = event.target;
403404
const selector = getBestSelector(el);
404405
ra_len = document.recorded_actions.length;
406+
rec_mode = sessionStorage.getItem('recorder_mode');
407+
if (rec_mode === '2' || rec_mode === '3')
408+
return;
405409
if (ra_len > 0 &&
406410
document.recorded_actions[ra_len-1][0] === 'mo_dn' &&
407411
document.recorded_actions[ra_len-1][1] === selector)
@@ -505,48 +509,19 @@
505509
ra_len = document.recorded_actions.length;
506510
rec_mode = sessionStorage.getItem('recorder_mode');
507511
tag_name = tagName(el);
508-
text = '';
509512
if (rec_mode === '2' || rec_mode === '3')
513+
{
510514
el = turnIntoParentAsNeeded(el);
511515
texts = [el.innerText, el.textContent];
512-
if (ra_len > 0 && document.recorded_actions[ra_len-1][0] === 'mo_dn')
513-
document.recorded_actions.pop();
514-
if (tag_name === 'select') {
515-
// Do Nothing. ('change' action.)
516-
}
517-
else
518-
document.recorded_actions.push(['mo_dn', selector, texts, d_now]);
519-
json_rec_act = JSON.stringify(document.recorded_actions);
520-
sessionStorage.setItem('recorded_actions', json_rec_act);
521-
});
522-
document.body.addEventListener('mouseup', function (event) {
523-
reset_if_recorder_undefined();
524-
if (sessionStorage.getItem('pause_recorder') === 'yes') return;
525-
const d_now = Date.now();
526-
const el = event.target;
527-
selector = getBestSelector(el);
528-
ra_len = document.recorded_actions.length;
529-
tag_name = tagName(el);
530-
parent_el = el.parentElement;
531-
parent_tag_name = tagName(parent_el);
532-
grand_el = "";
533-
grand_tag_name = "";
534-
origin = "";
535-
rec_mode = sessionStorage.getItem('recorder_mode');
536-
if (ra_len > 0 && document.recorded_actions[ra_len-1][0] === 'mo_dn' &&
537-
(rec_mode === '2' || rec_mode === '3'))
538-
{
539-
pre_sel = document.recorded_actions[ra_len-1][1];
540-
sel_has_contains = pre_sel.includes(':contains(');
541-
texts = document.recorded_actions[ra_len-1][2];
542516
text = texts[0];
543517
t_con = texts[1];
544518
origin = window.location.origin;
519+
sel_has_contains = selector.includes(':contains(');
545520
if (!text) { text = ''; }
546521
if (rec_mode === '2' || (
547522
rec_mode === '3' && sel_has_contains && text === t_con))
548523
{
549-
document.recorded_actions.push(['as_el', pre_sel, origin, d_now]);
524+
document.recorded_actions.push(['as_el', selector, origin, d_now]);
550525
json_rec_act = JSON.stringify(document.recorded_actions);
551526
sessionStorage.setItem('recorded_actions', json_rec_act);
552527
return;
@@ -564,13 +539,39 @@
564539
}
565540
}
566541
}
567-
tex_sel = [text, pre_sel];
542+
tex_sel = [text, selector];
568543
document.recorded_actions.push([action, tex_sel, origin, d_now]);
569544
json_rec_act = JSON.stringify(document.recorded_actions);
570545
sessionStorage.setItem('recorded_actions', json_rec_act);
571546
return;
572547
}
573548
}
549+
if (ra_len > 0 && document.recorded_actions[ra_len-1][0] === 'mo_dn')
550+
document.recorded_actions.pop();
551+
if (tag_name === 'select') {
552+
// Do Nothing. ('change' action.)
553+
}
554+
else
555+
document.recorded_actions.push(['mo_dn', selector, '', d_now]);
556+
json_rec_act = JSON.stringify(document.recorded_actions);
557+
sessionStorage.setItem('recorded_actions', json_rec_act);
558+
});
559+
document.body.addEventListener('mouseup', function (event) {
560+
reset_if_recorder_undefined();
561+
if (sessionStorage.getItem('pause_recorder') === 'yes') return;
562+
const d_now = Date.now();
563+
const el = event.target;
564+
selector = getBestSelector(el);
565+
ra_len = document.recorded_actions.length;
566+
tag_name = tagName(el);
567+
parent_el = el.parentElement;
568+
parent_tag_name = tagName(parent_el);
569+
grand_el = "";
570+
grand_tag_name = "";
571+
origin = "";
572+
rec_mode = sessionStorage.getItem('recorder_mode');
573+
if (rec_mode === '2' || rec_mode === '3')
574+
return;
574575
if (parent_el.parentElement != null) {
575576
grand_el = parent_el.parentElement;
576577
grand_tag_name = tagName(grand_el);

0 commit comments

Comments
 (0)