2014-01-10 63 views
0

即时通讯困惑:(作为自动化框架,如果我使用页面对象/工厂比我应该使用对象存储库我的意思是属性文件在硒webdriver 或 我可以一次使用一个页面工厂或属性文件的方法使用此代码页面工厂属性

IM:

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.ID,采用= “表单登录-用户名”) 私人WebElement usernameEditbox;在相同的文件如何。我可以从OR.properties调用它???

回答

0

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

0

这是suggestion我给其他人使用页面对象模式。

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

编辑:一个元素类的实例:

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

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

等。元素类只是为了坚持你的元素。然后通过上面链接中显示的PageFactory.init示例使用这些元素。对每个“页面”最好有一个单独的元素类。我希望这已经足够清晰了:)

+0

嘿感谢很多ü可以分享MyHomePageElements.class的脚本,按您的建议链接。 – user3181664

+0

编辑我的帖子向你展示一个元素类的例子。 – NaviSaysListen