[自动化测试] Junit+webdrive 实现android手机测试

selenium官网看到一篇讲述的是关于seleniumandroid手机上运行的文章,于是也就自己试了试。以android模拟器为例(在手机上运行会更顺畅)


配置环境android SDK4.04+ Android WebDriver

系统环境:winXP


步骤一:安装模拟器 Android Virtual Device (AVD)

该模拟器的安装不细说,网上一大堆,也可以不装直接用自己的手机也可。

我自己采用的是配置了AVD,然后模拟手机设置了一个1G的SD卡装置,将程序安装在模拟的SDK上;

启动AVD:emulator -avd SDK4.04 -sdcard D:\android-sdk-windows\tools\sdcard.img

步骤二:安装webdrive

从官网下载webdrive的apk:android-server-2.21.0.apk(地址:http://code.google.com/p/selenium/downloads/list

下载后模拟手机安装到模拟器的sdk上,安装好后如图:


页面上的webDrive代表已经装好了。

启动webdrive,映射8080端口:adb forward tcp:8080 tcp:8080

启动后,看到的手机页面是黑色的屏幕,弹出一个webdrive is already的信息后便进入无尽的等待中....

这个时候不要以为是自己没有装好,而是你手机端的webdrive没有收到请求,没有运行而已;


步骤三、编写junit测试用例

首先依赖包:selenium-java-X.zip

建立junit测试单元,测试google的单元,如下代码:

import static org.junit.Assert.*;
import org.junit.Test;
import junit.framework.TestCase;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.android.AndroidDriver;


public class OneTest extends TestCase {
public void testGoogle() throws Exception {
  WebDriver driver = new AndroidDriver();

  // And now use this to visit Google
  driver.get("http://www.google.com");

  // Find the text input element by its name
  WebElement element = driver.findElement(By.name("q"));

  // Enter something to search for
  element.sendKeys("Cheese!");

  // Now submit the form. WebDriver will find the form for us from the
  // element
  element.submit();

  // Check the title of the page
  System.out.println("Page title is: " + driver.getTitle());
  driver.quit();
}

@Test
public void test() throws Exception {
  this.testGoogle();
  fail("Not yet implemented");
}
}


测试单元也编写完成了,webdrive也在运行就绪状态,这个时候便是体现是否可行的时机了,
我们运行junit单元,仔细观察手机:


继续运行:


至此完成手机上webdrive的测试验证。
目前webdrive手机上测试只支持的Andriod手机系统为:Gingerbread (2.3.x), Honeycomb (3.x), Ice Cream Sandwich (4.0.x) and later
另外IOS支持至少4.2以上的版本。

参考文档:http://code.google.com/p/selenium/wiki/AndroidDriver
有兴趣的可以继续参阅后续的junit+webdrive的测试框架搭建!


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值