Skip to content

Instantly share code, notes, and snippets.

@mipearson
Last active July 26, 2018 04:06
Show Gist options
  • Save mipearson/5617600 to your computer and use it in GitHub Desktop.
Save mipearson/5617600 to your computer and use it in GitHub Desktop.
Persist a paypal developer sandbox login over multiple cucumber & capybara & selenium runs.
@javascript
Scenario: My Shopping Cart
Given I'm logged in to the PayPal Sandbox
And ...
PAYPAL_EXPECTED_NAME = 'Bob Bobson'
PAYPAL_EMAIL = 'bobtest@bobsworldofbobs.com.au'
PAYPAL_PASSWORD = 'supersecret'
Given(/^I'm logged in to the PayPal Sandbox$/) do
load_selenium_cookie_jar('developer.paypal.com')
visit 'https://developer.paypal.com'
if page.has_selector?('.topnav .enterCredentialsBlock')
step "I log in to PayPal"
end
find('.userinfo').should have_content(PAYPAL_EXPECTED_NAME) # dodgy test username
save_selenium_cookie_jar('developer.paypal.com')
end
Given(/^I log in to PayPal$/) do
within('.topnav') do
click_on 'Log In with PayPal'
end
# http://stackoverflow.com/questions/7612038/with-capybara-how-do-i-switch-to-the-new-window-for-links-with-blank-targets
new_window = page.driver.browser.window_handles.last
page.within_window new_window do
find('#email').set PAYPAL_EMAIL
find('#password').set PAYPAL_PASSWORD
find('#rememberMe').set true
click_on 'Log In'
end
# Reload the login page rather than waiting for PayPal to do that for us
visit 'https://developer.paypal.com'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment