【问题标题】:PageFactory seems to be slow when used in Appium iOS automation在 Appium iOS 自动化中使用时,PageFactory 似乎很慢
【发布时间】:2019-07-31 04:40:45
【问题描述】:

我们正在使用 Appium 自动化一个 react-native iOS 应用程序。我们正在使用 PageFactory 设计模式。点击一个元素,这是正在使用的代码:

  1. 等待元素可见。
  2. 点击元素

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 自动化中使用。

【问题讨论】:

    标签: appium-ios page-factory


    【解决方案1】:

    使用

    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();

    更多详情,https://medium.com/@ayman.ibrahim.mansour/appiums-best-way-to-deal-with-the-new-view-controller-presentation-in-ios-13-6d801fcc3cb

    【讨论】:

    • 我的问题不是关于使用动作点击的问题。关于PageFactory和By变量的使用比较。
    • 这就是重点,真正消耗最多时间的不是pageFactory行为,而是点击命令行为。实际上 pageFactory 行为更可取,以保持 TC 通过并避免 Elements Stale
    • 在此方法中 public boolean click(WebElement element) 而不是使用 element.click(); 尝试使用 actions.moveToElement(element).click().perform(); 在 iOS 13 及更高版本的情况下,这应该会使您的自动化更快。您所做的更改仅将 pageFactory 替换为纯硒,这不会导致时间减少,因为 pageFactory 无论如何都不会消耗那么多时间,消耗时间的是 element.click() 本身
    猜你喜欢
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 1970-01-01
    • 2016-09-08
    • 1970-01-01
    • 2015-02-16
    • 1970-01-01
    • 2016-07-29
    相关资源
    最近更新 更多