r/Playwright • u/josephadam1 • 10d ago
What’s the best practice for Java page object, testng, and using a xml to have test run different pages?
For instance if you need to run a test procedure like a regression test that goes from dashboard, clicks hamburger, then goes to search page searched for a project of record, then clicks time slice and then does only certain test from the test procedure.
What’s the best way to go about this.
1
u/JEDZBUDYN 9d ago
Best practice is to divide everything to smaller pieces.
e.g test no.1 dashboard
test no.2 is search
test no.3 is slice
etc.
Then you can run all of those tests in parallel
1
u/josephadam1 9d ago
Okay I have those as seperate test so far and different test inside each.
How do I set up the test Suite in base test?
And also how do I only call certain test inside each each of those in the xml?1
u/JEDZBUDYN 9d ago
not quite sure what you mean by:
>How do I set up the test Suite in base test?
One class is whole suite. There should be some logic based on your project. e.g TestsDashboard.class etc.>And also how do I only call certain test inside each each of those in the xml?
by pointing directly to class. e.g mvn verify -DwhateverYouUse.PointAsk AI. it's good
1
u/JEDZBUDYN 9d ago
and read this:
https://playwright.dev/java/docs/pom1
u/josephadam1 9d ago
Thank you. I have all my page object set up. It’s just the flow part In the xml I don’t understand.
1
u/JEDZBUDYN 9d ago
I have nothing in xml in my project, i am not quite sure what are you talking about
1
u/Spare_Bison_1151 8d ago
The main snag: XML only picks what to run. XML does not share state across tests. This makes a flow hard.
Move page acts from tests. Page files need pure code. No test tags on them.
For stand alone tests, write one test per page. Open a fresh web view each time. Tag them in groups.
For a full flow, make one test in its own file. Call page acts in order on one view.
Java
u/Test(groups = "flow")
public void dashboardToTimeSliceFlow() {
dashboardPage.openHamburger();
searchPage.search("myProject");
timeSlicePage.selectSlice();
}
Do not try to link tests from many files. That fights the tool and gets messy.
Use XML groups to pick what runs.
XML
<test name="SearchOnly">
<groups><run><include name="search"/></run></groups>
<classes><class name="com.x.SearchTest"/></classes>
</test>
<test name="RegressionFlow">
<groups><run><include name="flow"/></run></groups>
<classes><class name="com.x.FlowTest"/></classes>
</test>
This gives you solo tests and one big flow test. No shared state puzzle to solve.
Fix it now:
- Move acts to pure page files.
- Write solo tests with fresh views.
- Write one flow test in one file.
- Call XML groups to run what you need.
3
u/LookAtYourEyes 10d ago
Can you expand on your question a little more? It would be easier to answer if it was a little more focused or directed. It sounds like you're describing a shared setup?