前几天在搭建appium的环境,苦于项目紧急,没有好好解决一个滑动问题,经过网络的资料搜索,现在将我学习的过程中踩过的坑记录下来。
问题:app安装实现,启动实现,但是没有滑动。原因是:滑动代码没有放在@test下,且休眠时间太短,后面的坐标给的太小。代码实现如下:
package com.glen.demo;
import io.appium.java_client.AppiumDriver;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.remote.CapabilityType;import org.openqa.selenium.remote.DesiredCapabilities; import java.io.File; import java.net.URL; public class ContactsTest { private static AppiumDriver 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, "DreamHouse.apk"); //设置自动化相关参数 DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); capabilities.setCapability("platformName", "Android"); capabilities.setCapability("deviceName", "DreamHouse"); //设置安卓系统版本 capabilities.setCapability("platformVersion", "4.2.2"); //设置apk路径 capabilities.setCapability("app", app.getAbsolutePath()); //设置app的主包名和主类名 capabilities.setCapability("appPackage", "com.uama.dreamhouseforlc"); capabilities.setCapability("appActivity", "com.uama.dreamhouseforlc.actvity.LaunchActivity"); //初始化 //driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); } @After public void tearDown() throws Exception { //driver.quit(); System.out.println("fww"); } @Test public void swipe() throws InterruptedException{ Thread.sleep(10000); int width = driver.manage().window().getSize().width; int height = driver.manage().window().getSize().height; driver.swipe(width *7/8, height/6, width/8, height/6, 500); System.out.println("滑动第一页"); driver.swipe(width *7/8, height/6, width/8, height/6, 500); Thread.sleep(5000); System.out.println("滑动第二页"); driver.swipe(width *7/8, height/6, width/8, height/6, 500); System.out.println("滑动第三页"); Thread.sleep(5000); Thread.sleep(5000); driver.findElement(By.name("立即启用")).clear(); } }eclipse结构jar如下:
关键点在于jar包,如有问题请发我邮箱:286090326@qq.com
或者加入杭州appium自动化测试专业群:239226112