1

testng.xml

Here i've mentioned my test methods are parallel, my intention is to run the test methods in parallel but each tests should run sequentially one after the other like, After LoginPage-tests runs the testmethods in parallel, after that the dashboard testcase should run the testMethods in parallel.

how can i achieve this behaviour?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="MyStartupEquity AdminLogin suite" parallel="false">

    <listeners>
        <listener class-name="Listeners.ExtentListeners">
        </listener>
    </listeners>

    <test thread-count="5" name="LoginPage - Tests" parallel="methods">
        <parameter name="browser" value="chrome"></parameter>
        <classes>
            <class name="TestCases.loginTest" >
            <methods>
                <include name="verifyLoginPageTitle" />
                <include name="verifyInvalidCredentials" />
                <include name="logging_In" />
            </methods>
        </class>
        </classes>
    </test> 

     <test thread-count="5" name="DashboardPage - Tests" parallel="methods">
        <parameter name="browser" value="chrome"></parameter>
        <classes>
            <class name="TestCases.dashboardTest" >
            <methods>
                <include name="vestingTableCheck" />
                <include name="dashboardCheck" />
            </methods>
        </class>
        </classes>
    </test> 

</suite> 
  • 1
    I suspect the only way to do this would be to create a customer test runner. On the other hand it strikes me you are violating good test practise, being having a group of tests depend on the out come/side effect of a preceding test. You really should build tests that are isolated from one another, this will not only allow them to run in parallel but also in any order. – Gavin Dec 16 '19 at 09:06
  • Every question about Test Dependencies has a developer saying that it's a bad practice and that you shouldn't do it. No, it's not a bad practice. The feature in TestNG exists for a reason. This is not JUnit. It happens that they know little more than just Unit Testing in where tests do have to be independent from each other. For E2E testing and sometimes regression, sometimes (I would even say usually) dependencies are necessary to save execution time and get more clear reports. – Rodrigo Vaamonde Dec 16 '19 at 09:53
  • Anyway, my answer here my help you with this: https://stackoverflow.com/questions/58749157/beforeclass-methods-get-exexcuted-in-same-thread-if-we-put-parallel-tests-in/58752471#58752471 – Rodrigo Vaamonde Dec 16 '19 at 09:53
  • @Gavin can u suggest a better way for executing in parallel, each test cases has separate testMethods, so if i add parallel="methods" in suite level, 10-15 browser instances will be created for all the testmethods in all tests.. so only i thought it would be better to execute testmethods parallely and tests sequentially! can u suggest a better practice ? thanks in advance – Rajesh Ganessan Dec 16 '19 at 16:40
  • @RodrigoVaamonde thanks for the suggestion... – Rajesh Ganessan Dec 16 '19 at 16:49
  • For me an End to End (E2E) test should encompass a whole feature/flow/path through the application. Yes this means you will repeat for example login on each flow, but this makes the test easier to reason about as you know the test is full and complete and that you have no dependencies on other tests. Sometimes this means you might need to create say users for your test. But this is just one way, and what I see as strengths others see as weaknesses. A good book to read on around this is "Growing Object Orientated Systems Guided by Tests" – Gavin Dec 17 '19 at 08:48

0 Answers0