Module: Capybara::DSL
- Defined in:
- lib/capybara-facebook-macros/macros.rb
Instance Method Summary collapse
- #accept_additional_permissions ⇒ Object
- #accept_permissions_outside_facebook ⇒ Object
- #complete_facebook_dialogues_on_click(element, test_user) ⇒ Object
- #deauth_app ⇒ Object
- #fill_in_facebook_form(test_user) ⇒ Object
- #login_and_authorise_app_outside_facebook(test_user) ⇒ Object
- #login_to_facebook_homepage(test_user, after_login_url) ⇒ Object
- #logout ⇒ Object
Instance Method Details
#accept_additional_permissions ⇒ Object
22 23 24 25 26 27 |
# File 'lib/capybara-facebook-macros/macros.rb', line 22 def return if page.driver.browser.window_handles.length == 1 within_window page.driver.browser.window_handles.last do end end |
#accept_permissions_outside_facebook ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/capybara-facebook-macros/macros.rb', line 29 def # these checks are required as the flow cna change depending on if the user has authed before # read permissions dialogue # click_on('OK') if page.driver.browser.window_handles.length == 2 if page.driver.browser.window_handles.length >= 2 read_perms = first(:xpath, "//button[@name='__CONFIRM__']") read_perms.click unless read_perms.nil? end if page.driver.browser.window_handles.length >= 2 write_perms = first(:xpath, "//button[@name='__CONFIRM__']") write_perms.click unless write_perms.nil? end # write permision dialogue # click_on('OK') if page.driver.browser.window_handles.length == 2 end |
#complete_facebook_dialogues_on_click(element, test_user) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/capybara-facebook-macros/macros.rb', line 4 def complete_facebook_dialogues_on_click(element, test_user) # until bookface version bumped to latest we have no way to know its ready so delay, not ideal sleep 2 find("#{element}").click return if page.driver.browser.window_handles.length == 1 within_window page.driver.browser.window_handles.last do fill_in_facebook_form(test_user) if page.has_css?('#loginbutton') end end |
#deauth_app ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/capybara-facebook-macros/macros.rb', line 52 def deauth_app sleep 1 page.execute_script %Q{ FB.api("/me/permissions","DELETE", function(response){ console.log(response) }); } sleep 1 end |
#fill_in_facebook_form(test_user) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/capybara-facebook-macros/macros.rb', line 72 def fill_in_facebook_form(test_user) if test_user.class == Hash test_user = OpenStruct.new test_user end fill_in('email', :with => "#{test_user.email}") fill_in('pass', :with => "#{test_user.password}") find('#loginbutton').click end |
#login_and_authorise_app_outside_facebook(test_user) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/capybara-facebook-macros/macros.rb', line 15 def (test_user) within_window('Facebook') do fill_in_facebook_form(test_user) if page.has_css?('#loginbutton') end end |
#login_to_facebook_homepage(test_user, after_login_url) ⇒ Object
47 48 49 50 |
# File 'lib/capybara-facebook-macros/macros.rb', line 47 def login_to_facebook_homepage(test_user, after_login_url) fill_in_facebook_form(test_user) visit after_login_url end |
#logout ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/capybara-facebook-macros/macros.rb', line 62 def logout sleep 1 page.execute_script %Q{ FB.logout(function(response) { // user is now logged out }); } sleep 1 end |