gpt4 book ai didi

selenium - Selenium FindBy 是否在 PageObject 类中实例化 WebElement 实例?

转载 作者:行者123 更新时间:2023-12-05 03:11:58 24 4
gpt4 key购买 nike

Selenium FindBy 注解是否实际实例化了 WebElement 实例,如果是,对使用它们的框架有何含义?

我在我的页面对象中所做的现在看起来像这样。我所有的测试框架方法都将 By 定位器作为参数(而不是 WebElement 实例)。

//fields in the page
public static final By SEARCH_BOX = By.id("input-what");

我的问题是,使用 FindBy 是否会在类实例化时实例化 WebElement 实例?如果是这样,那么我怀疑我的框架方法需要采用 WebElement 实例。这是否正确,在框架中哪个更受欢迎:通过定位器参数还是 WebElement 参数?

@FindBy(id = "input-what")
public WebElement SEARCH_BOX_ELEMENT;

我知道我在期待一个有点自以为是的答案。如果你给我一个超链接引用你的信仰,那么我认为这将是一个合理的答案。我认为这具有深远的影响:例如,Selenide 中的方法框架,不要在其参数中采用 WebElement 实例,因此使用 FindBy 注释的 PageObjects 将无法将这些元素传递给 Selenide 方法?

最佳答案

如果我明白你在问什么,你的答案就在 documentation 的第一行:

In order to use the PageFactory, first declare some fields on a PageObject that are WebElements or List<WebElement>...

或者可能是同一文档的结尾:

WebElements are evaluated lazily. That is, if you never use a WebElement field in a PageObject, there will never be a call to "findElement" for it.

编辑:要完成答案:PageObject是一种收集有关您的网络应用程序信息的编码风格。为了使这种编码风格不那么冗长,Selenium 提供了一个 PageFactory ,它使用 @FindBy在您的 PageObject 类中装饰 WebElements 的注释。

关于selenium - Selenium FindBy 是否在 PageObject 类中实例化 WebElement 实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35490801/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com