JAVA Appium自动化测试入门
Posted 枫叶
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAVA Appium自动化测试入门相关的知识,希望对你有一定的参考价值。
一、使用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、导入Appium类库:
三、代码
package com.***.test;
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,"***.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.***.***");
capabilities.setCapability("appActivity","com.***.***.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 = "123456789**";
String pwd = "666***";
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自动化测试入门的主要内容,如果未能解决你的问题,请参考以下文章