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

JAVA Appium自动化测试入门

时间:2020-10-20 16:31:25      阅读:34      评论:0      收藏:0      [点我收藏+]

标签:相关   lease   user   mil   log   org   EAP   exce   device   

一、使用IntelliJ IDEA直接创建案例工程

  1、打开IntelliJ IDEA,【File】-->【New】-->【Project】

  2、选择【Java Project】-->【Next】

技术图片

 

  3、点击【Finish】

  4、点击工程 ,新建两个文件夹:apps和libs,目录结构如下:

技术图片

 

技术图片

 

 

 二、导入测试的类库

File -> Project Structure -> Modules -> 选中要添加build path的项目 -> Dependencies -> libs点击右边的小加号  -> 选择JARs or directories ->选择要添加的外部jar包。

技术图片

 

 

1、导入Selenum类库:http://docs.seleniumhq.org/download/

    1) selenium-server-standalone-2.44.0.jar

    2) selenium-java-2.44.0.zip

2、导入Appium类库:

    1) java-client-1.2.1.jar 

 三、代码

package com.chengyi.patienttest;

import io.appium.java_client.AppiumDriver;
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.concurrent.TimeUnit;


public class LoginTest {
private AppiumDriver driver;
@Before
public void setUp() throws Exception {
//设置apk路径
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot,"app");
File app = new File(appDir,"OrangerFamily.apk");

//设置自动化相关参数
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME,"");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("deviceName","HUAWEI VNS-AL00");
capabilities.setCapability("platformVersion","6.0");
capabilities.setCapability("app",app.getAbsolutePath());
capabilities.setCapability("appPackage","com.chengyifamily.patient");
capabilities.setCapability("appActivity","com.chengyifamily.patient.SplashActivity");

//初始化
driver = new AppiumDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
// AndroidDriver androidDriver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
}

@Test
public void loginTest() {
String account = "12345678907";
String pwd = "666666";
WebElement elAccount = driver.findElement(By.id("account_edit"));
elAccount.clear();
elAccount.sendKeys(account);
WebElement elPwd = driver.findElement(By.id("password_edit"));
elPwd.clear();
elPwd.sendKeys(pwd);
driver.findElement(By.id("login_button")).click();

//隐式等待
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}

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

 

参考:https://www.cnblogs.com/houchen/p/13408600.html

https://blog.csdn.net/jlminghui/article/details/41121479

边运行边记录,有问题后续改进~

JAVA Appium自动化测试入门

标签:相关   lease   user   mil   log   org   EAP   exce   device   

原文地址:https://www.cnblogs.com/fengye151/p/13840572.html

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