具有属性的页面工厂

时间:2014-01-10 12:08:33

标签: selenium

我很困惑:(作为自动化框架如果我使用页面对象/工厂比我应该使用对象存储库我的意思是在selenium webdriver中的属性文件。 要么 我可以一次使用一个页面工厂或属性文件方法。

我正在使用此代码:

package Pages;
import java.util.Properties;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;

public class LoginPage {

final WebDriver driver;
static Properties prop = new Properties();

@FindBy(how = How.ID, using = "form-login-username")
private WebElement usernameEditbox;

@FindBy(how = How.NAME, using = "password")
private WebElement passwordEditbox;

@FindBy(how = How.NAME, using = "Log In")
private WebElement loginButton;

public LoginPage(WebDriver driver) {
this.driver = driver;
}

public void enterUsername(String login) {
usernameEditbox.clear();
usernameEditbox.sendKeys(login);
}

/*public void enterUsername(String login) {
    signInUsername.clear();
    usernameEditbox.sendKeys(login);
    }*/

public void enterPassword(String password) {
passwordEditbox.clear();
passwordEditbox.sendKeys(password);
}

public void clickSigninButton() {
loginButton.click();
}
public  LandingPage login(String login, String password) {
enterUsername(login);
enterPassword(password);
clickSigninButton();
return PageFactory.initElements(driver, LandingPage.class);
}
}

而不是定义@FindBy(how = How.ID,using =“form-login-username”) private WebElement usernameEditbox;我在同一个文件中如何从OR.properties ???

调用它

3 个答案:

答案 0 :(得分:0)

如果您遵循页面对象模式,那么理论上每个选择器只存在一次。因此,可以在页面对象类中对它们进行硬编码而不是创建某种存储库或外部资源。

答案 1 :(得分:0)

这是我使用Page Object Pattern向其他人发送的suggestion

属性文件与将元素分离到元素类文件并按照我在链接帖子中描述的方式初始化它们没有区别。

编辑:元素类的示例:

@FindBy(css = "button[id='Save']")
public static WebElement buttonSave;

@FindBy(css = "button[id='Cancel']")
public static WebElement buttonCancel;

等等。元素类只是为了保持你的元素。然后,您可以通过上面链接中显示的PageFactory.init示例使用这些元素。对于每个“页面”,最好具有单独的元素类。我希望这很清楚:))

答案 2 :(得分:0)

查看具有增强的页面对象工厂实现的测试自动化框架(TAF)。它允许您为Page Factory类使用定位器的属性文件。

您可以为工厂提及默认定位器文件,也可以通过提供外部文件在运行时覆盖它(如果需要)。

http://menonvarun.github.io/taf/

http://menonvarun.github.io/taf/pages/locator_in_taf.html