JAVA Appium自动化测试入门

当筵意气临九霄,星离雨散不终朝。这篇文章主要讲述JAVA Appium自动化测试入门相关的知识,希望能为你提供帮助。
java Appium自动化测试入门一、使用IntelliJ IDEA直接创建案例工程
1、打开IntelliJ IDEA,【File】--> 【New】--> 【Project】
2、选择【Java Project】--> 【Next】

JAVA Appium自动化测试入门

文章图片

 
 
 
3、点击【Finish】
4、点击工程 ,新建两个文件夹:apps和libs,目录结构如下:
JAVA Appium自动化测试入门

文章图片

 
 
   
JAVA Appium自动化测试入门

文章图片

 
 
  二、导入测试的类库
File -> Project Structure -> Modules -> 选中要添加build path的项目 -> Dependencies -> libs点击右边的小加号  -> 选择JARs or directories -> 选择要添加的外部jar包。
JAVA Appium自动化测试入门

文章图片

 
 
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.***.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自动化测试入门】边运行边记录,有问题后续改进~

    推荐阅读