xli
xli

Reputation: 1308

Multiple ways of performing an action with the page object pattern

When implementing the page object pattern, the recommendation that I've seen is that actions should be high-level, instead of individual UI actions:

For example:

page.search(query)

Rather than:

page.enterSearchBarText(query)
page.clickSearchButton()

However, the search should also execute when the user hits Enter instead of clicking the search button.

So search could also be:

page.enterSearchBarText(query)
page.pressEnter()

If I want to cover both in my tests, what is a conventional way of implementing this? I thought perhaps

search(query, method)

where method could be one of enum { SearchButton, Enter }

Upvotes: 1

Views: 42

Answers (1)

NarendraR
NarendraR

Reputation: 7708

You can create 2 methods in that class

public void dataSearchBySearchButton(String query){

page.enterSearchBarText(query);
page.clickSearchButton();

}

And

public void dataSearchByEnterKey(String query){


page.enterSearchBarText(query);
page.pressEnter();

}

and you can call the relevant method which require in your test

Upvotes: 1

Related Questions