这是我对应用于 Webdriver 的 PageObjects/Pagefactory 的尝试实现理解:
1. Create the following structure in eclipse
--> com.example.qa.pageobjects
--> LoginPage.java
Every class in this package has something like:
@FindBy(how = How.NAME, using = "logonName")
private WebElement logonNameField;
and the Methods, call Webelement, and call methods on them, like:
logonNameField.sendKeys("username");
Which are called from ScenrioTests.
--> HomePage.java (i go there after i login)
--> Page.java (abstract)
--> com.example.qa.setup
--> Browser.java
--> FirefoxBrowser.java (Code specific to FFox)
--> ChromeBrowser.java (Code Specific to Chrome)
--> com.example.qa.test
--> Scenario1234.java
--> Scenario2345.java
这些场景类实例化 PageObjects,并在其中调用方法,而浏览器设置仅在每次测试运行时调用一次。
现在的问题是:
- 我应该声明如下方法并调用 Pagefactory 吗?
public MyPage method() { 调用 Login() 等方法 return PageFactory.initElements(driver, MDNSLoginPage.class); }
或者,我应该从默认构造函数调用相同的 PageFactory
我的理解/实施是否正确?