appium實現的一個簡單的測試案例

來源:互聯網
上載者:User

標籤:

前幾天在搭建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實現的一個簡單的測試案例

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.