Automating mobile web apps

If you’re interested in automating your web app 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 capabilities.//iOS用Safari浏览器,安卓用Chrome浏览器。

 

Mobile Safari on Simulator

First of all, make sure developer mode is turned on in your Safari preferences so that the remote debugger port is open.//使用发开着模式。

If you are 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:

 // java
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari");
capabilities.setCapability(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 have to trust the machine before you can can run tests against your iOS device.//实体机需要使用代理和额外的app。

For instruction on how 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 will need to:

  • Have the ios-webkit-debug-proxy installed, running and listening on port 27753 (see the hybrid docs for instructions)
  • Turn on web inspector on iOS device (settings > safari > advanced)
  • Create a provisioning profile that can be used to deploy the SafariLauncherApp.

To create a profile 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 generate the 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 you test to run against safari simply set the “browserName” to be “Safari”.

 

Java Example

 // java
//setup the web driver and launch the webview app.
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari");
URL url = new URL("http://127.0.0.1:4723/wd/hub");
AppiumDriver driver = new AppiumDriver(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");
WebElement div = driver.findElement(By.id("i_am_an_id"));
Assert.assertEquals("I am a div", div.getText()); //check the text retrieved matches expected value
driver.findElement(By.id("comments")).sendKeys("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 value
assertEqual('I am a div', div.text) # populate the comments field by id
driver.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 (an app with the package com.android.chrome) is installed on your device or emulator. Getting Chrome for the x86 version of the emulator is not currently possible without building Chromium, so you may want to run an ARM emulator and then copy a Chrome APK from a real device to get Chrome on an emulator.//仿真器必须要用ARM,然后装一个Chrome apk。
  • If downloaded from NPM, or running from the .app, nothing needs to be done. If running from source, npm install will download ChromeDriver and put it in node_modules/appium-chromedriver/chromedriver/<OS name>/ for users having npm v3+ and for npm v2 it will be in node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/<OS name>/. A particular version can be specified by passing the --chromedriver_version config property (e.g., npm install appium --chromedriver_version="2.16"), otherwise the most recent one will be retrieved.//如果从源码安装appium,那么需要把chrome driver放到特定路径下。

Then, use desired capabilities like these to run your test in Chrome:

 // java
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");

Note that on 4.4+ devices, you can also use the 'Browser’ browserName cap to automate the built-in browser. On all devices you can use the 'Chromium’ browserName cap to automate a build of Chromium.//在安卓系统版本4.4+的设备上,使用“Browser”这个browserName可以驱动内置浏览器,使用“Chromium”这个browserName可以驱动Chromium浏览器。

Troubleshooting chromedriver

As of Chrome version 33, a rooted device is no longer required. If running tests on older versions of Chrome, devices needed to be rooted as ChromeDriver required write access to the /data/local directory to set Chrome’s command line arguments.//使用版本号33及其以上的Chrome浏览器,设备不需要root权限。

If testing on Chrome app prior to version 33, ensure adb shell has read/write access to /data/local directory on the device://使用版本号33及其以上的Chrome浏览器时,adb shell需要有权限访问/data/local目录。

$ adb shell su -c chmod 777 /data/local

For more chromedriver specific documentation see ChromeDriver documentation.

appium(4)-Automating mobile web apps的更多相关文章

  1. Why mobile web apps are slow

    http://sealedabstract.com/rants/why-mobile-web-apps-are-slow/ I’ve had an unusual number of interest ...

  2. appium(7)-Automating mobile gestures

    While the Selenium WebDriver spec has support for certain kinds of mobile interaction, its parameter ...

  3. Isomorphic JavaScript: The Future of Web Apps

    Isomorphic JavaScript: The Future of Web Apps At Airbnb, we’ve learned a lot over the past few years ...

  4. HTML5和Web Apps框架和方法

    单页: 1jQuery Mobile 该框架以其基于AJAX的导航系统和可使用主题的ThemeRoller设计而闻名.支持Android,ios,Windows Phone,webOs等.编程模式为C ...

  5. 【Office Web Apps】在 SharePoint 中使用 Office Web Apps

    在 SharePoint 中使用 Office Web Apps 在安装并配置了 Microsoft Office Web Apps 的 SharePoint 网站上,通过 Office Web Ap ...

  6. Progressive Web Apps入门

      PC和Mobile开发技术演进 PC方向,从客户端到富客户端,到现在广泛使用的Web.   移动方向,目前主要还是原生应用和Mobile Web,PWA相关技术是未来发展方向.   PWA的概念 ...

  7. Asp.net与office web apps的整合

    其实网上有关office web app的整合已经有相关的文章了,典型的是如何整合Office Web Apps至自己开发的系统(一) 和如何整合Office Web Apps至自己开发的系统(二), ...

  8. Isomorphic JavaScript: The Future of Web Apps(译)

                                                                                                 Isomorp ...

  9. [转]60fps on the mobile web

    Flipboard launched during the dawn of the smartphone and tablet as a mobile-first experience, allowi ...

随机推荐

  1. babel转码神器babel-preset-env

    简介 现如今不同的浏览器和平台chrome, opera, edge, firefox, safari, ie, ios, android, node, electron 不同的模块 "am ...

  2. Codeforces 576D Flights for Regular Customers(矩阵加速DP)

    题目链接  Flights for Regular Customers 首先按照$d$的大小升序排序 然后分成$m$个时刻,每条路径一次处理过来. $can[i][j]$表示当前时刻$i$能否走到$j ...

  3. javascript 函数初探 (三)--- javascript 变量的作用域

    javascript 变量的作用域: 这是一个至关重要的问题.特别是当我们从别的语言转向javascript时,必须要明白一点,即在javascript中,变量的定义并不是以代码块作为作用域的,而是以 ...

  4. 算法题1+2+...+N

    题目:求1+2+-+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字以及条件判断语句(A?B:C). int solve(int n) { int i = 1 ...

  5. cocos2d-x step by step(3) Double Kill

    喏,咱们已经调通hello world 了,然后呢,咱们做一些高大上的东西,那做什么呢,做一个打乒乓球的小东西,啊哈! 这就是最终界面了,没画一个球形  就用一个白色方框代替吧. 啊哈! public ...

  6. iOS -- SKPhysicsJointSpring类

    SKPhysicsJointSpring类 继承自 NSObject 符合 NSCoding(SKPhysicsJoint)NSObject(NSObject) 框架  /System/Library ...

  7. 第八讲_图像问答Image Question Answering

    第八讲_图像问答Image Question Answering 课程结构 图像问答的描述 具备一系列AI能力:细分识别,物体检测,动作识别,常识推理,知识库推理..... 先要根据问题,判断什么任务 ...

  8. 在c++11中你最惊讶的新feature是什么?

    对我来说,我最惊讶竟然把对于多线程的支持加到标准中了.真的想不明确,对于c++这样一种语言.怎么会加进这个东西. 1. 由于各个平台的不同,对于多线程的支持会有很多平台独有的特色.这样c++标准的定义 ...

  9. XPath可以快速定位到Xml中的节点或者属性。XPath语法很简单,但是强大够用,它也是使用xslt的基础知识。

    示例Xml: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 <?xml versio ...

  10. Chrome内核保存为mhtml(单网页)

    在地址栏输入:chrome://flags  回车 然后Ctrl+f查找mhtml Tips: 如果网页图片看不太清可以CTRL+鼠标滚轮放大网页 如果系统原因以及其它因素可以下载:QQ浏览器(默认保 ...