终于有意识的把代码块封装起来了,首次给自个赞个:)
点击指定控件的指定位置,要用到枚举~~
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); } } }