標籤:
前幾天在搭建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如下:
650) this.width=650;" src="http://s1.51cto.com/wyfs02/M02/84/3C/wKioL1eI8CnQh5bbAAIC9-85VsA896.jpg-wh_500x0-wm_3-wmp_4-s_176203552.jpg" title="11.jpg" alt="wKioL1eI8CnQh5bbAAIC9-85VsA896.jpg-wh_50" />
關鍵點在於jar包,如有問題請發我郵箱:[email protected]
或者加入杭州appium自動化測試專業群:239226112
本文出自 “ghost” 部落格,請務必保留此出處http://fangwei009.blog.51cto.com/5234706/1826852
appium實現的一個簡單的測試案例