The order in which the test cases are executed by TestNG has been altered with the latest update to version 6.14

After updating the TestNG version to 6.14.2, I started encountering issues with running sequences that were not present when using version 6.8.8. Despite trying various solutions such as changing priorities, the tests did not run as expected. For more details, please refer to the source code.

class1.java


    package TestNG;

    import org.testng.annotations.AfterClass;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.Test;
    public class class1
    {
    @BeforeClass
    public void beforeclass1()
    {
        System.out.println("before_class1");

    }

    @AfterClass
    public void afterclass1()
    {
        System.out.println("after_class1");

    }

    @Test(priority = 0)
    public void class1_method1()
    {
        System.out.println("class1_method1");
    }

    @Test(priority = 1)
    public void class1_method2()
    {
        System.out.println("class1_method2");

    }

    @Test(priority = 2)
    public void class1_method3()
    {
        System.out.println("class1_method3");

    }
}

class2.java

package TestNG;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class class2
{

    @BeforeClass
    public void beforeclass1()
    {
        System.out.println("before_class2");

    }

    @AfterClass
    public void afterclass1()
    {
        System.out.println("after_class2");

    }

    @Test(priority = 0)
    public void class2_method1()
    {
        System.out.println("class2_method1");
    }

    @Test(priority = 1)
    public void class2_method2()
    {
        System.out.println("class2_method2");

    }

    @Test(priority = 2)
    public void class2_method3()
    {
        System.out.println("class2_method3");

    }
}

class3.java

package TestNG;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class class3
{

    @BeforeClass
    public void beforeclass1()
    {
        System.out.println("before_class3");

    }

    @AfterClass
    public void afterclass1()
    {
        System.out.println("after_class3");

    }

    @Test(priority = 0)
    public void class3_method1()
    {
        System.out.println("class3_method1");
    }

    @Test(priority = 1)
    public void class3_method2()
    {
        System.out.println("class3_method2");

    }

    @Test(priority = 2)
    public void class3_method3()
    {
        System.out.println("class3_method3");

    }
}

testng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="Test" >
    <classes>
      <class name="TestNG.class1">
        <methods>
          <include name="class1_method1"/>
          <include name="class1_method2"/>
          <include name="class1_method3"/>
          <include name="beforeclass1"></include>
          <include name="after_class1"></include>
          </methods>
      </class>
      <class name="TestNG.class2">
       <methods>
          <include name="class2_method1"/>
          <include name="class2_method2"/>
          <include name="class2_method3"/>
          <include name="beforeclass2"></include>
          <include name="after_class2"></include>         
          </methods>
      </class>
      <class name="TestNG.class3">
          <methods>
          <include name="class3_method1"/>
          <include name="class3_method2"/>
          <include name="class3_method3"/>
          <include name="beforeclass3"></include>
          <include name="after_class3"></include>
          </methods>
       </class>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Actual Output after running testng.xml using testng(6.14.2):

before_class1

class1_method1

before_class2

class2_method1

before_class3

class3_method1

class1_method2

class2_method2

class3_method2

class1_method3

after_class1

class2_method3

after_class2

class3_method3

after_class3

Expected Output :(Working fine with testng 6.8.8 but not working in testng 6.14.2)

before_class1

class1_method1

class1_method2

class1_method3

after_class1

before_class2

class2_method1

class2_method2

class2_method3

after_class2

before_class3

class3_method1

class3_method2

class3_method3

after_class3

Answer №1

Until 6.9.10, this configuration will remain effective; afterwards, priority becomes global for a test tag.

To ensure sequential execution within a class, utilize dependsOnMethods or dependsOnGroups. If you want a method to run even if the dependent method fails, add alwaysRun = true.

Alternatively, consider separating classes into distinct test tags for better organization.

It is unclear whether including before and after methods in the methods tag is necessary.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to find out which JavaScript file the AJAX function is using to send a request to a Java servlet?

I am facing an issue with two js files, one.js and two.js. Both of these files make ajax requests to the same Java servlet class(AppController.java). Here is the code from one.js: function addOne(){ var formData = $('#form1').serialize(); ...

Testing a cucumber scenario by comparing the redirect URL with a different URL

Currently, I am working on writing Cucumber tests for my project. One issue I have encountered is that when clicking a certain button in my code, it redirects to another page with a fixed URL. How can I retrieve the current URL within the Cucumber test? I ...

Unable to locate and interact with a concealed item in a dropdown menu using Selenium WebDriver

Snippet: <select class="select2 ddl visible select2-hidden-accessible" data-allow-clear="true" id="Step1Model_CampaignAdditionalDataTypeId" multiple="" name="Step1Model.CampaignAdditionalDataTypeId" tabindex="-1" aria-hidden="true"> <option value ...

Selenium in C#: Timeout issue with SendKeys and Error thrown by JS Executor

Attempting to insert the large amount of data into the "Textarea1" control, I have tried two different methods. The first method successfully inserts the data but occasionally throws a timeout error, while the second method results in a JavaScript error. A ...

Steps for creating an HTML report using Intern JS

Our team relies on intern JS for automating functional tests, however we are facing difficulty in generating an html report. I attempted to use locvhtml as suggested by the Intern documentation (https://theintern.github.io/intern/#reporter-lcov), but unfo ...

Is there a way to access an Excel file with JavaScript without relying on the ActiveX control?

Is there a way to access an Excel document using JavaScript code without relying on an ActiveX control object such as shown below: var myApp = new ActiveXObject("Excel.Application"); myApp.workbooks.open("test.xls"); ...

Guide on setting an attribute value with JavaScriptExecutor in Selenium WebDriver

I am attempting to set an attribute value for all instances of the same type of <img> tag on My website, for example: <img src="images/temp/advertisement.png"> and I want to set style="display: none" so that I can hide them. I have tried the ...

Is there a simple method to refresh a JSP or Spring MVC page using AJAX?

I'm tackling a seemingly basic question in Java web development here, but I could use some guidance. How can I refresh data on a JSP page? I understand the fundamentals (utilize jQuery for AJAX, Spring MVC for the "Controller" & handle data reque ...

Interacting with shadow DOM elements using Selenium's JavaScriptExecutor in Polymer applications

Having trouble accessing the 'shop now' button in the Men's Outerwear section of the website with the given code on Chrome Browser (V51)'s JavaScript console: document.querySelector('shop-app').shadowRoot.querySelector ...

What is the best way to duplicate an entire webpage with all its content intact?

Is it possible to copy an entire page including images and CSS using Selenium? Traditional methods like ctrl + a or dragging the mouse over the page do not seem to work. How can this be achieved with Selenium without requiring an element to interact with? ...

AngularJS 500 server error

In my current project, I am developing a straightforward angularjs - J2EE application that fetches data from a mysql server and then displays it on an HTML page. The angular function is triggered on form submission as shown below: <div id="register_for ...

Understanding Java and JavaScript variables within a JSP webpage

I am currently working on populating a pie chart from Google with data fetched from my database. Although I have successfully retrieved the desired results in my result set, I am facing challenges in converting my Java variables into JavaScript variables ...

Combining a JavaScript NPM project with Spring Boot Integration

Recently, I built a frontend application in React.js using NPM and utilized IntelliJ IDEA as my IDE for development. Additionally, I have set up a backend system using Spring Boot, which was also developed in IntelliJ IDEA separately. My current goal is t ...

Mastering Protractor's end-to-end control flow and managing time outs

When testing an angular app using protractor, I encountered a strange issue recently. Every now and then, or since a recent update, protractor seems to stall or slow down significantly. After investigating the problem, I discovered that a simple someEleme ...

The AJAX response consistently returns a 405 status code

I am experiencing an issue with an AJAX post request. $.ajax({ type: "POST", contentType: "application/json", url: "/rating/save", data: JSON.stringify(rating), dataType: "json", mimeType: "application/json" ...

waiting for elements in Nightwatch.js using FluentWait

I am seeking assistance on implementing FluentWait using nightwatch.js. How can I achieve this? Within my project, I have a global.js file that includes: waitForConditionPollInterval : 300, waitForConditionTimeout : 5000, However, it seems like this ...

Analyzing Dynamic Content

Currently, I am engaged in content parsing and have successfully executed a sample program. To demonstrate, I have utilized a mock link which you can access below: Alternatively, you can click on this link: Click Here In the provided link, I have parsed ...

Encountering an Issue Executing Selenium Test on jQuery v2.0.2 and Play Framework

While I may not be a selenium expert, it seems that I've stumbled upon a bug when trying to utilize jQuery v2.0.2 with my Play Framework 2.2.1 application instead of the default jQuery v.1.9.0. Whenever I run "play test", I encounter the following err ...

Tips for effectively managing dynamic xpaths

When conducting a search operation, I am required to select the text that is returned as a result. Each search will produce different xpaths. Below are examples of various xpaths returned during a search: .//*[@id='messageBoxForm']/div/div[1]/di ...

The issue of Access-Control-Allow-Origin not functioning properly when using Ajax for a POST request

I am encountering an issue with the header "Access-control-allow-origin" when making a request using the following code: <script type='text/javascript'> function save() { $.ajax( { type: 'POST', ur ...