Skip to content

Commit 41b344a

Browse files
committed
Add more Gherkin step definitions for "behave" BDD mode
1 parent b6e6c7d commit 41b344a

File tree

1 file changed

+165
-65
lines changed

1 file changed

+165
-65
lines changed

sbase/steps.py

Lines changed: 165 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ def assert_element(context, selector):
134134
@step('Assert text "{text}" in \'{selector}\'')
135135
@step("Text in '{selector}' should contain '{text}'")
136136
@step('Text in "{selector}" should contain "{text}"')
137-
@step('Text in "{selector}" should contain \'{text}\'')
138137
@step("Text in '{selector}' should contain \"{text}\"")
138+
@step('Text in "{selector}" should contain \'{text}\'')
139139
def assert_text_in_element(context, text, selector):
140140
sb = context.sb
141141
text = normalize_text(text)
@@ -160,8 +160,8 @@ def assert_text(context, text):
160160
@step('Assert exact text "{text}" in \'{selector}\'')
161161
@step("Text in '{selector}' should be '{text}'")
162162
@step('Text in "{selector}" should be "{text}"')
163-
@step('Text in "{selector}" should be \'{text}\'')
164163
@step("Text in '{selector}' should be \"{text}\"")
164+
@step('Text in "{selector}" should be \'{text}\'')
165165
def assert_exact_text(context, text, selector):
166166
sb = context.sb
167167
text = normalize_text(text)
@@ -172,8 +172,8 @@ def assert_exact_text(context, text, selector):
172172
@step('Highlight "{selector}"')
173173
@step("Highlight element '{selector}'")
174174
@step('Highlight element "{selector}"')
175-
@step("User uses JS to highlight '{selector}'")
176-
@step('User uses JS to highlight "{selector}"')
175+
@step("Use JS to highlight '{selector}'")
176+
@step('Use JS to highlight "{selector}"')
177177
def highlight_element(context, selector):
178178
sb = context.sb
179179
sb.highlight(selector)
@@ -192,13 +192,37 @@ def click_link(context, link):
192192
@step('JS click "{selector}"')
193193
@step("JS click element '{selector}'")
194194
@step('JS click element "{selector}"')
195-
@step("User uses JS to click '{selector}'")
196-
@step('User uses JS to click "{selector}"')
195+
@step("Use JS to click '{selector}'")
196+
@step('Use JS to click "{selector}"')
197197
def js_click(context, selector):
198198
sb = context.sb
199199
sb.js_click(selector)
200200

201201

202+
@step("Save screenshot as '{name}'")
203+
@step('Save screenshot as "{name}"')
204+
@step("User saves screenshot as '{name}'")
205+
@step('User saves screenshot as "{name}"')
206+
def save_screenshot_as(context, name):
207+
sb = context.sb
208+
name = normalize_text(name)
209+
sb.save_screenshot(name)
210+
211+
212+
@step("Save screenshot to '{folder}' as '{name}'")
213+
@step('Save screenshot to "{folder}" as "{name}"')
214+
@step("Save screenshot to '{folder}' as \"{name}\"")
215+
@step('Save screenshot to "{folder}" as \'{name}\'')
216+
@step("User saves screenshot to '{folder}' as '{name}'")
217+
@step('User saves screenshot to "{folder}" as "{name}"')
218+
@step("User saves screenshot to '{folder}' as \"{name}\"")
219+
@step('User saves screenshot to "{folder}" as \'{name}\'')
220+
def save_screenshot_to_folder_as(context, name, folder):
221+
sb = context.sb
222+
name = normalize_text(name)
223+
sb.save_screenshot(name, folder)
224+
225+
202226
@step("Save screenshot to logs")
203227
@step("Save a screenshot to the logs")
204228
@step("User saves screenshot to logs")
@@ -233,36 +257,6 @@ def go_forward(context):
233257
sb.go_forward()
234258

235259

236-
@step("JS type '{text}' in '{selector}'")
237-
@step('JS type "{text}" in "{selector}"')
238-
@step("JS type '{text}' in \"{selector}\"")
239-
@step('JS type "{text}" in \'{selector}\'')
240-
@step("JS type '{text}' into '{selector}'")
241-
@step('JS type "{text}" into "{selector}"')
242-
@step("JS type '{text}' into \"{selector}\"")
243-
@step('JS type "{text}" into \'{selector}\'')
244-
@step("JS type text '{text}' in '{selector}'")
245-
@step('JS type text "{text}" in "{selector}"')
246-
@step("JS type text '{text}' in \"{selector}\"")
247-
@step('JS type text "{text}" in \'{selector}\'')
248-
@step("JS type text '{text}' into '{selector}'")
249-
@step('JS type text "{text}" into "{selector}"')
250-
@step("JS type text '{text}' into \"{selector}\"")
251-
@step('JS type text "{text}" into \'{selector}\'')
252-
@step("User uses JS to type '{text}' in '{selector}'")
253-
@step('User uses JS to type "{text}" in "{selector}"')
254-
@step("User uses JS to type '{text}' in \"{selector}\"")
255-
@step('User uses JS to type "{text}" in \'{selector}\'')
256-
@step("User uses JS to type '{text}' into '{selector}'")
257-
@step('User uses JS to type "{text}" into "{selector}"')
258-
@step("User uses JS to type '{text}' into \"{selector}\"")
259-
@step('User uses JS to type "{text}" into \'{selector}\'')
260-
def js_type(context, text, selector):
261-
sb = context.sb
262-
text = normalize_text(text)
263-
sb.js_type(selector, text)
264-
265-
266260
@step("Set value of '{selector}' to '{text}'")
267261
@step('Set value of "{selector}" to "{text}"')
268262
@step("Set value of \"{selector}\" to '{text}'")
@@ -271,7 +265,7 @@ def js_type(context, text, selector):
271265
@step('User sets value of "{selector}" to "{text}"')
272266
@step("User sets value of \"{selector}\" to '{text}'")
273267
@step('User sets value of \'{selector}\' to "{text}"')
274-
def set_value(context, text, selector):
268+
def set_value(context, selector, text):
275269
sb = context.sb
276270
text = normalize_text(text)
277271
sb.set_value(selector, text)
@@ -627,8 +621,8 @@ def clear_session_storage(context):
627621

628622
@step("JS click all '{selector}'")
629623
@step('JS click all "{selector}"')
630-
@step("User uses JS to click all '{selector}'")
631-
@step('User uses JS to click all "{selector}"')
624+
@step("Use JS to click all '{selector}'")
625+
@step('Use JS to click all "{selector}"')
632626
def js_click_all(context, selector):
633627
sb = context.sb
634628
sb.js_click_all(selector)
@@ -781,8 +775,8 @@ def assert_attribute_has_value(context, selector, attribute, value):
781775

782776
@step("Show file choosers")
783777
@step("Show hidden file choosers")
784-
@step("User uses JS to show file choosers")
785-
@step("User uses JS to show hidden file choosers")
778+
@step("Use JS to show file choosers")
779+
@step("Use JS to show hidden file choosers")
786780
def show_file_choosers(context):
787781
sb = context.sb
788782
sb.show_file_choosers()
@@ -924,10 +918,42 @@ def open_new_window(context):
924918
sb.open_new_window()
925919

926920

921+
@step("Accept alert")
922+
@step("User accepts alert")
923+
def accept_alert(context):
924+
sb = context.sb
925+
sb.accept_alert()
926+
927+
928+
@step("Dismiss alert")
929+
@step("User dismisses alert")
930+
def dismiss_alert(context):
931+
sb = context.sb
932+
sb.dismiss_alert()
933+
934+
935+
@step("Assert URL '{url}'")
936+
@step('Assert URL "{url}"')
937+
@step("The URL should be '{url}'")
938+
@step('The URL should be "{url}"')
939+
def assert_url(context, url):
940+
sb = context.sb
941+
url = normalize_text(url)
942+
sb.assert_url(url)
943+
944+
945+
@step("Assert URL contains '{substring}'")
946+
@step('Assert URL contains "{substring}"')
947+
@step("The URL should contain '{substring}'")
948+
@step('The URL should contain "{substring}"')
949+
def assert_url_contains(context, substring):
950+
sb = context.sb
951+
substring = normalize_text(substring)
952+
sb.assert_url_contains(substring)
953+
954+
927955
@step("Hover '{selector}'")
928956
@step('Hover "{selector}"')
929-
@step("Hover on '{selector}'")
930-
@step('Hover on "{selector}"')
931957
@step("Hover over '{selector}'")
932958
@step('Hover over "{selector}"')
933959
@step("Hover element '{selector}'")
@@ -958,35 +984,109 @@ def context_click(context, selector):
958984
sb.context_click(selector)
959985

960986

961-
@step("Accept alert")
962-
@step("User accepts alert")
963-
def accept_alert(context):
987+
@step("JS type '{text}' in '{selector}'")
988+
@step('JS type "{text}" in "{selector}"')
989+
@step("JS type '{text}' in \"{selector}\"")
990+
@step('JS type "{text}" in \'{selector}\'')
991+
@step("JS type '{text}' into '{selector}'")
992+
@step('JS type "{text}" into "{selector}"')
993+
@step("JS type '{text}' into \"{selector}\"")
994+
@step('JS type "{text}" into \'{selector}\'')
995+
@step("JS type text '{text}' in '{selector}'")
996+
@step('JS type text "{text}" in "{selector}"')
997+
@step("JS type text '{text}' in \"{selector}\"")
998+
@step('JS type text "{text}" in \'{selector}\'')
999+
@step("JS type text '{text}' into '{selector}'")
1000+
@step('JS type text "{text}" into "{selector}"')
1001+
@step("JS type text '{text}' into \"{selector}\"")
1002+
@step('JS type text "{text}" into \'{selector}\'')
1003+
@step("Use JS to type '{text}' in '{selector}'")
1004+
@step('Use JS to type "{text}" in "{selector}"')
1005+
@step("Use JS to type '{text}' in \"{selector}\"")
1006+
@step('Use JS to type "{text}" in \'{selector}\'')
1007+
@step("Use JS to type '{text}' into '{selector}'")
1008+
@step('Use JS to type "{text}" into "{selector}"')
1009+
@step("Use JS to type '{text}' into \"{selector}\"")
1010+
@step('Use JS to type "{text}" into \'{selector}\'')
1011+
def js_type(context, text, selector):
9641012
sb = context.sb
965-
sb.accept_alert()
1013+
text = normalize_text(text)
1014+
sb.js_type(selector, text)
9661015

9671016

968-
@step("Dismiss alert")
969-
@step("User dismisses alert")
970-
def dismiss_alert(context):
1017+
@step("jQuery click '{selector}'")
1018+
@step('jQuery click "{selector}"')
1019+
@step("jQuery click element '{selector}'")
1020+
@step('jQuery click element "{selector}"')
1021+
@step("Use jQuery to click '{selector}'")
1022+
@step('Use jQuery to click "{selector}"')
1023+
def jquery_click(context, selector):
1024+
sb = context.sb
1025+
sb.jquery_click(selector)
1026+
1027+
1028+
@step("jQuery click all '{selector}'")
1029+
@step('jQuery click all "{selector}"')
1030+
@step("Use jQuery to click all '{selector}'")
1031+
@step('Use jQuery to click all "{selector}"')
1032+
def jquery_click_all(context, selector):
1033+
sb = context.sb
1034+
sb.jquery_click_all(selector)
1035+
1036+
1037+
@step("jQuery type '{text}' in '{selector}'")
1038+
@step('jQuery type "{text}" in "{selector}"')
1039+
@step("jQuery type '{text}' in \"{selector}\"")
1040+
@step('jQuery type "{text}" in \'{selector}\'')
1041+
@step("jQuery type '{text}' into '{selector}'")
1042+
@step('jQuery type "{text}" into "{selector}"')
1043+
@step("jQuery type '{text}' into \"{selector}\"")
1044+
@step('jQuery type "{text}" into \'{selector}\'')
1045+
@step("jQuery type text '{text}' in '{selector}'")
1046+
@step('jQuery type text "{text}" in "{selector}"')
1047+
@step("jQuery type text '{text}' in \"{selector}\"")
1048+
@step('jQuery type text "{text}" in \'{selector}\'')
1049+
@step("jQuery type text '{text}' into '{selector}'")
1050+
@step('jQuery type text "{text}" into "{selector}"')
1051+
@step("jQuery type text '{text}' into \"{selector}\"")
1052+
@step('jQuery type text "{text}" into \'{selector}\'')
1053+
@step("Use jQuery to type '{text}' in '{selector}'")
1054+
@step('Use jQuery to type "{text}" in "{selector}"')
1055+
@step("Use jQuery to type '{text}' in \"{selector}\"")
1056+
@step('Use jQuery to type "{text}" in \'{selector}\'')
1057+
@step("Use jQuery to type '{text}' into '{selector}'")
1058+
@step('Use jQuery to type "{text}" into "{selector}"')
1059+
@step("Use jQuery to type '{text}' into \"{selector}\"")
1060+
@step('Use jQuery to type "{text}" into \'{selector}\'')
1061+
def jquery_type(context, text, selector):
9711062
sb = context.sb
972-
sb.dismiss_alert()
1063+
text = normalize_text(text)
1064+
sb.jquery_type(selector, text)
9731065

9741066

975-
@step("Assert URL '{url}'")
976-
@step('Assert URL "{url}"')
977-
@step("The URL should be '{url}'")
978-
@step('The URL should be "{url}"')
979-
def assert_url(context, url):
1067+
@step("Find '{selector}' and set {attribute} to '{value}'")
1068+
@step('Find "{selector}" and set {attribute} to "{value}"')
1069+
@step("Find '{selector}' and set {attribute} to \"{value}\"")
1070+
@step('Find "{selector}" and set {attribute} to \'{value}\'')
1071+
def set_attribute(context, selector, attribute, value):
9801072
sb = context.sb
981-
url = normalize_text(url)
982-
sb.assert_url(url)
1073+
value = normalize_text(value)
1074+
if attribute.startswith("'") or attribute.startswith('"'):
1075+
attribute = attribute[1:]
1076+
if attribute.endswith("'") or attribute.endswith('"'):
1077+
attribute = attribute[:-1]
1078+
sb.set_attribute(selector, attribute, value)
9831079

9841080

985-
@step("Assert URL contains '{substring}'")
986-
@step('Assert URL contains "{substring}"')
987-
@step("The URL should contain '{substring}'")
988-
@step('The URL should contain "{substring}"')
989-
def assert_url_contains(context, substring):
1081+
@step("Find all '{selector}' and set {attribute} to '{value}'")
1082+
@step('Find all "{selector}" and set {attribute} to "{value}"')
1083+
@step("Find all '{selector}' and set {attribute} to \"{value}\"")
1084+
@step('Find all "{selector}" and set {attribute} to \'{value}\'')
1085+
def set_attributes(context, selector, attribute, value):
9901086
sb = context.sb
991-
substring = normalize_text(substring)
992-
sb.assert_url_contains(substring)
1087+
value = normalize_text(value)
1088+
if attribute.startswith("'") or attribute.startswith('"'):
1089+
attribute = attribute[1:]
1090+
if attribute.endswith("'") or attribute.endswith('"'):
1091+
attribute = attribute[:-1]
1092+
sb.set_attributes(selector, attribute, value)

0 commit comments

Comments
 (0)