首页 > 解决方案 > 如何将下面提到的代码修复到 Eclipse 中以滚动移动应用程序?

问题描述

我正在编写脚本来上下滚动移动应用程序,但是带有 testng 框架的 Appium studio 代码在 Eclipse 中不起作用。

我是这种脚本和测试的新手,请帮助修复它。

我尝试了 Appium 工作室代码。但它需要修复才能运行脚本。

//package <set your test package>;
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.TouchAction;
import java.time.Duration;
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.testng.annotations.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.logging.Level;

public class scrollandsave {
    private String reportDirectory = "reports";
    private String reportFormat = "xml";
    private String testName = "scrollandsave";
    protected AndroidDriver<AndroidElement> driver = null;

    DesiredCapabilities dc = new DesiredCapabilities();

    @BeforeMethod
    public void setUp() throws MalformedURLException {
        dc.setCapability("reportDirectory", reportDirectory);
        dc.setCapability("reportFormat", reportFormat);
        dc.setCapability("testName", testName);
        dc.setCapability(MobileCapabilityType.UDID, "330033acecf394bd");
        driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), dc);
        driver.setLogLevel(Level.INFO);
    }

    @Test
    public void testscrollandsave() {
        new TouchAction(driver).press(480, 1348).waitAction(Duration.ofMillis(624)).moveTo(338, 312).release().perform();
        new TouchAction(driver).press(591, 1376).waitAction(Duration.ofMillis(592)).moveTo(421, 138).release().perform();
        driver.findElement(By.xpath("(//*[@id='listAllImgByCat']/*/*/*/*[@id='icPlayVideo'])[1]")).click();
        new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@text='EDIT']")));
        driver.findElement(By.xpath("//*[@text='EDIT']")).click();
        new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@text='SAVE']")));
        driver.findElement(By.xpath("//*[@text='SAVE']")).click();
        driver.findElement(By.xpath("//*[@text='Export as GIF']")).click();
        driver.findElement(By.xpath("//*[@id='btnHome']")).click();
    }

    @AfterMethod
    public void tearDown() {
        driver.quit();
    }
}

我希望每当我执行上面的代码时屏幕应该向下滚动。

标签: eclipsescrolltestngappium-android

解决方案


你可以试试这段代码driver.executeScript("seetest:client.swipe(\"Down\", 1000, 500)"); 。此代码将从偏移量 1000 向下滑动 500 毫秒。访问这里了解更多信息


推荐阅读