Mobile Web automation on iOS real device – Safari


#1

As there are a lot of us facing issues with Safari browser automation, I wanted to document the steps that
help the members to do the browser automation.

  1. Pre-requisites:
    a. Xcode installed on Mac OS X.
    b. Device added to Apple developer program
    c. Get SafariLauncher.app(https://github.com/budhash/SafariLauncher)
    d. Launch the SafariLauncher.app on connected device from Xcode.
    e. Install appium (IDE)
    f. Download appium from github (https://github.com/appium/appium)
    g. Install ios-webkit-debug-proxy … use below command from terminal.
    Install brew install ios-webkit-debug-proxy

  2. a. Connect the device to your mac and verify the device is shown under Xcode
    b. Launch the app on device from xcode

  3. Open appium IDE, add your device details as mentioned in the below screen.

  1. launch ios_webkit_debug_proxy from terminal

  2. Open new terminal window and navigate to your cloned appium source and
    run the command ./bin/ios-webkit-debug-proxy-launcher.js -cUDID -d (This is workaround for dubug proxy crash)

Launch the appium from IDE

You are all set to run your test now.

Below is the standalone TestNG/java file to open google home page.

package vin.automation;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.ios.IOSDriver;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class VinWebTest {
AppiumDriver driver;
DesiredCapabilities capabilities = new DesiredCapabilities();

@BeforeClass()
public void init() throws MalformedURLException {
	capabilities.setCapability("platformName", "iOS");
	capabilities.setCapability("deviceName", "iPhone 5s");
	capabilities.setCapability("browser", "safari");
	driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"),
			capabilities);
	driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

@Test
public void googleTest() {
	driver.get("http://www.google.com");
}

}

Please let me know if you face any issues, Happy coding.

Thanks,
Amarnath Rayudu


Hi all, Am planning to use Appium to test my application in mobile. As am very new to this can any plz guide how to select the framework and which one is best for my application. And how do i design it?
Unable to launch safari browser even in Simulator: error: Could not prepare mobile safari: Error: Couldn't find built in app in its home or temp dir!
Error Message: A new session could not be created. (Original error: Please provide the 'app' or 'browserName' capability or start appium with the --app or --browser-name argument. Alternatively, you may provide the 'bundleId' and 'udid' capabilities for a
Unable to launch safari on real device using appium
Fruitstrap quit unexpectedly when I tried to launch safari on real device
#2

Hi Amarnath,
Really appreciate your initiative. This will definitely help our community and mobile world.

Thanks,
Donald


#3

Hi Amarnath ,

Thanks for sharing the information.
After configuring everything I am not able to laucnh URL using “driver.get(“http://www.google.com”);”

can you please help me out?

Thanks,
Amol


#4

@AmarnathRayudu Are you able to continuously run SafariBrowser in iOS real device. Like some 100+ testscripts continuosly without any break/stall???


#5

Hi @Mobile_Test_Test ,
We are also doing automation on real device on iOS on safari, but test execution is not stable. We face issues with stale tabs which remain in the browser in case a script fails. Now we are facing an issue when we try to click an element which opens a new tab. As soon as new tab is opened we see an issue in appium server- The target application appears to have died. Do you have any idea about this issue ?


#6

Hi All,

Can any one of you please let me know how to open the safari from Xcode ?

Thanks in advance!


#7

Hi All,

I have gone through the above the Pre-requisites and I have done the same set up but I got stuck @ one step.

These things I have already done - SafariLauncher is installed via XCODE on IPAD Mini Air (9.3) and device is also connected using os-webkit-debug-proxy.

But when I am running test I am getting below exception

==================================================

info: [debug] Error: ENOENT, stat ‘/Applications/Appium.app/Contents/Resources/node_modules/appium/build/SafariLauncher/SafariLauncher.zip’
at Error (native)
info: [debug] Responding to client with error: {“status”:33,“value”:{“message”:“A new session could not be created. (Original error: ENOENT, stat ‘/Applications/Appium.app/Contents/Resources/node_modules/appium/build/SafariLauncher/SafariLauncher.zip’)”,“errno”:-2,“code”:“ENOENT”,“path”:"/Applications/Appium.app/Contents/Resources/node_modules/appium/build/SafariLauncher/SafariLauncher.zip",“origValue”:“ENOENT, stat ‘/Applications/Appium.app/Contents/Resources/node_modules/appium/build/SafariLauncher/SafariLauncher.zip’”},“sessionId”:null}

error: Failed to start an Appium session, err was: Error: ENOENT, stat ‘/Applications/Appium.app/Contents/Resources/node_modules/appium/build/SafariLauncher/SafariLauncher.zip’

info: <-- POST /wd/hub/session 500 162.301 ms - 498

===========================================

Can anyone guide me here ??

Thanks & Regards
Mukesh


#8

Hey @Mukesh_otwani, can you please tell me how to do that ? how to get the xcode project and launch it from xcode ?


#9

Download XCode and Install it. After installation import the SafariLauncher in xcode and Run it.

Once build is successful, it will installed SafariLauncher in your device


#10

Friends, I did all my setup. That is setting up Safari Launcher and webkit proxy as well. The problem is when I start the test Safari Launcher starts and opens up the browser but no URL launches. Just the apple.com page launches.

The same test runs well on Simulator.


#11

Hey @yukonpd, you should launch the url from your test scripts, not the SafariLauncher.
If you would like to change the first launched page from the SafariLauncher, you should open it with Xcode and change the Default Value of Root.plist


#12

Thanks @mferturk for your reply,
I launched the URL from the test scripts itself, below is the snippet:

Web driver class{

  private WebDriver setMobileDriver(Map<String, String> selConfig) {

        DesiredCapabilities cap = new DesiredCapabilities();
	String [] appiumDeviceConfig = selConfig.get("mobileDevice").split(":"); 
	cap.setCapability("deviceName", appiumDeviceConfig[0]);
	cap.setCapability("automationName", "Appium");
	cap.setCapability("platformName", "iOS");
	String appiumServerHostUrl = selConfig.get("appiumServer");
	URL appiumServerHost = null;
	try {
		appiumServerHost = new URL(appiumServerHostUrl);
	} catch (MalformedURLException e) {
		e.printStackTrace();
	}
	cap.setJavascriptEnabled(true);
	System.out.println(appiumServerHostUrl);
	AppiumDriver driver=new IOSDriver(appiumServerHost, cap);
	
	try {
		Thread.sleep(30000);
		System.out.println("now entering url");
	} catch (InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	driver.get("https://google.com");

Just to remind the same lines work on the Simulator, I have appium 3.1.0 version under my POM.xml. Just let me know if you need more info.


#13

Please change the url driver.get("

https://google.com

"); to

https://www.google.com/


#14

Hi Friends,

My mobile application is a iOS Native app. Please go through the below steps

  1. After Launching the app there is a button called Forgot Your PIN
  2. When we click on Forgot Your PIN button.
  3. The application will redirect to a Safari Web page where I have the below fields.
  4. Mobile Number, Last Name and Data of Birth Picker.
  5. I am unable to tap or select Mobile Number field by using Tap feature of Safari browser using Appium Inspector.

So please someone help me how to tap or select Mobile number field of a browser.


#15

Hi yukonpd,

I have the same issue with you.
Did you solve it? Could you share for us your solution?


#16

Hi otwani

I have the same issue with you.
Did you solve it? Could you share for us your solution?


#17

Hi Friends,

No till now I did not get any solution, if anything is there i will let you know guys.

Thanking you,
Bhaskar.M


#18

Hi, I am facing issue with safari on real device. SafariLauncher opens the safari browser on device but did not hit my URL.
set following capabilities
deviceUDID= xxxxxx
bundleid= com.apple.mobilesafari
appium-version =1.4.11
browserName =Safari
platformName =iOS
deviceName =iPhone 6
platformVersion =8.4


#19

Hi Mukesh,

I am facing the same issue. could you pls share the solution?


#20

Hi Mukesh,

I got the same error which you were getting earlier, could you please confirm whether you got a solution for this.

info: --> POST /wd/hub/session {“desiredCapabilities”:{“appium-version”:“1.4.13”,“platformName”:“iOS”,“deviceName”:“Bin_iPhone”,“udid”:“1f789643be7b96813c4d2ae5b037bc27cb1b4a26”,“bundleId”:“com.binoy.safarilauncher”,“browserName”:“safari”,“version”:“8.4.1”}}

info: Client User-Agent string: undefined
info: *************************************
info: *************************************
info: *************************************
info: *************************************
info: *************************************
info: *************************************
info: *************************************
info: *************************************
info: **** NEW SESSION ***
info: **** NEW SESSION ***
info: **** NEW SESSION ***
info: **** NEW SESSION ***
info: **** NEW SESSION ***
info: **** NEW SESSION ***
info: **** NEW SESSION ***
info: **** NEW SESSION ***
info: *************************************
info: *************************************
info: *************************************
info: *************************************
info: *************************************
info: *************************************
info: *************************************
info: *************************************
info: [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. : appium-version, version

error: Failed to start an Appium session, err was: Error: ENOENT, stat '/Applications/Appium.app/Contents/Resources/node_modules/appium/build/SafariLauncher/SafariLauncher.zip’

info: [debug] Configuring Safari session
info: [debug] Using local .zip from command line: /Applications/Appium.app/Contents/Resources/node_modules/appium/build/SafariLauncher/SafariLauncher.zip
info: [debug] Copying local zip to tmp dir
info: [debug] Got configuration error, not starting session
info: [debug] Cleaning up appium session
info: [debug] Error: ENOENT, stat ‘/Applications/Appium.app/Contents/Resources/node_modules/appium/build/SafariLauncher/SafariLauncher.zip’
at Error (native)
info: [debug] Responding to client with error: {“status”:33,“value”:{“message”:“A new session could not be created. (Original error: ENOENT, stat ‘/Applications/Appium.app/Contents/Resources/node_modules/appium/build/SafariLauncher/SafariLauncher.zip’)”,“errno”:-2,“code”:“ENOENT”,“path”:"/Applications/Appium.app/Contents/Resources/node_modules/appium/build/SafariLauncher/SafariLauncher.zip",“origValue”:“ENOENT, stat ‘/Applications/Appium.app/Contents/Resources/node_modules/appium/build/SafariLauncher/SafariLauncher.zip’”},“sessionId”:null}
info: <-- POST /wd/hub/session 500 4.849 ms - 498

Thanks
Bin