Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to launch Safari on real device (iOS) #1083

Closed
PavithraNavaneeth opened this issue Sep 2, 2013 · 40 comments
Closed

Failed to launch Safari on real device (iOS) #1083

PavithraNavaneeth opened this issue Sep 2, 2013 · 40 comments
Labels
Bug a problem that needs fixing iOS related to iOS native driver(s) Mobile Safari related to mobile Safari driver Real Devices relating to use w/ real devices

Comments

@PavithraNavaneeth
Copy link
Contributor

I am trying to test my web on Safari iOS. I am stuckup and not able to proceed: kindly help out!!

I followed the instructions from: https://github.com/appium/appium/blob/master/docs/hybrid.md

My device is connected to MAC.
I started the appium server (0.8.5) (GUI) providing properly UDID with force ipad and use Mobile Safari checked. I didnt provide the bundle id (hope it is not required to start safari on ios)

Here is my test:
Here is my test: Could you please help out resolving this issue..

private static WebDriver driver;
@BeforeTest
public void setUp() throws Exception {
DesiredCapabilities caps = new DesiredCapabilities();

    caps.setCapability("app", "safari");
    caps.setCapability("device", "iPad Device");
    caps.setCapability("version", "6.1");

    driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub/"), caps);
    System.out.println("Pausing.. Manually switch to safari now..");
    //here i manually switched to safari on the device
    Thread.sleep(10000);
    for(String winHandle : driver.getWindowHandles()){
        driver.switchTo().window(winHandle);
    }
    driver.get("http://mail.aol.com");
    Thread.sleep(5000);
}

First of all when it is instantiating the remotewebdriver, it is launching the ipad simulator (does it launch even when we want to run on device only) opens the safari browser and then throws the below errror in appium console:

info: Welcome to Appium v0.8.5 (REV 3a6720d)

info: Appium REST http interface listener started on 127.0.0.1:4723
info: socket.io started

debug: Appium request initiated at /wd/hub/session

info: Trying to use mobile safari, version 6.1

debug: Request received with params: {"desiredCapabilities":{"app":"safari","device":"iPad Device","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 pavithrank

info: Deleting /Users/pavithrank/Library/Application\ Support/iPhone\ Simulator/6.1/Library/Caches/Snapshots/com.apple.mobilesafari

info: Deleting /Users/pavithrank/Library/Application\ Support/iPhone\ Simulator/6.1/Library/Caches/com.apple.mobilesafari/Cache.db*
info: Deleting /Users/pavithrank/Library/Application\ Support/iPhone\ Simulator/6.1/Library/Caches/com.apple.WebAppCache/.db
info: Deleting /Users/pavithrank/Library/Application\ Support/iPhone\ Simulator/6.1/Library/Safari/
.plist
info: Deleting /Users/pavithrank/Library/Application\ Support/iPhone\ Simulator/6.1/Library/WebKit/LocalStorage/.
info: Deleting /Users/pavithrank/Library/Application\ Support/iPhone\ Simulator/6.1/Library/Library/WebKit/GeolocationSites.plist
info: Deleting /Users/pavithrank/Library/Application\ Support/iPhone\ Simulator/6.1/Library/Cookies/*.binarycookies

info: Creating new appium session 46bf8f15-a289-4cf7-b7e6-01a95bf67934

info: Cleaned up instruments socket /tmp/instruments_sock

debug: No device id or app, not installing to real device.

info: Not setting device type since we're connected to a 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: Attempting to run app on real device with UDID "Actual UDID Value"

info: Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Appium.app/Contents/Resources/node_modules/appium/app/uiauto/Automation.tracetemplate -w "Actual UDID Value" /tmp/Appium-MobileSafari.app -e UIASCRIPT /Applications/Appium.app/Contents/Resources/node_modules/appium/app/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/appium-instruments/
info: And extra without-delay env: {"DYLD_INSERT_LIBRARIES":"/usr/lib/libgenkit.dylib"}

info: [INST STDERR] 2013-09-02 15:17:19.705 instruments[29904:1703] Recording cancelled : At least one target failed to launch; aborting run
Instruments Trace Error : Failed to start trace.

error: Instruments did not launch successfully, failing session

info: [INSTSERVER] Instruments exited with code 253

error: Failed to start an Appium session, err was: Instruments did not launch successfully--please check your app paths or bundle IDs and try again

info: Responding to client with error: {"status":6,"value":{"message":"A session is either terminated or not started","origValue":"Instruments did not launch successfully--please check your app paths or bundle IDs and try again"},"sessionId":"46bf8f15-a289-4cf7-b7e6-01a95bf67934"}

POST /wd/hub/session 500 58075ms - 270

info: Clearing out appium devices

@PavithraNavaneeth
Copy link
Contributor Author

Additional details:

Pavithras-MacBook-Pro:~ pavithrank$ /bin/bash -c 'which node'
/usr/local/bin/node
Pavithras-MacBook-Pro:~ pavithrank$ /bin/bash -c 'which instruments_client'
/usr/local/bin/instruments_client
Pavithras-MacBook-Pro:~ pavithrank$

@PavithraNavaneeth
Copy link
Contributor Author

Do we need to get the webviewapp(from github repository) to be installed in the device to launch safari on the real device ?

@PavithraNavaneeth
Copy link
Contributor Author

Tried launching via SafariLauncher but still same issue. Through xcode I installed the Safarilauncher on the device and safari came up after few seconds delay.
When I start appium server - what bundle id I should provide or is it enough just to check on "Use mobile safari" ?

Kindly help out, I am stuck up !!

@snevesbarros
Copy link
Contributor

@PavithraNavaneeth, you have two options:

  • Use the SafariLauncher which navigates to a URL causing Safari to launch.
    It needs to have a 20 - 30 seconds delay after launching the app before it navigates to the link or else Appium thinks the app has crashed.
    NOTE: In this case you will have to set the app to be the safari launcher app.
  • Or if you dont want the 20 seconds delay then you can use the webview app.
    The downside of this is that the webview isn't as good as safari at rendering certain elements (e.g. canvas).
    NOTE: In this case you will have to set the app value to be the webview app.

For both solutions you will have to run the ios-webkit-debug-proxyand build the app using a profile that allows it to be installed on your device.

In NO case can you set the app to safari or set the bundle id to com.apple.mobilesafari for a real device. This will not work!

@PavithraNavaneeth
Copy link
Contributor Author

Sergio, Thanks for your reply !!
I wanted to launch via safarilauncher, however i am confused to how to launch safarilauncher via appium ?
Do I need to mention it in bundle id or as app in code ?
Or Do i need to start the safarilauncher manually everytime ?

Note: I have installed safarilauncher in my device via xcode. Also I have run the ios-webkit-debug-proxy..

@snevesbarros
Copy link
Contributor

When you build the app through Xcode it will stored on your machine in the ~/Library/Developer/Xcode/DerivedData/ folder. Find your .app file (in the iphoneos folder). Set this file including path as your "app" value.

@PavithraNavaneeth
Copy link
Contributor Author

Now, I could launch the safarilauncher in the device by providing the app details with path. However after starting the app it is just hanging and not proceeding further at all (I almost waited for more than 3 mts but nothing happened).

Here is my code:
DesiredCapabilities caps = new DesiredCapabilities();
String my_Safari = "/Users/pavithrank/Library/Developer/Xcode/DerivedData/SafariLauncher-cfrvqexlzffqbndvbwbhmlyvlqah/Build/Products/Debug-iphoneos/SafariLauncher.app";
caps.setCapability("app", my_Safari);
caps.setCapability("device", "iPad Device");
caps.setCapability("version", "6.1");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub/"), caps);
System.out.println("Pausing.. Manually switch to safari now..");
Thread.sleep(30000);
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
driver.get("http://mail.aol.com");
Thread.sleep(5000);

Note: I couldnt see even my System.println (pausing) in the eclipse console. Also, in appiium console, there were no further logs generated once the safarilauncher was started.
What should I do..

Appium logs:
info: Welcome to Appium v0.8.5 (REV 3a6720d)

info: Appium REST http interface listener started on 127.0.0.1:4723
info: socket.io started

debug: Appium request initiated at /wd/hub/session

debug: Request received with params: {"desiredCapabilities":{"app":"/Users/pavithrank/Library/Developer/Xcode/DerivedData/SafariLauncher-cfrvqexlzffqbndvbwbhmlyvlqah/Build/Products/Debug-iphoneos/SafariLauncher.app","device":"iPad Device","version":"6.1"}}

info: Using local app from desiredCaps: /Users/pavithrank/Library/Developer/Xcode/DerivedData/SafariLauncher-cfrvqexlzffqbndvbwbhmlyvlqah/Build/Products/Debug-iphoneos/SafariLauncher.app

info: Creating new appium session d60b3df5-c612-462d-a743-f1e3fd121bca

info: Cleaned up instruments socket /tmp/instruments_sock

debug: No device id or app, not installing to real device.

info: Not setting device type since we're connected to a 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: Attempting to run app on real device with UDID UDIDValue

info: Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Appium.app/Contents/Resources/node_modules/appium/app/uiauto/Automation.tracetemplate -w UDIDValue
/Users/pavithrank/Library/Developer/Xcode/DerivedData/SafariLauncher-cfrvqexlzffqbndvbwbhmlyvlqah/Build/Products/Debug-iphoneos/SafariLauncher.app -e UIASCRIPT /Applications/Appium.app/Contents/Resources/node_modules/appium/app/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/appium-instruments/

info: And extra without-delay env: {"DYLD_INSERT_LIBRARIES":"/usr/lib/libgenkit.dylib"}

info: [INST] 2013-09-03 04:49:24 +0000 Default: Instruments shell user: pavithrank

info: [INST] 2013-09-03 04:49:37 +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.

info: Pushing command to appium work queue: "au.bundleId()"

debug: Sending command to instruments: au.bundleId()

info: [INSTSERVER] Socket data received (15 bytes)

info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Sending command to instruments: au.bundleId()

info: [INST] 2013-09-03 04:49:43 +0000 Default: Got new command 0 from instruments: au.bundleId()

@snevesbarros
Copy link
Contributor

Try and launch it manually. Does it open safari after e.g 30 seconds?

@PavithraNavaneeth
Copy link
Contributor Author

Yes it is launching after a delay. Actually even via appium it is launching the safari after some delay but, after that it is stuck. Looks like after launching safari it is not responding back to appium and hence it hangs.

Sometimes, when I try to manually launch the safari launcher app (in between during this hung) - it responds back and proceeds further - but not all the time.

So, how should I get rid of this - not responding issue?

Thanks
Pavithra

On 03-Sep-2013, at 12:45 PM, Sergio Neves Barros notifications@github.com wrote:

Try and launch it manually. Does it open safari after e.g 30 seconds?


Reply to this email directly or view it on GitHub.

@snevesbarros
Copy link
Contributor

Check in the safariLauncher app if the timeout in the app is set to 20 seconds. If it is change it to 30. I have seen a few threads were this was the problem. Appium needs to be given enough time to determine the app has launched successfully.

Once you have safari open and appium ready your switch to window should take over (and make sure you have the ios webkit debug proxy running in the background).

Sergio

@PavithraNavaneeth
Copy link
Contributor Author

In SafariLauncher - I could see the default value startDelay_ = 20; which I changed it to 30; now. Hope this is fine ?
Now, I am getting the below error from Instrument:

info: [INST] 2013-09-03 09:09:27 +0000 Fail: Could not start script, target application is not frontmost.
Instruments Trace Complete (Duration : 33.310009s; Output : /Applications/Appium.app/Contents/Resources/node_modules/appium/instrumentscli16.trace)

info: [INSTSERVER] Instruments exited with code 0

@PavithraNavaneeth
Copy link
Contributor Author

Out of bloom, just one time it proceeded fully. Is it expected to work inconsistent? (or) is there any permanent way out for this..

@snevesbarros
Copy link
Contributor

As we are not polling when appium is "ready" but merely guessing, the time-out depends on the speed/power of the machine and device it's running and testing against.

So where 20 seconds might work for one machine/device combination another might need 40.

A more reliable solution will have to be put in place anyways (e.g. a way for appium to detect that it's safari that has been launched and not throw any errrors at that point.).

@PavithraNavaneeth
Copy link
Contributor Author

I am confused... actually when the safarilauncher is launching via appium (it approximately takes around 15 to 20 seconds) to launch the browser and to navigate to default url:www.apple.com. And default delay is provided as 30 seconds in safarilauncher - presferences code. With this, I hope it should work - kindly clarify. In my case, after launching the app (within 15 to 20 secs) - it is just hanging. It looks like: Instrument is not responding back - could you please clarify this by checking the below console logs:So, what could be reason for the instrument to get stuck?

info: And extra without-delay env: {"DYLD_INSERT_LIBRARIES":"/usr/lib/libgenkit.dylib"}

info: [INST] 2013-09-03 04:49:24 +0000 Default: Instruments shell user: pavithrank

info: [INST] 2013-09-03 04:49:37 +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.

info: Pushing command to appium work queue: "au.bundleId()"

debug: Sending command to instruments: au.bundleId()

info: [INSTSERVER] Socket data received (15 bytes)

info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Sending command to instruments: au.bundleId()

info: [INST] 2013-09-03 04:49:43 +0000 Default: Got new command 0 from instruments: au.bundleId()

@PavithraNavaneeth
Copy link
Contributor Author

I increased the time to 45 seconds now and built the app. Now, I am consistently getting the below error:"Could not start script, target application is not frontmost." But I could see the safarillauncher.app is launched and ready..
what does this mean?

info: Instruments exited with code 1 and trace dir undefined

error: Instruments socket client never checked in; timing out

info: [INST] 2013-09-04 07:01:39 +0000 Fail: Could not start script, target application is not frontmost.
Instruments Trace Complete (Duration : 41.808094s; Output : /Applications/Appium.app/Contents/Resources/node_modules/appium/instrumentscli43.trace)

error: Instruments did not launch successfully, failing session

@snevesbarros
Copy link
Contributor

I think you're better off waiting until this functionality is supported by Appium and using the web view app until then. It's much easier to setup and to run.

This functionality is definitely one of the things I would like to pick up in the near future if I can.

For now it simply seems to be to unreliable (which is to be expected considering the hard coded wait and how it's trying to "fool" appium, rather then using it properly).

@jlipps
Copy link
Member

jlipps commented Sep 4, 2013

@snevesbarros, what is necessary to make Appium aware of what's going on here?

On Sep 4, 2013, at 1:03 AM, Sergio Neves Barros notifications@github.com wrote:

I think you're better off waiting until this functionality is supported by Appium and using the web view app until then. It's much easier to setup and to run.

This functionality is definitely one of the things I would like to pick up in the near future if I can.

For now it simply seems to be to unreliable (which is to be expected considering the hard coded wait and how it's trying to "fool" appium, rather then using it properly).


Reply to this email directly or view it on GitHub.

@snevesbarros
Copy link
Contributor

I looked into it a while ago. I think what happens when the app navigates
to the page and launches Safari instruments assumes the app has died and
the onExit callback is triggered for instruments.

I was looking at how to determine that it was the safari launcher:

  1. Checking if the front-most app is Safari
  2. Doing it based on the bundle ID of the safari launcher (not nice)

If we can stop it at that point the remote debugger can take over.

The next thing was to see if we could close our reset the browser (or maybe
just the tabs). hadn't checked yet if this was possible with webkit
protocol.

Sergio
On 4 Sep 2013 17:22, "Jonathan Lipps" notifications@github.com wrote:

@snevesbarros, what is necessary to make Appium aware of what's going on
here?

On Sep 4, 2013, at 1:03 AM, Sergio Neves Barros notifications@github.com
wrote:

I think you're better off waiting until this functionality is supported
by Appium and using the web view app until then. It's much easier to setup
and to run.

This functionality is definitely one of the things I would like to pick
up in the near future if I can.

For now it simply seems to be to unreliable (which is to be expected
considering the hard coded wait and how it's trying to "fool" appium,
rather then using it properly).


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1083#issuecomment-23803037
.

@jlipps
Copy link
Member

jlipps commented Sep 5, 2013

What if we detected that (a) the user's app is 'safari' and (b) the user has a UDID therefore wanting to run the test on a real device.

In this case we could launch the safari launcher app automatically and know to wait. In other words, we could bundle the safari launcher as part of appium itself and use it as a special case when the user requests 'safari' as the app for a real device.

Jonathan

On Sep 5, 2013, at 12:08 AM, Sergio Neves Barros notifications@github.com wrote:

I looked into it a while ago. I think what happens when the app navigates
to the page and launches Safari instruments assumes the app has died and
the onExit callback is triggered for instruments.

I was looking at how to determine that it was the safari launcher:

  1. Checking if the front-most app is Safari
  2. Doing it based on the bundle ID of the safari launcher (not nice)

If we can stop it at that point the remote debugger can take over.

The next thing was to see if we could close our reset the browser (or maybe
just the tabs). hadn't checked yet if this was possible with webkit
protocol.

Sergio
On 4 Sep 2013 17:22, "Jonathan Lipps" notifications@github.com wrote:

@snevesbarros, what is necessary to make Appium aware of what's going on
here?

On Sep 4, 2013, at 1:03 AM, Sergio Neves Barros notifications@github.com
wrote:

I think you're better off waiting until this functionality is supported
by Appium and using the web view app until then. It's much easier to setup
and to run.

This functionality is definitely one of the things I would like to pick
up in the near future if I can.

For now it simply seems to be to unreliable (which is to be expected
considering the hard coded wait and how it's trying to "fool" appium,
rather then using it properly).


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1083#issuecomment-23803037
.


Reply to this email directly or view it on GitHub.

@snevesbarros
Copy link
Contributor

What about build profile? The user would have to deploy the safari launcher
app to their device with a valid profile but what would you set as the app
value when running the test?

From your description I assume you would want to use the bundled app in
appium you were mentioning, but would that work without it having been
built with a suitable profile (as long as they're not deploying it)?

Or is it possible to use the bundle id?

Sergio
On 5 Sep 2013 16:41, "Jonathan Lipps" notifications@github.com wrote:

What if we detected that (a) the user's app is 'safari' and (b) the user
has a UDID therefore wanting to run the test on a real device.

In this case we could launch the safari launcher app automatically and
know to wait. In other words, we could bundle the safari launcher as part
of appium itself and use it as a special case when the user requests
'safari' as the app for a real device.

Jonathan

On Sep 5, 2013, at 12:08 AM, Sergio Neves Barros notifications@github.com
wrote:

I looked into it a while ago. I think what happens when the app
navigates
to the page and launches Safari instruments assumes the app has died and
the onExit callback is triggered for instruments.

I was looking at how to determine that it was the safari launcher:

  1. Checking if the front-most app is Safari
  2. Doing it based on the bundle ID of the safari launcher (not nice)

If we can stop it at that point the remote debugger can take over.

The next thing was to see if we could close our reset the browser (or
maybe
just the tabs). hadn't checked yet if this was possible with webkit
protocol.

Sergio
On 4 Sep 2013 17:22, "Jonathan Lipps" notifications@github.com wrote:

@snevesbarros, what is necessary to make Appium aware of what's going
on
here?

On Sep 4, 2013, at 1:03 AM, Sergio Neves Barros <
notifications@github.com>
wrote:

I think you're better off waiting until this functionality is
supported
by Appium and using the web view app until then. It's much easier to
setup
and to run.

This functionality is definitely one of the things I would like to
pick
up in the near future if I can.

For now it simply seems to be to unreliable (which is to be expected
considering the hard coded wait and how it's trying to "fool" appium,
rather then using it properly).


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub<
https://github.com/appium/appium/issues/1083#issuecomment-23803037>
.


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1083#issuecomment-23876898
.

@jlipps
Copy link
Member

jlipps commented Sep 6, 2013

It is possible to use the bundle ID alone. So assuming they've got it on their device….

Or we could just have the code for the launcher app in appium itself and build it using xcodebuild and deploy it to the device using your fruitstrap methods

On Sep 6, 2013, at 2:22 AM, Sergio Neves Barros notifications@github.com wrote:

What about build profile? The user would have to deploy the safari launcher
app to their device with a valid profile but what would you set as the app
value when running the test?

From your description I assume you would want to use the bundled app in
appium you were mentioning, but would that work without it having been
built with a suitable profile (as long as they're not deploying it)?

Or is it possible to use the bundle id?

Sergio
On 5 Sep 2013 16:41, "Jonathan Lipps" notifications@github.com wrote:

What if we detected that (a) the user's app is 'safari' and (b) the user
has a UDID therefore wanting to run the test on a real device.

In this case we could launch the safari launcher app automatically and
know to wait. In other words, we could bundle the safari launcher as part
of appium itself and use it as a special case when the user requests
'safari' as the app for a real device.

Jonathan

On Sep 5, 2013, at 12:08 AM, Sergio Neves Barros notifications@github.com
wrote:

I looked into it a while ago. I think what happens when the app
navigates
to the page and launches Safari instruments assumes the app has died and
the onExit callback is triggered for instruments.

I was looking at how to determine that it was the safari launcher:

  1. Checking if the front-most app is Safari
  2. Doing it based on the bundle ID of the safari launcher (not nice)

If we can stop it at that point the remote debugger can take over.

The next thing was to see if we could close our reset the browser (or
maybe
just the tabs). hadn't checked yet if this was possible with webkit
protocol.

Sergio
On 4 Sep 2013 17:22, "Jonathan Lipps" notifications@github.com wrote:

@snevesbarros, what is necessary to make Appium aware of what's going
on
here?

On Sep 4, 2013, at 1:03 AM, Sergio Neves Barros <
notifications@github.com>
wrote:

I think you're better off waiting until this functionality is
supported
by Appium and using the web view app until then. It's much easier to
setup
and to run.

This functionality is definitely one of the things I would like to
pick
up in the near future if I can.

For now it simply seems to be to unreliable (which is to be expected
considering the hard coded wait and how it's trying to "fool" appium,
rather then using it properly).


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub<
https://github.com/appium/appium/issues/1083#issuecomment-23803037>
.


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1083#issuecomment-23876898
.


Reply to this email directly or view it on GitHub.

@PavithraNavaneeth
Copy link
Contributor Author

Kindly let me know when this can be expected to get resolved. Sorry, till then we are stuck up and cannot proceed further.

@snevesbarros
Copy link
Contributor

@PavithraNavaneeth as mentioned above you can use the web view app (in the sample code) to do your testing until this has been resolved. This is what we are currently using for our browser based tests and it works for viewing and interacting with web pages.

Once the solution is in place your tests will require minor tweaks to get them working with Safari.

NOTE: The only downside to the web view is it struggles to render e.g. the HTML5 canvas (which works well with Safari), but other than that its fine.

@PavithraNavaneeth
Copy link
Contributor Author

With webapp view what I noticed manually (also) is I am not able to navigate to any url by typing in the url value in the address bar field. Tap on Go button- doesnt do anything. May be we can change the default url to our app url in webviewapp. But in between the tests we have scenarios to type in the address bar and navigate - which might not work if 'tap on go' doesnt work.

@snevesbarros
Copy link
Contributor

You dont need the native elements (e.g the go button) to navigate to a page.

Simply grab the windhandles switch to the web view and the use the webdriver goto method go navigate to whatever page you want.

@PavithraNavaneeth
Copy link
Contributor Author

Any idea I am not able to checkout the webviewapp from https://github.com/appium/appium/tree/master/sample-code/apps/WebViewApp
Note: I could checkout Safarilauncher, but while checkout webviewapp it is saying fatal error: repository not found..

Tried git clone https://github.com/appium/appium/tree/master/sample-code/apps/WebViewApp

@PavithraNavaneeth
Copy link
Contributor Author

Checked out and tested with WebViewApp on ipad. But it is not rendering the UI as expected as in Safari. We have different UI for iphone and ipad and with WebViewApp on ipad - it is showing the iphone UI even with zoomed view (since the webview app is of specific size). Hence it doesn't solve the purpose for us. As of now, I can live with testing only on iphone and ipad Simulators. But kindly resolve the issue with SafariLauncher so that real device testing can be proceeded.

@snevesbarros
Copy link
Contributor

Our team was quite proactive and innovative and altered the app in a couple of hours. It simply needs a view for ipad which any ios developer can do (and in our case a QA did it). A little pro-activeness goes a long way :)

@PavithraNavaneeth
Copy link
Contributor Author

Thanks for the suggestion and motivation Sergio :-) Modified the code and got the webviewapp for ipad view and it is running fine for our web app.

@snevesbarros
Copy link
Contributor

👍

@PavithraNavaneeth
Copy link
Contributor Author

Now got issue with iphone. I built the app on iphone - it is launching the webview app. But when driver is trying to get the windowhandles the app is getting killed. Also appium server is also stopped. Here is my code and appium console logs:
Set windowHandles = driver.getWindowHandles();
String nextWindowName = windowHandles.iterator().next();
driver.switchTo().window(nextWindowName);

console logs:
info: Using local app from desiredCaps: /Users/pavithrank/Library/Developer/Xcode/DerivedData/WebViewApp-cdpzaddiuzidvvfcbqcaitpceyxv/Build/Products/Debug-iphoneos/WebViewApp.app

info: Creating new appium session 3faf1a30-9134-4500-bb5d-8f002095e2dd

debug: Appium request initiated at /wd/hub/session

debug: Request received with params: {"desiredCapabilities":{"app":"/Users/pavithrank/Library/Developer/Xcode/DerivedData/WebViewApp-cdpzaddiuzidvvfcbqcaitpceyxv/Build/Products/Debug-iphoneos/WebViewApp.app","device":"iphone device","version":"6.1"}}

info: Cleaned up instruments socket /tmp/instruments_sock

debug: No device id or app, not installing to real device.

info: Not setting device type since we're connected to a 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: Attempting to run app on real device with UDID c320087b32c72ec753434668a811c7046e7be152

info: Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Appium.app/Contents/Resources/node_modules/appium/app/uiauto/Automation.tracetemplate -w c320087b32c72ec753434668a811c7046e7be152 /Users/pavithrank/Library/Developer/Xcode/DerivedData/WebViewApp-cdpzaddiuzidvvfcbqcaitpceyxv/Build/Products/Debug-iphoneos/WebViewApp.app -e UIASCRIPT /Applications/Appium.app/Contents/Resources/node_modules/appium/app/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/appium-instruments/
info: And extra without-delay env: {}

info: [INST] 2013-09-12 11:38:58 +0000 Default: Instruments shell user: pavithrank

info: [INST] 2013-09-12 11:39:11 +0000 Default: Found node in Appium.app

info: [INSTSERVER] Instruments is ready to receive commands

debug: Sending command to instruments: au.bundleId()

info: Instruments launched. Starting poll loop for new commands.
info: Pushing command to appium work queue: "au.bundleId()"
info: [INSTSERVER] Socket data received (15 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event

info: [INSTSERVER] Sending command to instruments: au.bundleId()

info: [INST] 2013-09-12 11:39:15 +0000 Default: Got new command 0 from instruments: au.bundleId()

info: [INST] 2013-09-12 11:39:15 +0000 Default: Result is not protocol compliant, wrapping

info: [INSTSERVER] Socket data received (68 bytes)

debug: Sending command to instruments: au.setScreenOrientation('PORTRAIT')

info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":"io.appium.WebViewApp"}
info: Bundle ID for open app is io.appium.WebViewApp
info: Setting initial orientation to PORTRAIT
info: Pushing command to appium work queue: "au.setScreenOrientation('PORTRAIT')"
info: [INSTSERVER] Sending command to instruments: au.setScreenOrientation('PORTRAIT')

info: [INST] 2013-09-12 11:39:16 +0000 Default: Got new command 1 from instruments: au.setScreenOrientation('PORTRAIT')

info: [INSTSERVER] Socket data received (56 bytes)

debug: Sending command to instruments: setBootstrapConfig: useLocationServices=true

info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":"PORTRAIT"}
info: Pushing command to appium work queue: "setBootstrapConfig: useLocationServices=true"
info: [INSTSERVER] Sending command to instruments: setBootstrapConfig: useLocationServices=true

info: [INST] 2013-09-12 11:39:16 +0000 Debug: target.setDeviceOrientation("1")
2013-09-12 11:39:17 +0000 Default: Got new command 2 from instruments: setBootstrapConfig: useLocationServices=true

info: [INST] 2013-09-12 11:39:17 +0000 Default: Got bootstrap config: useLocationServices=true

info: [INST] 2013-09-12 11:39:17 +0000 Default: Set bootstrap config key 'useLocationServices' to true

info: [INSTSERVER] Socket data received (56 bytes)

info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":"PORTRAIT"}
info: Appium session started with sessionId 3faf1a30-9134-4500-bb5d-8f002095e2dd

debug: Appium request initiated at /wd/hub/session/3faf1a30-9134-4500-bb5d-8f002095e2dd

POST /wd/hub/session 303 35310ms - 9
info: Responding to client with success: {"status":0,"value":{"version":"6.0","webStorageEnabled":false,"locationContextEnabled":false,"browserName":"iOS","platform":"MAC","javascriptEnabled":true,"databaseEnabled":false,"takesScreenshot":true},"sessionId":"3faf1a30-9134-4500-bb5d-8f002095e2dd"}
GET /wd/hub/session/3faf1a30-9134-4500-bb5d-8f002095e2dd 200 2ms - 319

debug: Appium request initiated at /wd/hub/session/3faf1a30-9134-4500-bb5d-8f002095e2dd/window_handles

error: uncaughtException date=Thu Sep 12 2013 17:08:08 GMT+0530 (IST), pid=95745, uid=502, gid=20, cwd=/Applications/Appium.app/Contents/Resources/node_modules/appium, execPath=/Applications/Appium.app/Contents/Resources/node/bin/node, version=v0.10.15, argv=[/Applications/Appium.app/Contents/Resources/node/bin/node, /Applications/Appium.app/Contents/Resources/node_modules/appium/server.js, --port, 4723, --app, /Users/pavithrank/Library/Developer/Xcode/DerivedData/WebViewApp-cdpzaddiuzidvvfcbqcaitpceyxv/Build/Products/Debug-iphoneos/WebViewApp.app, --udid, c320087b32c72ec753434668a811c7046e7be152, --no-session-override, --keep-artifacts], rss=38674432, heapTotal=31139328, heapUsed=15515376, loadavg=[1.21923828125, 1.3662109375, 1.5498046875], uptime=535738, trace=[column=11, file=net.js, function=errnoException, line=901, method=null, native=false, column=19, file=[as oncomplete] (net.js, function=Object.afterConnect, line=892, method=afterConnect, native=false], stack=[Error: connect ECONNREFUSED, at errnoException (net.js:901:11), at Object.afterConnect as oncomplete]

@snevesbarros
Copy link
Contributor

Not really sure what the error is related to.

Do make sure that the ios-webkit-debug-proxy is running (for the right device) in the background.

Verify that your app works manually and is able to navigate to a page etc...

@PavithraNavaneeth
Copy link
Contributor Author

I am getting the exception exactly when it driver is trying to get the window handles (not while launching the app). Through automation I am able to launch the app in the iphone device (it confirms that I am using the right udid of the device in the background).
Manually - I am able to launch the webview app, type the url in the url field but its not navigating when I tap on Go button. Samething happened on ipad also manually,however when I ran the automation code for ipad - it navigated to the proper url.

@PavithraNavaneeth
Copy link
Contributor Author

w.r.t iphone device - webinspector in safari settings was not enabled on the phone. Hence it was failing with above error. Now my test runs successfully on iphone device as well with webviewapp. Thanks !!

@jlipps
Copy link
Member

jlipps commented Sep 17, 2013

we should definitely add this to README/docs/troubleshooting. it's important for both simulator and real device, webview/hybrid/safari support

On Sep 17, 2013, at 3:05 PM, PavithraNavaneeth notifications@github.com wrote:

w.r.t iphone device - webinspector in safari settings was not enabled on the phone. Hence it was failing with above error. Now my test runs successfully on iphone device as well with webviewapp. Thanks !!


Reply to this email directly or view it on GitHub.

@PavithraNavaneeth
Copy link
Contributor Author

Just an update to this actual issue: When I gave sleep for 30 Secs to my selenium code (after launching the driver) + along with increasing the safari launcher delay to 30 sec- it resolved the issue of throwing the error: Could not start script, target application is not frontmost.

Now, I have the question of how to close the safari launcher app? From one of the google discussion, Sergio suggested to use https://github.com/appium/appium/blob/master/sample-code/examples/java/testng/src/main/java/com/example/LocalWebDriver.java

But when I directly just used mobile: closeapp it didn't work. It is not closing the safari app which is not allowing my next test to launch the safari (unless i restart my device).

@snevesbarros
Copy link
Contributor

#1244 this fix removes the need for the delay.

@penguinho
Copy link
Member

I think the issue here is resolved, also no updates in 2 months.

@ASYB
Copy link

ASYB commented Aug 7, 2014

Hi

I am facing the same issue like safariLauncher is launched successfully but later on it hangs I mean driver.get(myURL) is not opening in the safari.

DesiredCapabilities d = new DesiredCapabilities();
d.setCapability("browserName", "Safari");
d.setCapability("udid","70149e3cfa43cd97f95f3302b8fe0586bd058322");
d.setCapability("deviceName", "z081534’s iPhone");
d.setCapability("app","/Users/a041720/Library/Developer/Xcode/DerivedData/SafariLauncher-fbbrjxxurtldtyafzgoimqjfxpet/Build/Products/Debug-iphoneos/SafariLauncher.app");
d.setCapability("BundleID", "com.target.SafariLauncher");

d.setCapability("platformName", "iOS");
URL url = new URL("http://127.0.0.1:4723/wd/hub");
RemoteWebDriver remoteWebDriver = new RemoteWebDriver(url, d);

// Navigate to the page and interact with the elements on the guinea-pig page using id.
remoteWebDriver.navigate().to("http://google.com");

Please find the logs

info: Welcome to Appium v1.2.0 (REV fd2c284)
info: Appium REST http interface listener started on 0.0.0.0:4723
debug: Non-default server args: {"udid":"6865f773f09277c6e8c6df46c7bb4273b994cd4d"}
info: LogLevel: debug
info: --> POST /wd/hub/session {"desiredCapabilities":{"app":"/Users/a041720/Library/Developer/Xcode/DerivedData/SafariLauncher-fbbrjxxurtldtyafzgoimqjfxpet/Build/Products/Debug-iphoneos/SafariLauncher.app","deviceName":"z081534’s iPhone","platformName":"iOS","browserName":"Safari","udid":"6865f773f09277c6e8c6df46c7bb4273b994cd4d","BundleID":"com.target.SafariLauncher"}}
debug: The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : BundleID
debug: Configuring Safari session
debug: Using local .zip from desired caps: /Users/a041720/Desktop/shaik/appium/build/SafariLauncher/SafariLauncher.zip
debug: Copying local zip to tmp dir
debug: /Users/a041720/Desktop/shaik/appium/build/SafariLauncher/SafariLauncher.zip copied to /var/folders/pm/bxq0m6ys6yj13d3gf21tfwlmtjgpw2/T/11477-7578-176zwu2/appium-app.zip
debug: Unzipping /var/folders/pm/bxq0m6ys6yj13d3gf21tfwlmtjgpw2/T/11477-7578-176zwu2/appium-app.zip
debug: Testing zip archive: /var/folders/pm/bxq0m6ys6yj13d3gf21tfwlmtjgpw2/T/11477-7578-176zwu2/appium-app.zip
debug: Zip archive tested clean
debug: Unzip successful
debug: Using locally extracted app: /var/folders/pm/bxq0m6ys6yj13d3gf21tfwlmtjgpw2/T/11477-7578-176zwu2/submodules/SafariLauncher/build/Release-iphoneos/SafariLauncher.app
debug: Creating new appium session 813b1470-94b4-4cac-87c9-6e748f6946df
debug: Removing any remaining instruments sockets
debug: Cleaned up instruments socket /tmp/instruments_sock
debug: Setting Xcode folder
debug: Setting Xcode version
debug: Setting iOS SDK Version
debug: iOS SDK Version set to 7.1
debug: Detecting automation tracetemplate
debug: Not auto-detecting udid, running on sim
error: Could not parse plist file (as binary) at /var/folders/pm/bxq0m6ys6yj13d3gf21tfwlmtjgpw2/T/11477-7578-176zwu2/submodules/SafariLauncher/build/Release-iphoneos/SafariLauncher.app/en.lproj/Localizable.strings
info: Will try to parse the plist file as XML
parseFileSync() is deprecated. Use parseStringSync() instead.
error: Could not parse plist file (as XML) at /var/folders/pm/bxq0m6ys6yj13d3gf21tfwlmtjgpw2/T/11477-7578-176zwu2/submodules/SafariLauncher/build/Release-iphoneos/SafariLauncher.app/en.lproj/Localizable.strings
warn: Could not parse app Localizable.strings
debug: Not setting locale because we're using a real device
debug: Creating instruments
debug: Preparing uiauto bootstrap
debug: Dynamic bootstrap dir: /Users/a041720/Library/Application Support/appium/bootstrap
debug: Dynamic env: {"nodePath":"/usr/local/Cellar/node/0.10.30/bin/node","commandProxyClientPath":"/Users/a041720/Desktop/shaik/appium/node_modules/appium-uiauto/bin/command-proxy-client.js","instrumentsSock":"/tmp/instruments_sock"}
debug: Dynamic bootstrap code: // This file is automatically generated. Do not manually modify!

#import "/Users/a041720/Desktop/shaik/appium/node_modules/appium-uiauto/uiauto/bootstrap.js";

bootstrap({
nodePath: "/usr/local/Cellar/node/0.10.30/bin/node",
commandProxyClientPath: "/Users/a041720/Desktop/shaik/appium/node_modules/appium-uiauto/bin/command-proxy-client.js",
instrumentsSock: "/tmp/instruments_sock",
});
debug: Dynamic bootstrap path: /Users/a041720/Library/Application Support/appium/bootstrap/bootstrap-eea82a889943d8c8.js
debug: Reusing dynamic bootstrap: /Users/a041720/Library/Application Support/appium/bootstrap/bootstrap-eea82a889943d8c8.js
debug: Fixing device was changed from:" iPhone - Simulator - iOS 7.1 " to:"iPhone Retina (4-inch 64-bit) - Simulator - iOS 7.1"
debug: Not setting iOS and app preferences since we're on a real device
debug: Starting iOS device log capture via idevicesyslog
debug: Not setting device type since we're connected to a device
debug: Getting bundle ID from app
debug: Parsed app Info.plist (as binary)
debug: Checking app install status using: /Users/a041720/Desktop/shaik/appium/build/fruitstrap/fruitstrap isInstalled --id 6865f773f09277c6e8c6df46c7bb4273b994cd4d --bundle com.bytearc.SafariLauncher
debug: Starting command proxy.
debug: Instruments socket server started at /tmp/instruments_sock
debug: Starting instruments
debug: Instruments is at: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments
info: Launching instruments
debug: Attempting to run app on real device with UDID 6865f773f09277c6e8c6df46c7bb4273b994cd4d
debug: Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -D /tmp/appium-instruments/instrumentscli0.trace -w 6865f773f09277c6e8c6df46c7bb4273b994cd4d /var/folders/pm/bxq0m6ys6yj13d3gf21tfwlmtjgpw2/T/11477-7578-176zwu2/submodules/SafariLauncher/build/Release-iphoneos/SafariLauncher.app -e UIASCRIPT /Users/a041720/Library/Application Support/appium/bootstrap/bootstrap-eea82a889943d8c8.js -e UIARESULTSPATH /tmp/appium-instruments
debug: And extra without-delay env: {}
debug: And launch timeouts (in ms): {"global":90000}
debug: [INST] 2014-08-07 11:30:23 +0000 Fail: Could not start script, target application is not frontmost.

debug: [INST] Instruments Trace Complete (Duration : 14.199546s; Output : /tmp/appium-instruments/instrumentscli0.trace)

debug: [INSTSERVER] Instruments exited with code 0
debug: Cleaning up after instruments exit
debug: Not worrying about instruments exit since we're using SafariLauncher

@lock
Copy link

lock bot commented May 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators May 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug a problem that needs fixing iOS related to iOS native driver(s) Mobile Safari related to mobile Safari driver Real Devices relating to use w/ real devices
Projects
None yet
Development

No branches or pull requests

5 participants