I am building three test cases with a page object that contains three ID locators. I am wondering if I can pass a locator to a single method for all three cases.
Page Object:
public class SomeClass {
@FindBy(how=How.CSS, using="label[for='yes']")
private WebElement yes;
@FindBy(how=How.CSS, using="label[for='maybe']")
private WebElement maybe;
@FindBy(how=How.CSS, using="label[for='no']")
private WebElement no;
public SomeClass(WebDriver driver) {
super(driver);
}
public SomeClass clicksButtons() {
*some locator*.click();
return new someClass(this.driver);
}
}
Test Case:
public class SomeTest {
@Test
public void willClickAButton() {
SomeClass someClass = new SomeClass(this.getDriver());
SomeClass.clicksButtons();
Assert.assertTrue(true);
}
I would like to pass a parameter (yes, maybe, or no) into the clicksButtons method so that I can reuse the method in the other two test cases without have to hardcode it. I've searched Google and couldn't find a clear answer.
I found the answer in Selenium Testing Tools Cookbook 2nd edition.