How to define dependencies between groups in TestNG XML file
File: KWTestNG.java
package tests;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class KWTestNG 
{
    WebDriver driver;
    @Test(groups = {"OpenBrowserNavigate"})
    public void OpenBrowserNavigate()
    {
        System.setProperty("webdriver.chrome.driver", "/home/kodingwindow/drivers/chromedriver");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.navigate().to("http://newtours.demoaut.com");
    }
    @Test(groups = {"LoginLogout"})
    public void LoginLogout()
    {
        driver.findElement(By.name("userName")).sendKeys("mercury");
        driver.findElement(By.name("password")).sendKeys("mercury");
        driver.findElement(By.name("login")).click();
        driver.findElement(By.linkText("SIGN-OFF")).click();
        driver.close();
    }
}
File: testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Selenium Project">
    <test name="Login">
        <groups>
            <dependencies>
                <group name="LoginLogout" depends-on="OpenBrowserNavigate"></group>
            </dependencies>
        </groups>
        <classes>
            <class name="tests.KWTestNG"/>
        </classes>
    </test>
</suite>
Output
[RemoteTestNG] detected TestNG version 7.0.0

===============================================
Selenium Project
Total tests run: 2, Passes: 2, Failures: 0, Skips: 0
===============================================
Advertisement