Skip to content

Instantly share code, notes, and snippets.

@Vic-L Vic-L/page_functions.rb
Last active May 9, 2016

Embed
What would you like to do?
Rspec page objects module
module PageFunctions
include Capybara::DSL
def in_browser(name)
old_session = Capybara.session_name
Capybara.session_name = name
yield
Capybara.session_name = old_session
end
def alert_text
page.driver.browser.switch_to.alert.text
end
def accept_confirm
page.driver.browser.switch_to.alert.accept
end
def reject_confirm
page.driver.browser.switch_to.alert.dismiss
end
def find_css selector
page.driver.find_css selector
end
def scroll_into_view selector
eval("execute_script(\"$('#{selector}')[0].scrollIntoView(false);\")")
sleep 1
end
def click_common selector, counter=0
if counter.zero?
eval("execute_script(\"$('#{selector}')[0].scrollIntoView(false);\")")
eval("execute_script(\"$('#{selector}')[0].click();\")")
sleep 1
else
eval("execute_script(\"$('#{selector}').slice(#{counter},#{counter+1})[0].scrollIntoView(false);\")")
eval("execute_script(\"$('#{selector}').slice(#{counter},#{counter+1})[0].click();\")")
sleep 1
end
end
def click_unique selector
find(selector).click
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.