Appium对自动化手机网页应用

如果你正对于如何在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

前期设置

当你要在真机上的Safari中执行你的测试脚本之前你需要先注意以下几点: *安装并正常运行ios-webkit-debug-proxy(具体可以参考(shybrid docs) *打开iOS真机中的web inspector,可以在iOS6.0或更高版本中的设置 > safari > 高级找到。 *创建一个provisioning profile 能够帮助你配置safariLauncher. * 你可以前往Apple Developers Member Center 创建一个launcher profile:

  • 第一步: 创建一个新的App Id 同时设置WildCard App ID这个选项置为"*"
  • 第二步: 为步骤1的App Id创建一个new Development Profile .
  • 第三步: 选择你的certificate(s) and device(s) 并选择下一步.
  • 第四步: 设置profile的名称以及generate the profile.
  • 第五步: 下载profile并使用文本编辑器打开.
  • 第六步: 寻找并牢记你的UUID

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

$ git clone https://github.com/appium/appium.git
$ cd appium

# 选项1:你可以不设置任何的参数就可以设置ios开发者证书
$ ./reset.sh --ios --real-safari

# 选项2:你需要定义code signing identity并且允许xcode可选择profile identity code
$ ./reset.sh --ios --real-safari --code-sign '' 

#选项3:你需要设置
$ ./reset.sh --ios --real-safari --code-sign '' --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'
};

原文链接:官方教程 Appium入门 - 自动化手机网页应用

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值