Last active
May 9, 2016 13:51
-
-
Save kusakusakusa/68032378cee5d9fc1a8722030b1c3609 to your computer and use it in GitHub Desktop.
Rspec page objects module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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