Set up the testng.xml file to execute tests in a sequential order effortlessly, without the need to

Currently, I am using selenium to automate tests for a point-of-sale application that requires communication with external devices. However, due to the limitations of an external program managing this interaction, only one browser session can be open at a time to avoid confusion.

In my testng.xml file, I have been structuring my tests as follows:

<suite name="Test Suite" verbose="10" preserve-order="True">
  <test name="Item Entry -- Quantity Required -- Basic" annotations="JDK">
    <parameter name = "filepath" value = "C:\Java Projects\Gravity\config\US\" />
    <classes>
      <class name="tests.itementry.quantityrequired.BasicPath"/>
    </classes>
  </test>
    <test name = "Item Entry -- Quantity Required -- Cancel">
        <classes>
            <class name = "tests.itementry.quantityrequired.Cancel" />
        </classes>
    </test>
</suite>

I have tried specifying the package instead of the class, but it resulted in the tests running in parallel with multiple browsers open simultaneously. While combining tests into one class is an option, I prefer to keep each scenario as its own class.

If you have any advice on configuring the testng.xml file or organizing test scenarios within TestNG tests, I would greatly appreciate your input.

Answer №1

Testng typically runs tests sequentially by default unless specified otherwise in the parallel attribute of the suite. If you're experiencing issues, try defining the package to resolve them. You can also set parallel = false in your suite declaration to investigate why your tests are running concurrently. For more information, you can refer to this resource. Additionally, double-check your code to ensure that teardown is being executed properly.

Looking at the dtd of the XML file...

!ATTLIST suite
    name CDATA #REQUIRED
    junit (true | false) "false"
    verbose CDATA #IMPLIED
    parallel (false | methods | tests | classes | instances) "false"

It's also worth noting that grouping all tests in a single class may not be the most optimal approach.

Answer №2

I encountered a similar issue where using parallel="false" for both resulted in multiple browsers being launched at the same time. To solve this problem, I decided to annotate all my classes as @Test and assigned them to a specific group. By including the dependsOnGroups attribute within the @Test annotation, you can define the order of execution and ensure that each test runs sequentially by setting alwaysRun="true". Make sure to include the package and specify all groups in the testNG xml file.

<test name="My suite">   
 <groups>
    <dependencies>
      <group name="c" depends-on="a  b" />
      <group name="z" depends-on="c" />
    </dependencies>  
 </groups> 
</test>

Hopefully this solution will work for you.

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

Using Selenium to interact with hidden elements, such as clicking on an anchor tag within a ul tag that is styled with "display: none;"

<div id="menu1Div" style="float: right;"> <ul id="menu1" class="ui-menu ui-widget ui-widget-content ui-corner-all ui-menu-icons" role="menu" tabindex="0" aria-activedescendant="ui-id-2"> <li class="ui-menu-item" role="presentation"> &l ...

Testing the integration between Oracle and Selenium

For integration testing, I am looking to test some connections between a web application and its Oracle DB data store. There is a specific table where I want to verify the stored values. I am contemplating the most effective method to accomplish this task ...

Beautiful Soup failing to retrieve image URL with scraper

My web scraper seems to be inconsistent in capturing the image URL from the webpage. Sometimes it fetches the URL correctly, but most times it fails to do so. When it doesn't capture the URL, my CSV file shows: data: I'm having trouble identifyi ...

Having trouble retrieving JSON value in JSP using Spring MVC, as it always returns 0

Seeking assistance with JSON string retrieval in JSP after adding it to the modelAndView. Upon debugging, I discovered that it is indeed being added to the modelAndView instance. Here's the snippet of code: Controller: modelAndView.addObject("json ...

Enhancing the protection against JSON injection in Java

I have been trying to sanitize JSON data using the code below, but I am still encountering JSON injection issues when scanning with Fortify. Can someone please assist me in identifying the problem? I have looked for similar questions, but none of the solut ...

Using Selenium WebDriver version 2.32.1 in C#, ensure that you wait for the loading div to be hidden after the page has finished loading

Apologies if this question has already been addressed, but I was unable to locate it. Please forgive my lack of knowledge as I am still new to WebDriver. Upon the initial page load, a LOADING DIV is displayed until all data is loaded. How can I ensure th ...

Having trouble resolving issues with Selenium's Java WebDriver and ChromeDriver?

Hello! I'm encountering an error even after adding all the necessary jar files to the classpath. I have an interview coming up on Monday, so I really need to resolve this issue as soon as possible. My Java version is 21 and Chrome version is 122. Can ...

Looking for a solution on how to Resolve MixIn for non-static Inner Class with ObjectMapper in Java 6

Encountering a problem with ObjectMapper for a non-static inner class is causing me some trouble. I've attempted to create a MixIn to resolve the issue, but so far have not been successful. Below you will find my class (which unfortunately cannot be a ...

Having difficulty clicking on an element even though it appears to be present on the webpage

Having trouble clicking on an element even though the Web driver can locate it. I have already applied an implicit wait. I also tried using an explicit wait, but when using an explicit wait, I receive an error saying that the element is not attached to th ...

When using Selenium, the moveToElement method does not properly click on the desired target in Internet Explorer but works correctly

While using Selenium to navigate a menu, I have encountered an issue specifically with IE where the submenu item becomes inaccessible as it ends up clicking on the menu below my target. This method works perfectly in Chrome but not in IE. // Actions not s ...

Testing the functionality of Webdriver by simulating events and notifications within the test environment

Let me paint the picture: We execute webdriver tests using Python to test a robust-client application written in Javascript. In the event of an error (typically when the backend fails to respond or responds with FAILURE), the application displays a "We&ap ...

Tips for managing a dialog box that only has a close button in Selenium using Java

Currently, I am in the process of automating a website that has a "submit" button triggering a dialog box. Within this dialog box, I need to click on an "update" button. However, my code does not proceed to open the dialog box after clicking the "submit" ...

Encountering a connection error while running a Node.js Selenium test case on Chrome. The specific error message received is: "Error: ECONNREFUSED - Connection refused to 127.0

When attempting to run a test case on a Selenium Node.js server, an error was encountered: Error: ECONNREFUSED connect ECONNREFUSED. The test case script is as follows: var assert = require('assert'), test = require('selenium-webdriver ...

Finding elements on a webpage using Xpath with a dynamic variable

I've been trying to solve this issue for a while now, but I just can't seem to figure it out. My goal is to click on an email within my Yahoo account based on its subject. When I hardcode the value in the XPath locator, it works fine for the firs ...

Steps for initiating the application under test for each test case without the need to generate a new session with WinAppDriver

Currently working on automating a Windows application using Java with WinAppDriver. I have set up three test cases, each requiring the application to be launched. Below is the code snippet I am using to initialize the driver and launch the application: D ...

Is there a more efficient method for showcasing model objects in Thymeleaf rather than utilizing a form?

I've been exploring Spring Boot, Thymeleaf, and frontend development in general. Currently, I have a frontend table that displays a list of objects from the backend, along with a form to allow users to view properties of each item in the list. Howeve ...

What is the best method to take a high-quality screenshot of a website?

Looking to capture high-resolution screenshots of websites for text recognition or saving high-quality images? I experimented with Python 2.7 and tried the following code using the website as an example. from selenium import webdriver import time driver ...

Are there any techniques to control <script> elements with the Selenium Web driver in Java?

In the process of developing a web application, I have implemented a query form for users to input search criteria. Once the user fills out the query form and performs a search, a table is dynamically loaded below the search form. Interestingly, this tab ...

Change a JSON String into an ArrayList to use in a Spinner

Received a JSON string from the server with the following values: {"server_response":[{"violation":"Driving with No Helmet"},{"violation":"Try"}]} Attempting to convert this JSON string into a String Array or ArrayList containing Driving with no Helmet a ...

Issue encountered: Selenium requires the browser binary location to be specified when running on a Windows hosting

Here is a sample of the work I am doing: I am trying to retrieve text from Google and display it on a homepage using ASP.NET. Additionally, I am testing the functionality of Selenium on a Windows host. The objective is to run Selenium on a Windows hostin ...