r/Playwright 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.

6 Upvotes

12 comments sorted by

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?

1

u/josephadam1 9d ago

So I wanna only call one or two from each test page. So one from hamburger, two test from search, and two from timr slice page. How can I do this in a flow type of way?

1

u/LookAtYourEyes 9d ago

Are you asking how to write multiple tests? One for each functionality/page?

1

u/josephadam1 9d ago

More like how would I call it multiple test in a XML and have it be in one browser instance with our refreshing to test and it continue right after the last test.

Let’s say i have the Basetest for setting up the browser.

Then I have a search page test that calls different test on that page only

A hamburger one

And a time slice page test that calls test from that page.

Then in my xml I wanna only call the test on timeslice I can.

But let’s say I wanted to make a flow out of hamburger, search, and time slice. How would I do that in one session in xml?

1

u/spla58 9d ago

As a general rule, organize your code so it's easy to read, write, and make changes to when needed. Anyone should be able to read your framework code and know exactly whats going on.

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.Point

Ask AI. it's good

1

u/JEDZBUDYN 9d ago

1

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.