Search code examples
javaselenium-webdriverwebdriverbddqaf

How to use QAF Page Objects with QAF BDD2


For ex : I have created a test Page

public class HomePage extends WebDriverBaseTestPage<WebDriverTestPage>{

    @FindBy(locator = SLIDER_LOC)
    public QAFWebElement slider;
    @FindBy(locator = SEARCH_TEXTBOX_LOC)
    public QAFWebElement searchTextbox;
}

Now in step definition class, How to utilize this page I have tried below method but I am sure if it's the right way.

public class BDDSteps{
    
    static HomePage homepage = new HomePage();
    @QAFTestStep(description = "Step description")
    public void stepImplementation() {
        homepage.searchTextbox.sendKeys("asdfads");
        
    }
}

Solution

  • If you are creating a page class, it's better to create reusable methods specific to page inside page. In addition to that any method with @QAFTestStep will be available to use as bdd step. So you need to create additional step class only for the steps which are across the page. For example if search functionality is on home page then your homepage may include method like below

    @QAFTestStep(description = "Search for {term}")
    public void serachFor(String term){
       searchTextbox.sendKeys(term);
       searchTextbox.submit();
    }
    

    You can call this method in any other step or directly use in BDD as step. When using in other method/class, never create static variable for page class, instead create and initialize as and when required.