如何将Android滑动转换为Android触摸



我正在使用AppiumStudio工具在我创建的Android应用程序上运行一些测试。该工具自动生成了Java代码,我使用该代码在Eclipse上进行测试。但是,当我粘贴代码时,Java不识别driver.swipe((;即使完成了所有进口。这是工具生成的代码

package Appium;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.By;
import org.junit.*;
import java.net.URL;
import java.net.MalformedURLException;
public class Cadastro_base {
 private String reportDirectory = "reports";
 private String reportFormat = "xml";
 private String testName = "Cadastro_base";
 protected AndroidDriver<AndroidElement> driver = null;
 DesiredCapabilities dc = new DesiredCapabilities();
 @Before
 public void setUp() throws MalformedURLException {
  dc.setCapability("reportDirectory", reportDirectory);
  dc.setCapability("reportFormat", reportFormat);
  dc.setCapability("testName", testName);
  dc.setCapability(MobileCapabilityType.UDID, "5210ce98fa7eb4b3");
  driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), dc);
 }
 @Test
 public void testCadastro_base() {
  driver.findElement(By.xpath("//*[@id='emailView']")).sendKeys("teduspwrpbrasil@mailinator.com");
  driver.swipe(500, 596, 518, 478, 471);
  driver.swipe(434, 468, 471, 312, 417);
  driver.findElement(By.xpath("//*[@id='password_view']")).sendKeys("Smart2000");
  new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='confirm_password_view']")));
  driver.findElement(By.xpath("//*[@id='confirm_password_view']")).sendKeys("Smart2000");
  driver.swipe(734, 368, 737, 212, 813);
  driver.swipe(290, 987, 346, 571, 2003);
  driver.findElement(By.xpath("//*[@id='name_and_surname_view']")).sendKeys("TED USP");
  driver.swipe(409, 518, 493, 256, 1468);
  driver.findElement(By.xpath("//*[@id='cpfView']")).sendKeys("41801452865");
  driver.swipe(531, 465, 637, 175, 1724);
  driver.findElement(By.xpath("//*[@id='dobView']")).click();
  driver.findElement(By.xpath("//*[@text='OK']")).click();
  driver.swipe(650, 481, 756, 215, 1627);
  driver.findElement(By.xpath("//*[@id='phoneView']")).sendKeys("13982133161");
  driver.swipe(446, 800, 468, 675, 1359);
  driver.findElement(By.xpath("//*[@id='generView']")).click();
  driver.findElement(By.xpath("//*[@text='Feminino']")).click();
  driver.swipe(584, 712, 590, 609, 1013);
  driver.findElement(By.xpath("//*[@text='Cadastrar']")).click();
 }
 @After
 public void tearDown() {
     driver.quit();
 }
}

我的问题是:要正确运行测试,我需要在屏幕上的字段之间滑动。如何将命令驱动程序转换为触摸action或将执行操作移动操作的触摸action或工作命令?

您应该使用touchAction(https://appium.github.io/java-client/io/appium/java_client/touchaction.html(

使用Java客户端中的当前弃用方法6 Beta:

new TouchAction(driver).press(startX, startY).waitAction(Duration.ofMillis(duration)).moveTo(endX, endY).release().perform();

使用新方法:

new TouchAction(localdriver).press(point(startX, startY)).waitAction(waitOptions(Duration.ofMillis(duration)))
            .moveTo(point(endX, endY)).release().perform();

startx,starty,endx,endy是您的坐标持续时间是在毫秒中滑动的时间(try 1000(

最新更新