eclipse - 如何将下面提到的代码修复到 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();
}
}
我希望每当我执行上面的代码时屏幕应该向下滚动。
解决方案
你可以试试这段代码driver.executeScript("seetest:client.swipe(\"Down\", 1000, 500)");
。此代码将从偏移量 1000 向下滑动 500 毫秒。访问这里了解更多信息
推荐阅读
- python - python中的复杂循环
- ruby - 为什么 Set#map 返回一个 Array 而不是另一个 Set?
- python - 将数据框转换为字典,不包括 ID
- node.js - 如何检查节点进程线程数
- graphviz - 带有自循环的graphviz状态机
- javascript - 在节点 js 中对 axios 请求的 Jest 测试
- javascript - 从 SharePoint 列表填充字段的最佳方式是什么?
- wordpress - 使用返回时 Nginx 位置指令不起作用
- python - 如何从键值匹配中找到键值?
- azure - AzDO 应用程序注册 appRoles 禁用问题