如果你正对于如何在iOS的Safari或Android上的Chrome做网页应用的自动化,那么Appium能够帮助你。你可以写一个最普通的WebDriver测试代码,就像使用Selenium服务一样使用Appium来满足需求。

iOS模拟器上的Safari浏览器

首先,我们需要先确认在你的Safari浏览器的设置中开启了开发者模式,这样Safari的远程调试端口也会被同时打开。

如果你打算在模拟器或真机上使用Appium的话,你必须先开发Safari。

然后设置如下显示的这些信息以便于在设备中的Safari执行测试:


{
  app: 'safari'
  , device: 'iPhone Simulator'
  , version: '6.1'
}


iOS真机上的Safari浏览器

为了能够在真机上的Safari执行测试,我们使用了SafariLauncher App来启动Safari。使用ios-webkit-webkit-proxy来自动启动Safari的远程调试功能。

提示: 目前针对iOS7版本的上,ios-webkit-debug-proxy有一个问题。a bug

前期设置

ios-webkit-debug-proxy(具体可以参考(shybrid docs) *打开iOS真机中的web inspector,可以在iOS6.0或更高版本中的设置 > safari > 高级找到。 *创建一个provisioning profile 能够帮助你配置safariLauncher. * 你可以前往Apple Developers Member Center

  • 第一步: 创建一个新的App Id
  • 第二步: 为步骤1的App Id创建一个new Development Profile
  • 第三步: 选择你的certificate(s) and device(s)
  • 第四步: 设置profile的名称以及generate the profile.
  • 第五步:
  • 第六步: 寻找并牢记你的UUID

现在你有了自己的profile文件,可以在终端中输入如下的命令:


'
 

#选项3:你需要设置和
$ ./reset.sh --ios --real-safari --code-sign '' --profile ''

#设置成功之后,就可以像往常一样启动服务
$ node /lib/server/main.js -U 
和

$ ./reset.sh --ios --real-safari --code-sign '' --profile ''

#设置成功之后,就可以像往常一样启动服务
$ node /lib/server/main.js -U 
'
 --profile ''

#设置成功之后,就可以像往常一样启动服务
$ node /lib/server/main.js -U



执行你的测试

如果要在safari下的运行你的测试, 只需要简单的配置app为safari即可

Java 举例


//setup the web driver and launch the webview app.
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("app", "safari");  
URL url = new URL("http://127.0.0.1:4723/wd/hub");
RemoteWebDriver remoteWebDriver = new RemoteWebDriver(url, desiredCapabilities);

// Navigate to the page and interact with the elements on the guinea-pig page using id.
remoteWebDriver.get("http://saucelabs.com/test/guinea-pig");
WebElement div = remoteWebDriver.findElement(By.id("i_am_an_id"));
Assert.assertEquals("I am a div", div.getText()); //check the text retrieved matches expected value
remoteWebDriver.findElement(By.id("comments")).sendKeys("My comment"); //populate the comments field by id.

//close the app.
remoteWebDriver.quit();


在真机或模拟器上的Chrome执行测试

需要做的准备:

  • 确认Chrome已经安装在了你的真机或模拟器上 (应用的包名是

com.android.chrome

  • ) .在不编译chromiun的情况下, 不可能得到模拟器上的x86版本的chrome, 你可以运行一个ARM的模拟器然后从真机上获取一个Chrome的APK安装在模拟器上.
  • 确认 ChromeDriver, version >= 2.0 正确的安装在你的系统上并且设置了

chromedriver

  • 成为系统全局变量.

接着,像这样设置就可以在Chrome上执行测试了:


{
  app: 'chrome'
  , device: 'Android'
};