Appium(3) 开始编写第一个app Test

参考网上其他大神文档,写一个简单的计算器的test

在上面两个练习,环境启动正常后,则可以开始练习

1.1、在intellij idea中创建一个Maven项目,之后在pom.xml添加如下依赖:

  

 <dependencies>
       <dependency>
           <groupId>org.seleniumhq.selenium</groupId>
           <artifactId>selenium-java</artifactId>
           <version>2.42.1</version>
       </dependency>
       <dependency>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-surefire-plugin</artifactId>
           <version>2.12.4</version>
       </dependency>
       <dependency>
           <groupId>org.testng</groupId>
           <artifactId>testng</artifactId>
           <version>6.8.8</version>
       </dependency>
       <dependency>
           <groupId>io.appium</groupId>
           <artifactId>java-client</artifactId>
           <version>3.2.0</version>
       </dependency>
       <dependency>
           <groupId>com.google.android</groupId>
           <artifactId>android</artifactId>
           <version>4.1.1.4</version>
       </dependency>
       <dependency>
           <groupId>junit</groupId>
           <artifactId>junit</artifactId>
           <version>4.12</version>
       </dependency>
   </dependencies>
   <build>
       <plugins>
           <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                   <forkMode>once</forkMode>
                   <argLine>-Dfile.encoding=UTF-8</argLine>
                </configuration>
           </plugin>
       </plugins>
</build>

1.2、在项目中创建一个类demo1,在类中输入以下代码、

代码内容为,启动Android模拟器上自带的Calculator计算器,并分别点击“1+2=”;

 

public class demo1 {

    private AppiumDriver driver;

    @Before
    public void calc() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();

        capabilities.setCapability("deviceName", "Android Emulator");
        capabilities.setCapability("platformVersion", "4.4.2");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("appPackage", "com.android.calculator2");
        capabilities.setCapability("appActivity", ".Calculator");
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
}

    @After
    public void tearDown() throws Exception {
        driver.quit();
    }

    @Test
    public void add() {
        driver.findElementByName("1").click();
        driver.findElementByName("+").click();
        driver.findElementByName("2").click();
        driver.findElementByName("=").click();
    }
}

1.3、在类中,右键单击


之后可看到测试用例正在运行

查看Appium,输出了很多运行的日志

查看模拟器,android 虚拟机打开了自带的计算器,并分别点击“1+2=”

到目前,配置Appium测试环境已大致完成了,并成功运行一个小的demo

后面就可以开始开发实际移动自动化测试用例了


注:参考一些其他大神文档,如有遇到相似,望各位大神谅解

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值