• appim自动化--点击指定控件的指定位置


    终于有意识的把代码块封装起来了,首次给自个赞个:)

    点击指定控件的指定位置,要用到枚举~~

    package appiumtest;
    import java.net.URL;
    
    import io.appium.java_client.MobileElement;
    import io.appium.*;
    import io.appium.java_client.AppiumDriver;
    import io.appium.java_client.android.AndroidDriver;
    
    import org.apache.bcel.generic.SWITCH;
    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import org.openqa.selenium.*;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.remote.DesiredCapabilities;
    
    import com.robotium.solo.*;
    
    public class test {
        private AppiumDriver driver;
        private Solo solo;
        @Before
        public void setUp() throws Exception
        {
            DesiredCapabilities capabilities=new DesiredCapabilities();
            capabilities.setCapability("deviceName", "Android Emulator");
            capabilities.setCapability("platformName", "Android");
            capabilities.setCapability("platformVersion", "4.4");
            capabilities.setCapability("appPackage", "com.android.contacts");
            capabilities.setCapability("appActivity", ".activities.AuroraPeopleActivity");
            driver=new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    
        }
        
        @After
        public void tearDown() throws Exception
        {
            driver.quit();
    
        }
        
        @Test
        public void addcontacts()throws Exception
        {
            clickControl(driver.findElementByName("彭洪"),Location.UPLEFT );
            
        }
        
        
        public enum Location{
            UPLEFT,LOWLEFT,UPRIGHT,LOWRIGHT,CENTRE
        }
        
        public void clickControl(WebElement webElement,Location location) throws InterruptedException
        {
            int h=webElement.getSize().height;
            int w=webElement.getSize().width;
            int x=webElement.getLocation().x;
            int y=webElement.getLocation().y;
            System.out.println(h);
            System.out.println(w);
            System.out.println(x);
            System.out.println(y);
        
            switch(location)
            {
            case LOWLEFT:
                driver.tap(1,x,y+h,100);
                Thread.sleep(2000);
            case UPLEFT:
                driver.tap(1, x, y, 100);
                Thread.sleep(2000);
            case UPRIGHT:
                driver.tap(1,x+w,y,100);
                Thread.sleep(2000);
            case LOWRIGHT:
                driver.tap(1,x+w,y+h,100);
                Thread.sleep(2000);
            case CENTRE:
                driver.tap(1, x+w/2, y+h/2,100);
                Thread.sleep(2000);
                
            }
            }
    
    }
  • 相关阅读:
    Codeforces Round #353 (Div. 2)
    Codeforces Round #304 (Div. 2)
    Codeforces Round #250 (Div. 2)D
    Codeforces Round #368 (Div. 2)
    hdu4348区间更新的主席树+标记永久化
    poj3468线段树标记永久化
    Educational Codeforces Round 35 (Rated for Div. 2)
    一维数组取一部分
    序列化数组。
    禅道常识
  • 原文地址:https://www.cnblogs.com/penghong2014/p/4368098.html
Copyright © 2020-2023  润新知