Skip to content

Fix #98: use the decorator @step #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions behave_webdriver/steps/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,94 +13,94 @@
use_step_matcher('transform-parse')


@when('I pause for {milliseconds:d}ms')
@step('I pause for {milliseconds:d}ms')
def sleep_ms(context, milliseconds):
context.behave_driver.pause(milliseconds)


@when('I click on the element "{element}"')
@step('I click on the element "{element}"')
def click_element(context, element):
context.behave_driver.click_element(element)


@when('I doubleclick on the element "{element}"')
@step('I doubleclick on the element "{element}"')
def doubleclick_element(context, element):
context.behave_driver.doubleclick_element(element)


@when('I click on the link "{link_text}"')
@step('I click on the link "{link_text}"')
def click_link(context, link_text):
context.behave_driver.click_link_text(link_text)


@when('I click on the button "{element}"')
@step('I click on the button "{element}"')
def click_button(context, element):
context.behave_driver.click_element(element)


@when('I set "{value}" to the inputfield "{element}"')
@step('I set "{value}" to the inputfield "{element}"')
def set_input(context, value, element):
elem = context.behave_driver.get_element(element)
elem.clear()
elem.send_keys(value)


@when('I add "{value}" to the inputfield "{element}"')
@step('I add "{value}" to the inputfield "{element}"')
def add_input(context, value, element):
elem = context.behave_driver.get_element(element)
elem.send_keys(value)


@when('I clear the inputfield "{element}"')
@step('I clear the inputfield "{element}"')
def clear_input(context, element):
elem = context.behave_driver.get_element(element)
elem.clear()


@when('I drag element "{from_element}" to element "{to_element}"')
@step('I drag element "{from_element}" to element "{to_element}"')
def drag_element(context, from_element, to_element):
context.behave_driver.drag_element(from_element, to_element)


@when('I submit the form "{element}"')
@step('I submit the form "{element}"')
def submit_form(context, element):
context.behave_driver.submit(element)


@when('I set a cookie "{cookie_key}" with the content "{value}"')
@step('I set a cookie "{cookie_key}" with the content "{value}"')
def set_cookie(context, cookie_key, value):
context.behave_driver.add_cookie({'name': cookie_key, 'value': value})


@when('I delete the cookie "{cookie_key}"')
@step('I delete the cookie "{cookie_key}"')
def delete_cookie(context, cookie_key):
context.behave_driver.delete_cookie(cookie_key)


@when('I press "{key}"')
@step('I press "{key}"')
def press_button(context, key):
context.behave_driver.press_button(key)


@when('I scroll to element "{element}"')
@step('I scroll to element "{element}"')
def scroll_to(context, element):
context.behave_driver.scroll_to_element(element)


@when('I select the {nth} option for element "{element}"')
@step('I select the {nth} option for element "{element}"')
def select_nth_option(context, nth, element):
index = int(''.join(char for char in nth if char in string.digits))
context.behave_driver.select_option(element,
by='index',
by_arg=index)


@when('I move to element "{element}" with an offset of {x_offset:d},{y_offset:d}')
@step('I move to element "{element}" with an offset of {x_offset:d},{y_offset:d}')
def move_to_element_offset(context, element, x_offset, y_offset):
context.behave_driver.move_to_element(element, (x_offset, y_offset))


@when('I move to element "{element}"')
@step('I move to element "{element}"')
def move_to_element(context, element):
context.behave_driver.move_to_element(element)

Expand Down
22 changes: 11 additions & 11 deletions behave_webdriver/steps/actions_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
use_step_matcher('transform-re')


@when('I close the last opened (tab|window)')
@step('I close the last opened (tab|window)')
def close_last_tab(context, _):
context.behave_driver.switch_to_window(context.behave_driver.last_opened_handle)
context.behave_driver.close()
context.behave_driver.switch_to_window(context.behave_driver.primary_handle)


@when('I focus the last opened (tab|window)')
@step('I focus the last opened (tab|window)')
def focus_last_tab(context, _):
context.behave_driver.switch_to_window(context.behave_driver.last_opened_handle)


@when('I select the option with the (text|value|name) "([^"]*)?" for element "([^"]*)?"')
@step('I select the option with the (text|value|name) "([^"]*)?" for element "([^"]*)?"')
def select_option_by(context, attr, attr_value, element):
attr_map = {'text': 'visible_text'}
attr = attr_map.get(attr, attr)
Expand All @@ -33,22 +33,22 @@ def select_option_by(context, attr, attr_value, element):
by_arg=attr_value)


@when('I accept the (alertbox|confirmbox|prompt)')
@step('I accept the (alertbox|confirmbox|prompt)')
def accept_alert(context, modal_type):
context.behave_driver.alert.accept()


@when('I dismiss the (alertbox|confirmbox|prompt)')
@step('I dismiss the (alertbox|confirmbox|prompt)')
def dismiss_alert(context, modal_type):
context.behave_driver.alert.dismiss()


@when('I enter "([^"]*)?" into the (alertbox|confirmbox|prompt)')
@step('I enter "([^"]*)?" into the (alertbox|confirmbox|prompt)')
def handle_prompt(context, text, modal_type):
context.behave_driver.alert.send_keys(text)


@given('I have closed all but the first (window|tab)')
@step('I have closed all but the first (window|tab)')
def close_secondary_windows(context, window_or_tab):
if len(context.behave_driver.window_handles) > 1:
for handle in context.behave_driver.window_handles[1:]:
Expand All @@ -69,25 +69,25 @@ def open_site(context, url):
context.behave_driver.open_url(destination)


@given('the base url is "([^"]*)?"')
@step('the base url is "([^"]*)?"')
def set_base_url(context, url):
if url.endswith('/'):
url = url[:-1]
context.base_url = url


@given('I pause for (\d+)*ms')
@step('I pause for (\d+)*ms')
def pause(context, milliseconds):
milliseconds = int(milliseconds)
context.behave_driver.pause(milliseconds)


@given('I have a screen that is ([\d]+) by ([\d]+) pixels')
@step('I have a screen that is ([\d]+) by ([\d]+) pixels')
def set_screen_size(context, x, y):
context.behave_driver.screen_size = (x, y)


@given('I have a screen that is ([\d]+) pixels (broad|tall)')
@step('I have a screen that is ([\d]+) pixels (broad|tall)')
def set_screen_dimension(context, size, how):
size = int(size)
if how == 'tall':
Expand Down
Loading