码迷,mamicode.com
首页 > 移动开发 > 详细

用java和junit编写app自动化测试用例

时间:2018-01-13 22:17:41      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:pre   man   absolute   编写   stc   post   www.   orm   htm   

package myTest;

import static org.junit.Assert.*;

import io.appium.java_client.android.AndroidDriver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities; 
 
import java.io.File;  
import java.net.URL;  
import java.util.List;
import java.util.concurrent.TimeUnit;

public class MyTestCase {
    private AndroidDriver driver;

    @Before
    public void setUp() throws Exception {
        //设置apk的路径
        File classpathRoot = new File(System.getProperty("user.dir"));
        File appDir = new File(classpathRoot, "apps");
        File app = new File(appDir, "calculator_debug_2.3.1_10000_svn80220_200_staging_2017_12_16.apk");
        
        //设置自动化相关参数
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("deviceName", "7N2SSE158P001892");
        capabilities.setCapability("deviceName", "P4M7N15104001008");
                 
        //设置安卓系统版本
        capabilities.setCapability("platformVersion", "4.4.2");
        capabilities.setCapability("platformVersion", "6.0");
        //设置apk路径
        capabilities.setCapability("app", app.getAbsolutePath()); 
                
        //设置app的主包名和主类名
        capabilities.setCapability("appPackage", "com.gomo.calculator");
        capabilities.setCapability("appActivity", ".ui.activity.MainActivity");
                 
        //初始化
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); 
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @After
    public void tearDown() throws Exception {
        driver.quit();
//        driver.closeApp();
//        driver.launchApp();
    }
    
    @Test
    public void test_Add() {
        driver.findElement(By.id("com.gomo.calculator:id/input_num_1")).click();
        driver.findElement(By.id("com.gomo.calculator:id/display_op_add")).click();
        driver.findElement(By.id("com.gomo.calculator:id/input_num_2")).click();
        driver.findElement(By.id("com.gomo.calculator:id/display_eq")).click();
        System.out.println("test_Add success!!!");
        
    }
    
    @Test
    public void test_Mul() {
        driver.findElement(By.id("com.gomo.calculator:id/input_num_3")).click();
        driver.findElement(By.id("com.gomo.calculator:id/op_mul")).click();
        driver.findElement(By.id("com.gomo.calculator:id/input_num_4")).click();
        driver.findElement(By.id("com.gomo.calculator:id/display_eq")).click();
        System.out.println("test_Mul success!!!");
        
    }

}

 

python版请移步:用python和unittest编写app自动化测试用例

用java和junit编写app自动化测试用例

标签:pre   man   absolute   编写   stc   post   www.   orm   htm   

原文地址:https://www.cnblogs.com/mgzc-1508873480/p/8280540.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!