calabash / calabash-ios

Calabash for iOS
Other
1.81k stars 369 forks source link

iOS 9 Safari-view-controller support - we need an example #861

Open Senemix29 opened 9 years ago

Senemix29 commented 9 years ago

I wanna know if there's a forecast about your support to safari-view-controller? I'm facing a little problem when i'm trying to test an app that uses the iOS 9 and the new Facebook SDK.

In the Facebook SDK for iOS 9 , when an app try to login, it only open's Safari webview, even if the user has Facebook app. The problem is that every time its necessary to authorise the app when login, even if safari saves the current account logged.

I wanna know how to interact with the safari view controller. Different from the iOS 8 Safari View Controller, on iOS 9 when i do a query("*") i got this elements instead of nothing:

Can you guys give me a clue how to workaround it. thx.

jmoody commented 9 years ago

@Senemix29

So now you are seeing nothing on the Safari View Controller?

We had a smoke test running for iOS 8. I have not tried to run it in iOS 9.

Senemix29 commented 9 years ago

@jmoody sorry about my english, i'll describe a little more to make you understand. I'm testing an app that have two ways to login. Using an email and password or using Facebook button.

Until the iOS update, i have this scenario: --> iOS 8 and Facebook sdk 4.3 in this scenario, when my app calle facebook to login, if the user already have the Facebook app, the sdk use it. Else, facebook calls Safari, user put their information, click on login and then comeback to my app.

After the iOS 9, i have this scenario: --> iOS9 and Facebook sdk 4.6 The iOS Devs from my team choose to update our app to support iOS 9, and do some changes, like update the Facebook sdk too. After that, even if the user have the Facebook app, when my app calls Facebook login, it calls Safari. The difference is that now, Facebook calls the new webview to iOS, the Safari View Controller that is open a modal inside the app. Now, when the the app calls the Safari View Controller, when i do a query inside that screen, it show this elements:

Facebook SDK to iOS will use the Safari View Controller as default at 4.6 version or higher. Now, i think i can't automate the login using Facebook. I wanna know if you guys will support Safari View Controller in Calabash, like you already support UIWebView and WKWebView. I have read somethings, and Safari View Controller maybe its the new big thing in webviews to iOS.

thx;

jmoody commented 9 years ago

Never apologize for your English. :)

Thank you for the clarification.

I think Calabash will be able to interact with the views, but you'll probably need to use raw UIA JavaScript or one of the Calabash uia_* calls.

The RemoteViewBridge tells me that the views in this controller are being presented outside of your app.

Here are some suggestions:

  1. use query("all *") to see if you can find the views.
  2. To touch the buttons try: uia_tap_mark
  3. Try uia_query_windows

There is an example in the briar gem of how to interact with the views in the MFMessageComposeViewController (AKA send email).

https://github.com/jmoody/briar/blob/develop/lib/briar/email.rb

alan-honeycutt commented 8 years ago

Did this ever get resolved? I am also trying to write tests that at least close the SFSafariViewController by tapping the "Done" button, but I've had no success finding where that button would live within the various Remote views.

jmoody commented 8 years ago

Not resolved yet.

This might work:

uia_tap_mark("Done")
milancermak commented 8 years ago

FWIW, I faced a similar problem, where I had to write steps to automate log in with Facebook. This is my rather hacky solution:

And(/^I use "(.+?)" and "(.+?)" as Facebook credentials$/) do |email, password|
  # the Facabook login process is done in a modal SFSafariViewController

  # a uia_tap gets the email input field selected
  uia_tap
  uia_wait_for_keyboard

  # if Safari has a Facebook session, we don't get the login
  # input form (with email & password fields), but go directly
  # to the app auth dialog; in that case, the keyboard will not
  # be visible after the previous uia_tap, even though
  # uia_wait_for_keyboard does finish
  if keyboard_visible?
    # in here we cannot use keyboard_enter_text, even though
    # the keyboard is visible; instead, use the uia* methods
    uia_set_responder_value(email)

    # probably won't work for other than English, but I couldn't
    # find a generic way how to select the next field
    uia_tap_mark("Facebook Password")
    uia_set_responder_value(password)

    # simulates hitting Enter, i.e. confirming the dialog
    uia_type_string("\n")
  end

  # confirms the second step: "You have already authorized ..."
  uia_tap_mark("OK")

  # the Facebook login process is done now,
  # modal w/ Safari will be dismissed
end
jmoody commented 8 years ago

@milancermak Thanks. That actually looks pretty good.

We know that Calabash can interact with the SafariViewController, we just don't have an example in our test apps.

Pull requests are welcome.

moustacheGit commented 8 years ago

Hi, I have the same issue recently, I need to interact with facebook login but I have no idea how to do it. Did you find any solution? Thanks

jmoody commented 7 years ago

facebook

We don't have a solution for this.

If someone want to open a PR on the Permissions project, we can, as a community, try to create a solution.

https://github.com/calabash/Permissions

I do not have the time to create and maintain a Facebook app to test login against.