appium-ios - 在 Appium iOS 自动化中使用时,PageFactory 似乎很慢
问题描述
我们正在使用 Appium 自动化一个 react-native iOS 应用程序。我们正在使用 PageFactory 设计模式。对于单击元素,这是正在使用的代码:
- 等待元素可见。
- 单击元素
public Boolean waitUntilVisible(WebElement element)
{
try {
wait.until(ExpectedConditions.visibilityOf(element));
return true;
}catch (Exception e)
{}
return false;
}
public boolean click(WebElement element)
{
//Click on the element and return true if successful and false if unsuccessful.
try
{
waitUntilVisible(element);
element.click();
} catch (Exception e) {}
return false;
}
整体执行似乎花费了太多时间。根据我的理解,waitUntilVisible 会等到元素的 isDisplayed() 变为真。
当我们使用 PageFactory 时,我假设元素识别发生了两次。
1. 在检查可见性之前首先识别元素。
2、点击前会再次识别相同的元素。
由于我们在很多领域都使用xpath,因此元素识别通常需要更长的时间。对于一个简单的点击,相同的元素被识别两次,这进一步增加了时间。
我想知道存储已识别元素的任何解决方案,以便它不会花时间再次识别它。
所以我修改了我的代码,如下所示:
public WebElement waitUntilVisible(WebElement element)
{
try {
return wait.until(ExpectedConditions.visibilityOf(element));
}catch (Exception e)
{}
return null;
}
public boolean click(WebElement element)
{
//Click on the element and return true if successful and false if unsuccessful.
try
{
WebElement remoteElement = waitUntilVisible(element);
remoteElement.click();
} catch (Exception e) {}
return false;
}
这种方法似乎不节省时间。
我有没有其他方法可以减少执行时间。
注意:我们使用 WebElement 而不是 IOSElement,以便在桌面自动化中使用的相同代码也可以在 IOS 自动化中使用。
解决方案
利用
mobileElement = driver.findElement(MobileBy.locator("locator"));
appiumDriverActions.moveToElement(mobileElement).click().perform();
appiumWait.until(ExpectedConditions.condition(Element/locator));
代替
mobileElement = driver.findElement(MobileBy.locator("locator"));
mobileElement.click();
在某些情况下,使用来自 iOS13 的新默认 VC,最好是 moveToElement 然后使用操作单击而不是element.click();
推荐阅读
- xml - 将 XML 数据导入 MS Access 运行时错误
- soap - 什么是 Servicenow SOAP API getkeys 通配符?
- c++ - 使用新值和值但没有明确数量的元素的数组初始化
- laravel - 在另一个工厂调用工厂
- javascript - 从请求中分派 redux 操作的正确方法
- java - 在delphi android应用程序中使用java .jar库的问题
- javascript - 无法从按钮操作 (JavaScript) 中获取表单字段
- c# - EF Core - 通过键值对的子集合过滤非常慢
- javascript - document.getElementsByName.length 在 IE 中返回 0
- javascript - 将 html 按钮和选择添加到 Highcharts