Automating mobile web Apps
If you ' re interested in automating your Web apps in Mobile Safari on IOS or Chrome on Android, Appium can help you. Basically, you write a normal webdriver test, and use Appium as the Selenium server with a special set of desired Capabili Ties. //ios with Safari browser, Android with Chrome browser.
Mobile Safari on Simulator
First of all, make sure developer mode are turned on your Safari preferences so that's the remote debugger port is open.// Use the open mode.
If you were using the simulator or a real device, you must run Safari before attempting to use Appium.
Then, use desired capabilities like these to run your test in mobile Safari:
JavaDesiredcapabilitiesCapabilities=NewDesiredcapabilities();Capabilities.Setcapability(Mobilecapabilitytype.Platform_name. (mobilecapabilitytype. Platform_version. (mobilecapabilitytype. Browser_name. (mobilecapabilitytype. Device_name "IPhone Simulator"
Mobile Safari on a Real IOS Device
We Use the Safarilauncher App to launch Safari and run Tests against mobile Safari. Once Safari has been launched the Remote Debugger automatically connects using the Ios-webkit-debug-proxy. When working with Ios-webkit-debug-proxy, you had to trust the machine before you can can run tests against your iOS Devi Ce. //physical machines need to use proxies and additional apps.
For instruction on what to install and run ios-webkit-debugger-proxy see iOS webkit debug proxy documentation.
Setup
Before you can run your tests against Safari on a real device you'll need to:
- The ios-webkit-debug-proxy installed, running and listening on port 27753 (see the Hybrid docs for Instructi Ons
- Turn on Web Inspector in IOS device (settings > Safari >Advanced)
- Create a provisioning profile which can used to deploy the Safarilauncherapp.
To create a profiles for the launcher go into the Apple developers Member Center and:
- Step 1: Create a new app ID and select the WildCard app ID option and set it to "*"
- Step 2: Create a New development profile and for App Id Select the one created in step 1.
- Step 3: Select your certificate (s) and device (s) and click Next.
- Step 4: Set the profile name and generatethe profile.
- Step 5: Download the profile and open it with a text editor.
- Step 6: Search for the UUID and the string for it is your identity code.
Now simply include your UDID and device name in your desired capabilities:
{ "udid": ‘...‘, "deviceName": ‘...‘, "browserName": "Safari" }
Running your test
To configure your test to run against Safari simply set the "Browsername" to be "Safari".
Java Example
JavaSetup the Web driver and launch the WebView app.DesiredcapabilitiesDesiredcapabilities=NewDesiredcapabilities();Desiredcapabilities.Setcapability(Mobilecapabilitytype.Browser_name,"Safari");UrlUrl=NewUrl("Http://127.0.0.1:4723/wd/hub");AppiumdriverDriver=NewAppiumdriver(Url,Desiredcapabilities);Navigate to the page and interact with the elements on the Guinea-pig page using ID.Driver.Get("Http://saucelabs.com/test/guinea-pig");WebelementDiv=Driver.Findelement(By.Id("I_AM_AN_ID"assert. ( "I am a div" div.< Span class= "NA" >gettext ()); //check the text retrieved matches expected Valuedriver.findelement (by. Id ( "comments" ( "My comment" //populate the comments field by ID. //close the App.driver. Quit ()
Python Example
# python# setup The Web driver and launch the WebView app.Capabilities={' Browsername ':' Safari '}Driver=Webdriver.Remote(' Http://localhost:4723/wd/hub ',Capabilities)# Navigate to the page and interact with the elements on the Guinea-pig page using ID.Driver.Get(' Http://saucelabs.com/test/guinea-pig ');Div=driver. Find_element_by_id ( ' i_am_an_id ' ) # check the text Retrieved matches expected Valueassertequal ( ' I am a div ' div. Text) # populate the Comments field by Iddriver.find_element_by_id ( ' comments ' ) . Send_keys ( ' My comment ' ) # close the driver driver. Quit ()
Mobile Chrome on Emulator or Real Device
Pre-requisites:
- Make sure Chrome (a app with the package
com.android.chrome
) is installed on your device or emulator. Getting Chrome for the x86 version of the emulator are not currently possible without building Chromium Run an ARM emulator and then copy a Chrome APK from a real device to get Chrome on an emulator. //emulator must use arm and then install a chrome apk.
- If downloaded from NPM, or running from the. App, nothing needs to is done. If running from source, would
npm install
download chromedriver and put it in for node_modules/appium-chromedriver/chromedriver/<OS name>/
users has npm v3+ and for NPM v2 it WI ll is in node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/<OS name>/
. A particular version can specified by passing the --chromedriver_version
Config property (e.g., npm install appium --chromedriver_version="2.16"
), otherwise the most recent one WI ll be retrieved. //If you install Appium from the source, you need to put chrome driver on a specific path.
Then, use desired capabilities like these to run your test in Chrome:
JavaDesiredcapabilitiesCapabilities=NewDesiredcapabilities();Capabilities.Setcapability(Mobilecapabilitytype.Platform_name, "Android" ); capabilities. (mobilecapabilitytype. Platform_version. (mobilecapabilitytype. Device_name "Android Emulator" ); . (mobilecapabilitytype. Browser_name
Note in 4.4+ devices, you can also use the ' Browser ' browserName
cap to automate the built-in Browser. On all devices your can use the ' Chromium ' browserName
cap to automate a build of Chromium. On Android version 4.4+ device, use "Browser" this browsername can drive the built-in browser, use "Chromium" this browsername can drive Chromium browser.
Troubleshooting Chromedriver
As of Chrome version, a rooted device is no longer required. If running tests on older versions of Chrome, devices needed to being rooted as chromedriver required write access to The/da Ta/local directory to set Chrome's command line arguments. //using a Chrome browser with version number 33 and above, the device does not require root access.
If testing on Chrome apps prior to version, ensure ADB shell have read/write access to/data/local directory on the Devic E://When using version number 33 and above, the ADB shell needs to have access to the/data/local directory.
$ adb shell su -c chmod 777 /data/local
For more Chromedriver specific documentation see Chromedriver documentation.
Automating mobile web Apps