Skip to content

Instantly share code, notes, and snippets.

@gunesmes
Last active July 11, 2023 07:43
Show Gist options
  • Save gunesmes/c680eca01abf359dd42b to your computer and use it in GitHub Desktop.
Save gunesmes/c680eca01abf359dd42b to your computer and use it in GitHub Desktop.
Capybara and Cucumber: Handling iframe, Pop-ups and Facebook Login
Feature: Facebook Login
As An anonymous user
I Want to login the webpage
So That I can buy anything
Background: Member should open home page
Given I go to home page
@javascript
Scenario: Member should be able to login with Facebook
When member login with Facebook
Then member should see popup window closes
And member see member informations
When(/^member login with Facebook$/) do
# set the main window
main = page.driver.browser.window_handles.first
# to enable to click Facebook login button we must switch to Facebook iframe
facebok_iframe_name = find(:xpath, "//*[@id='fb-button-explore']/span/iframe")[:name]
page.driver.browser.switch_to.frame facebok_iframe_name
# now we can click the Facebook login button which open the pop-up
find(:id, "u_0_1").click()
# to enable to fill the Facebook creditional set popup windows
# and then switch to popup window
popup = page.driver.browser.window_handles.last
page.driver.browser.switch_to.window(popup)
# fill form and click login button
fill_in("email", :with => "mesut@testrisk.com")
fill_in("pass", :with => "Password123")
find(:id, "u_0_1").click()
# don't forget to switch to main window
page.driver.browser.switch_to.window(main)
end
@matiasmasca
Copy link

Thank you, you saved my day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment