iOS testing Facebook login (switch to Safari)

1,261 views
Skip to first unread message

Ling-Yi Kung

unread,
Aug 8, 2013, 12:05:15 AM8/8/13
to appium-...@googlegroups.com
Hello! I've implemented Facebook logging in for the app I'm testing, but I'm getting a weird bug. I'm using the strategy discussed here, where I have three sequential sessions:
  1. In the app, press the login button.
  2. In mobile Safari, log in and authorize the app.
  3. Open the app again to continue testing.
All the right buttons are getting pressed...but the user is not logged in when the app is opened the second time (the third step). This isn't a bug in the app code, since when you do it manually on the Simulator, everything works. I've put in some delays while the apps are switching in case some weird things are happening there, but those didn't help. Has anyone successfully implemented Facebook login in iOS before?

I put my code (part of my LoginScreen class and some helper functions) in a pastebin because it has nice syntax highlighting.

Running in the Simulator, the test (that just creates a new LoginScreen and calls login) looks like it should work.
  • It transitions from app to Safari when the login button is pressed.
  • The Safari driver kicks up, the username and password are entered, the login button for Facebook is pressed which opens a new page that asks the user to authorize the app, the button to confirm authorization is pressed, and it transitions from Safari to the app.
    • It wouldn't have transitioned to the app (before the app driver was started) unless the confirm button was pressed.
  • However, when the app loads after the transition, the user is not logged in.
  • Same when the app driver starts and the app is brought up again - the user isn't logged in.
This is super weird because 1) I could've sworn it worked on Sunday night when I was working on it (which is why I went home for the night, haha), and 2) the automation is going through all the right motions. I'm not sure if it's a weird Safari cookies thing (cookies are enabled for the Simulator), but it should work because it works manually.

Thanks in advance!

Jonathan Lipps

unread,
Aug 8, 2013, 11:55:07 AM8/8/13
to Ling-Yi Kung, appium-...@googlegroups.com
It might be that Appium is clearing out all app state and mobile safari state in between sessions. Make sure to add the --no-reset flag to the server if you haven't tried this already.

--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ling-Yi Kung

unread,
Aug 8, 2013, 4:18:41 PM8/8/13
to appium-...@googlegroups.com, Ling-Yi Kung
I restarted appium using "appium --no-reset", then ran my tests again. It seems like it's still clearing out the plist, though? This is when shutting down Safari and restarting the app:

debug: Appium request initiated at /wd/hub/session/1aa0c424-5a1b-444f-96c6-2eea754da667
info: Shutting down appium session...
info: [REMOTE] Disconnecting from remote debugger
info: [REMOTE] Debugger socket disconnected
info: [INST] 2013-08-08 20:11:39 +0000 Stopped: Script was stopped by the user
       Instruments Trace Complete (Duration : 7.174868s; Output : /Users/lkung/instrumentscli0.trace)

info: [INSTSERVER] Instruments exited with code 0
info: [INSTSERVER] Socket closed forcibly due to exit
info: [INSTSERVER] Instruments socket server closed
info: Deleted tracedir we heard about from instruments (/Users/lkung/instrumentscli0.trace)
info: Clearing out appium devices
info: Responding to client with success: {"status":0,"value":null,"sessionId":"1aa0c424-5a1b-444f-96c6-2eea754da667"}
DELETE /wd/hub/session/1aa0c424-5a1b-444f-96c6-2eea754da667 200 155ms - 89
info: Clearing out any previous sessions
debug: Appium request initiated at /wd/hub/session
debug: Request received with params: {"desiredCapabilities":{"app":"/Users/lkung/Documents/foo/foo_ios_app/FooAcceptance/lib/../Foo.app","browserName":"iOS","platform":"Mac","version":"6.1"}}
info: Using local app from desiredCaps: /Users/lkung/Documents/foo/foo_ios_app/FooAcceptance/lib/../Foo.app
info: Clearing out any previous sessions
info: Creating new appium session bf229bf8-660f-4ac8-a306-75aea8456e8f
info: Cleaned up instruments socket /tmp/instruments_sock
info: Forcing use of iphone
info: Parsed app Info.plist
info: Wrote new app Info.plist with device type
debug: No device id or app, not installing to real device.
debug: Creating instruments
info: instruments is: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments
info: [INSTSERVER] Instruments socket server started at /tmp/instruments_sock
info: Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /usr/local/share/npm/lib/node_modules/appium/app/uiauto/Automation.tracetemplate /Users/lkung/Documents/foo/foo_ios_app/FooAcceptance/lib/../Foo.app -e UIASCRIPT /usr/local/share/npm/lib/node_modules/appium/app/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/253d5a44-f267-4baa-a91c-67639c5eede3
info: And extra without-delay env: {"DYLD_INSERT_LIBRARIES":"/usr/local/share/npm/lib/node_modules/appium/build/iwd/InstrumentsShim.dylib","LIB_PATH":"/usr/local/share/npm/lib/node_modules/appium/build/iwd"}
info: [INST] 2013-08-08 20:11:47 +0000 Default: Instruments shell user: lkung
info: [INST] 2013-08-08 20:11:47 +0000 Default: Found node using `which node`: /usr/local/bin/node
info: [INSTSERVER] Instruments is ready to receive commands
info: Instruments launched. Starting poll loop for new commands.

And this is when the login button is clicked in the app and it transfers to Safari:

debug: Appium request initiated at /wd/hub/session/d54e0e7f-4f60-4b50-a876-537898d294b0/element/5/click
debug: Request received with params: {}
info: Pushing command to appium work queue: "au.tapById('5')"
debug: Sending command to instruments: au.tapById('5')
info: [INSTSERVER] Sending command to instruments: au.tapById('5')
info: [INST] 2013-08-08 20:11:22 +0000 Default: Got new command 14 from instruments: au.tapById('5')
info: [INSTSERVER] Socket data received (50 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":null}
info: Responding to client with success: {"status":0,"value":null,"sessionId":"d54e0e7f-4f60-4b50-a876-537898d294b0"}
POST /wd/hub/session/d54e0e7f-4f60-4b50-a876-537898d294b0/element/5/click 200 294ms - 89
debug: Appium request initiated at /wd/hub/session/d54e0e7f-4f60-4b50-a876-537898d294b0
info: Shutting down appium session...
info: [INST] 2013-08-08 20:11:22 +0000 Debug: (null).tap()
       2013-08-08 20:11:25 +0000 Stopped: Script was stopped by the user
Instruments Trace Complete (Duration : 8.193750s; Output : /Users/lkung/instrumentscli0.trace)

info: [INSTSERVER] Instruments exited with code 0
info: [INSTSERVER] Socket closed forcibly due to exit
info: [INSTSERVER] Instruments socket server closed
info: Deleted tracedir we heard about from instruments (/Users/lkung/instrumentscli0.trace)
info: Clearing out appium devices
info: Responding to client with success: {"status":0,"value":null,"sessionId":"d54e0e7f-4f60-4b50-a876-537898d294b0"}
DELETE /wd/hub/session/d54e0e7f-4f60-4b50-a876-537898d294b0 200 1027ms - 89
info: Clearing out any previous sessions
debug: Appium request initiated at /wd/hub/session
debug: Request received with params: {"desiredCapabilities":{"app":"safari","device":"iPhone Simulator","version":"6.1"}}
info: Trying to use mobile safari, version 6.1
info: Looking for built in app MobileSafari
info: Got app, trying to copy to tmp dir
info: Copied MobileSafari to /tmp/Appium-MobileSafari.app
info: Using mobile safari app at /tmp/Appium-MobileSafari.app
info: Cleaning mobile safari data files
info: Determining current user
info: User is lkung

Is something getting lost because it uses Safari in /tmp/ and not the actual one?

Ling-Yi Kung

unread,
Aug 8, 2013, 4:42:14 PM8/8/13
to appium-...@googlegroups.com, Ling-Yi Kung
Ah, sorry, cut off the logs too short. In the second one (shutting down the app and starting Safari), after "info: User is lkung", is this:

info: Deleting /Users/lkung/Library/Application\ Support/iPhone\ Simulator/6.1/Library/Caches/Snapshots/com.apple.mobilesafari
info: Deleting /Users/lkung/Library/Application\ Support/iPhone\ Simulator/6.1/Library/Caches/com.apple.mobilesafari/Cache.db*
info: Deleting /Users/lkung/Library/Application\ Support/iPhone\ Simulator/6.1/Library/Caches/com.apple.WebAppCache/*.db
info: Deleting /Users/lkung/Library/Application\ Support/iPhone\ Simulator/6.1/Library/Safari/*.plist
info: Deleting /Users/lkung/Library/Application\ Support/iPhone\ Simulator/6.1/Library/WebKit/LocalStorage/*.*
info: Deleting /Users/lkung/Library/Application\ Support/iPhone\ Simulator/6.1/Library/Library/WebKit/GeolocationSites.plist
info: Deleting /Users/lkung/Library/Application\ Support/iPhone\ Simulator/6.1/Library/Cookies/*.binarycookies
info: Clearing out any previous sessions
info: Creating new appium session 1aa0c424-5a1b-444f-96c6-2eea754da667
info: Cleaned up instruments socket /tmp/instruments_sock
info: Forcing use of iphone
info: Parsed app Info.plist
info: Wrote new app Info.plist with device type
debug: No device id or app, not installing to real device.
debug: Creating instruments
info: instruments is: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments
info: [INSTSERVER] Instruments socket server started at /tmp/instruments_sock
info: Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /usr/local/share/npm/lib/node_modules/appium/app/uiauto/Automation.tracetemplate /tmp/Appium-MobileSafari.app -e UIASCRIPT /usr/local/share/npm/lib/node_modules/appium/app/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/ca9a1f4b-26d5-461a-b284-eba21bb2304a
info: And extra without-delay env: {"DYLD_INSERT_LIBRARIES":"/usr/local/share/npm/lib/node_modules/appium/build/iwd/InstrumentsShim.dylib","LIB_PATH":"/usr/local/share/npm/lib/node_modules/appium/build/iwd"}
info: [INST] 2013-08-08 20:11:34 +0000 Default: Instruments shell user: lkung
info: [INST] 2013-08-08 20:11:34 +0000 Default: Found node using `which node`: /usr/local/bin/node
info: [INSTSERVER] Instruments is ready to receive commands
info: Instruments launched. Starting poll loop for new commands.

Everything is being erase before Safari starts...I'm not sure what's going on after Safari ends. I want the Facebook login cookies saved for the Safari on the device, and for them to exist even after that Safari is closed.

On Thursday, August 8, 2013 8:55:07 AM UTC-7, Jonathan Lipps wrote:

Jonathan Lipps

unread,
Aug 8, 2013, 4:55:32 PM8/8/13
to Ling-Yi Kung, appium-...@googlegroups.com
It could be that when using Safari everything is reset even when you have --no-reset set as a flag. If so that would be a bug!

Can you create a github issue to track this?

Jonathan

Ling-Yi Kung

unread,
Aug 8, 2013, 5:23:24 PM8/8/13
to appium-...@googlegroups.com, Ling-Yi Kung
Created! I tried it using both Appium 0.8.2 and 0.8.3 and --no-reset seems to fail for both.

Ling-Yi Kung

unread,
Aug 9, 2013, 3:44:05 AM8/9/13
to appium-...@googlegroups.com, Ling-Yi Kung
Hi Jonathan,

I commented out the code to erase the Safari data (toDeletes in helpers.js) and put a dummy directory 'foo' I had made in the baseDir as the only thing in the array. I'm not entirely sure what's going on in the code, but my test still wasn't able to login. What other places could data deletion happen?

The log is below:
debug: Appium request initiated at /wd/hub/session
debug: Request received with params: {"desiredCapabilities":{"app":"safari","device":"iPhone Simulator","version":"6.1"}}
info: Trying to use mobile safari, version 6.1
info: Looking for built in app MobileSafari
info: Got app, trying to copy to tmp dir
info: Copied MobileSafari to /tmp/Appium-MobileSafari.app
info: Using mobile safari app at /tmp/Appium-MobileSafari.app
info: Cleaning mobile safari data files
info: Determining current user
info: User is lkung
info: Deleting /Users/lkung/Library/Application\ Support/iPhone\ Simulator/6.1/Library/foo
info: Clearing out any previous sessions
info: Creating new appium session 631758a6-9e64-449b-a3b5-56f9590a980e
info: Cleaned up instruments socket /tmp/instruments_sock
info: Forcing use of iphone
info: Parsed app Info.plist
info: Wrote new app Info.plist with device type
debug: No device id or app, not installing to real device.
debug: Creating instruments
info: instruments is: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments
info: [INSTSERVER] Instruments socket server started at /tmp/instruments_sock

Thanks!

Ling-Yi Kung

unread,
Aug 9, 2013, 4:35:57 PM8/9/13
to appium-...@googlegroups.com, Ling-Yi Kung, jli...@gmail.com
We discovered the underlying issue to Facebook login, and the truth is that it will never work without using the embedded webview dialog because there can only be sequential sessions in Appium. Can this be made clear in the documentation, please?

The app I'm testing avoids using the webview dialog because the user always has to enter their login credentials every time they go through the login flow. Therefore, it defaults to opening the Facebook app if the device has it installed, or Safari, if there is no Facebook app. What happens is that when the "Log in with Facebook" button is pressed, a callback is passed to the Facebook SDK. The callback is how Facebook communicates with the app whether the user authorized it or not, and if the user did, gives the app the user information. What is happening (due to the nature of sequential sessions) is:
  1. App instance A is started. The login button is pressed and App A passes the callback to Facebook and awaits a response.
  2. Safari is started. This kills App A. The user logs into Facebook and authorizes the app (or not), and Facebook executes the callback.
  3. There's nothing listening to the callback.
  4. App instance B is started. It has no knowledge that anything ever happened with Facebook.
Our workaround for the time being is to create a testing version of the app that always uses the embedded webview, which Facebook login should theoretically work on (since the app is never exited). This is bad because we don't actually test how a user logs in, but it's the only way we can see Facebook login working until Appium supports multiple sessions.
Reply all
Reply to author
Forward
0 new messages