serenity-bdd / serenity-core

Serenity BDD is a test automation library designed to make writing automated acceptance tests easier, and more fun.
http://serenity-bdd.info
Other
724 stars 518 forks source link

Pages.getPage not allow to pass additional parameter to pass to the PageObject when is instantiated #1868

Closed vayaszsolt closed 2 years ago

vayaszsolt commented 5 years ago

I am using the Pages.getPage in order to create the PageObject dynamically at run-time. The getPage method doesn't allow to pass parameters in order to pass these through the PageObject construct when is instantiated inside the Pages class. The most common use case where I need this change is to pass to the PageObject to SearchContext. So the PageObject will not search in the entire page to locate different element, it will search within the passed SearchContext from the constructor. A concrete example can be the following:

My workaround is to pass the SearchContext with a setter method after the Table page object is created by Pages.getPage method.

componentCreators.put(PageComponentType.TABLE, (pages, webElement, table) -> { Table table = pages.get(Table.class); table.setTableElement(webElement.findElement(By.xpath(".//table[@id=" +table + "]"))); return table; });

I would like to ask to extend this API in order to allow to pass additional parameters to the Pages.getPage method. Any thoughts about this request?

wakaleo commented 5 years ago

I’d be happy to review a Pull Request - you might be able to do something similar to what is done in the Instrumented class.

vayaszsolt commented 5 years ago

I will do a pull request by tomorrow ;)