Skip to content

Commit 19c9aef

Browse files
committed
Add methods for non-empty text assertions
1 parent e4f1d51 commit 19c9aef

File tree

5 files changed

+470
-3
lines changed

5 files changed

+470
-3
lines changed

sbase/steps.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,19 @@ def assert_exact_text(context, text, selector):
168168
sb.assert_exact_text(text, selector)
169169

170170

171+
@step("Assert non-empty text in '{selector}'")
172+
@step('Assert non-empty text in "{selector}"')
173+
@step("Assert text in '{selector}' is not empty")
174+
@step('Assert text in "{selector}" is not empty')
175+
@step("Text in '{selector}' should be non-empty")
176+
@step('Text in "{selector}" should be non-empty')
177+
@step("Text in '{selector}' should not be empty")
178+
@step('Text in "{selector}" should not be empty')
179+
def assert_non_empty_text(context, selector):
180+
sb = context.sb
181+
sb.assert_non_empty_text(selector)
182+
183+
171184
@step("Highlight '{selector}'")
172185
@step('Highlight "{selector}"')
173186
@step("Highlight element '{selector}'")
@@ -492,6 +505,49 @@ def wait_for_text_in_element(context, text, selector):
492505
sb.wait_for_text(text, selector)
493506

494507

508+
@step("Wait for exact text '{text}' in '{selector}'")
509+
@step('Wait for exact text "{text}" in "{selector}"')
510+
@step("Wait for exact text '{text}' in \"{selector}\"")
511+
@step('Wait for exact text "{text}" in \'{selector}\'')
512+
@step("Wait for '{selector}' to have exact text '{text}'")
513+
@step('Wait for "{selector}" to have exact text "{text}"')
514+
@step('Wait for "{selector}" to have exact text \'{text}\'')
515+
@step("Wait for '{selector}' to have exact text \"{text}\"")
516+
@step("User waits for exact text '{text}' in '{selector}'")
517+
@step('User waits for exact text "{text}" in "{selector}"')
518+
@step("User waits for exact text '{text}' in \"{selector}\"")
519+
@step('User waits for exact text "{text}" in \'{selector}\'')
520+
@step("User waits for '{selector}' to have exact text '{text}'")
521+
@step('User waits for "{selector}" to have exact text "{text}"')
522+
@step('User waits for "{selector}" to have exact text \'{text}\'')
523+
@step("User waits for '{selector}' to have exact text \"{text}\"")
524+
def wait_for_exact_text_in_element(context, text, selector):
525+
sb = context.sb
526+
text = normalize_text(text)
527+
sb.wait_for_exact_text(text, selector)
528+
529+
530+
@step("Wait for non-empty text in '{selector}'")
531+
@step('Wait for non-empty text in "{selector}"')
532+
@step("Wait for '{selector}' to have non-empty text")
533+
@step('Wait for "{selector}" to have non-empty text')
534+
@step("User waits for non-empty text in '{selector}'")
535+
@step('User waits for non-empty text in "{selector}"')
536+
@step("User waits for '{selector}' to have non-empty text")
537+
@step('User waits for "{selector}" to have non-empty text')
538+
@step("Wait for '{selector}' to not have text")
539+
@step('Wait for "{selector}" to not have text')
540+
@step("Wait for text in '{selector}' to not be empty")
541+
@step('Wait for text in "{selector}" to not be empty')
542+
@step("User waits for '{selector}' to not have text")
543+
@step('User waits for "{selector}" to not have text')
544+
@step("User waits for text in '{selector}' to not be empty")
545+
@step('User waits for text in "{selector}" to not be empty')
546+
def wait_for_non_empty_text_in_element(context, selector):
547+
sb = context.sb
548+
sb.wait_for_non_empty_text(selector)
549+
550+
495551
@step("Wait for text '{text}'")
496552
@step('Wait for text "{text}"')
497553
@step("User waits for text '{text}'")
@@ -839,12 +895,21 @@ def deferred_assert_text(context, text):
839895

840896
@step("Deferred assert exact text '{text}' in '{selector}'")
841897
@step('Deferred assert exact text "{text}" in "{selector}"')
898+
@step("Deferred assert exact text '{text}' in \"{selector}\"")
899+
@step('Deferred assert exact text "{text}" in \'{selector}\'')
842900
def deferred_assert_exact_text(context, text, selector):
843901
sb = context.sb
844902
text = normalize_text(text)
845903
sb.deferred_assert_exact_text(text, selector)
846904

847905

906+
@step("Deferred assert non-empty text in '{selector}'")
907+
@step('Deferred assert non-empty text in "{selector}"')
908+
def deferred_assert_non_empty_text(context, selector):
909+
sb = context.sb
910+
sb.deferred_assert_non_empty_text(selector)
911+
912+
848913
@step("Process deferred asserts")
849914
def process_deferred_asserts(context):
850915
sb = context.sb

seleniumbase/behave/behave_helper.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,18 +435,46 @@ def generate_gherkin(srt_actions):
435435
sb_actions.append('%s "%s"' % (method, action[1][0]))
436436
else:
437437
sb_actions.append("%s '%s'" % (method, action[1][0]))
438+
elif action[0] == "asnet":
439+
method = "Assert non-empty text in"
440+
if '"' not in action[1]:
441+
sb_actions.append('%s "%s"' % (method, action[1]))
442+
elif "'" not in action[1]:
443+
sb_actions.append("%s '%s'" % (method, action[1]))
444+
else:
445+
sb_actions.append(
446+
"%s '%s'" % (method, action[1].replace("'", "\\'"))
447+
)
438448
elif action[0] == "da_el":
439449
method = "Deferred assert element"
440450
if '"' not in action[1]:
441451
sb_actions.append('%s "%s"' % (method, action[1]))
442-
else:
452+
elif "'" not in action[1]:
443453
sb_actions.append("%s '%s'" % (method, action[1]))
454+
else:
455+
sb_actions.append(
456+
"%s '%s'" % (method, action[1].replace("'", "\\'"))
457+
)
444458
elif action[0] == "da_ep":
445459
method = "Deferred assert element present"
446460
if '"' not in action[1]:
447461
sb_actions.append('%s "%s"' % (method, action[1]))
462+
elif "'" not in action[1]:
463+
sb_actions.append("%s '%s'" % (method, action[1]))
448464
else:
465+
sb_actions.append(
466+
"%s '%s'" % (method, action[1].replace("'", "\\'"))
467+
)
468+
elif action[0] == "danet":
469+
method = "Deferred assert non-empty text in"
470+
if '"' not in action[1]:
471+
sb_actions.append('%s "%s"' % (method, action[1]))
472+
elif "'" not in action[1]:
449473
sb_actions.append("%s '%s'" % (method, action[1]))
474+
else:
475+
sb_actions.append(
476+
"%s '%s'" % (method, action[1].replace("'", "\\'"))
477+
)
450478
elif action[0] == "s_scr":
451479
method = "Save screenshot as"
452480
if '"' not in action[1]:

seleniumbase/core/recorder_helper.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,18 +463,46 @@ def generate_sbase_code(srt_actions):
463463
sb_actions.append(
464464
"self.%s('%s')" % (method, action[1][0])
465465
)
466+
elif action[0] == "asnet":
467+
method = "assert_non_empty_text"
468+
if '"' not in action[1]:
469+
sb_actions.append('self.%s("%s")' % (method, action[1]))
470+
elif "'" not in action[1]:
471+
sb_actions.append("self.%s('%s')" % (method, action[1]))
472+
else:
473+
sb_actions.append(
474+
'self.%s("""%s""")' % (method, action[1])
475+
)
466476
elif action[0] == "da_el":
467477
method = "deferred_assert_element"
468478
if '"' not in action[1]:
469479
sb_actions.append('self.%s("%s")' % (method, action[1]))
470-
else:
480+
elif "'" not in action[1]:
471481
sb_actions.append("self.%s('%s')" % (method, action[1]))
482+
else:
483+
sb_actions.append(
484+
'self.%s("""%s""")' % (method, action[1])
485+
)
472486
elif action[0] == "da_ep":
473487
method = "deferred_assert_element_present"
474488
if '"' not in action[1]:
475489
sb_actions.append('self.%s("%s")' % (method, action[1]))
490+
elif "'" not in action[1]:
491+
sb_actions.append("self.%s('%s')" % (method, action[1]))
476492
else:
493+
sb_actions.append(
494+
'self.%s("""%s""")' % (method, action[1])
495+
)
496+
elif action[0] == "danet":
497+
method = "deferred_assert_non_empty_text"
498+
if '"' not in action[1]:
499+
sb_actions.append('self.%s("%s")' % (method, action[1]))
500+
elif "'" not in action[1]:
477501
sb_actions.append("self.%s('%s')" % (method, action[1]))
502+
else:
503+
sb_actions.append(
504+
'self.%s("""%s""")' % (method, action[1])
505+
)
478506
elif action[0] == "s_scr":
479507
method = "save_screenshot"
480508
if '"' not in action[1]:

0 commit comments

Comments
 (0)