1

I am trying to debug a TESTNG test using Debug Configurations option in Eclipse and I need to get the Program arguments inside my TestNG test. Could you please help me in accomplishing it?

enter image description here

Srinivasan Ramu
  • 1,033
  • 4
  • 11
  • 23

1 Answers1

2

You can pass values to TestNG via two means in the Run Configurations screen

  1. JVM arguments. Below screenshot shows how to pass them

JVM arguments

  1. As environment arguments. Below screenshot shows how to pass them

Environment arguments

The below sample shows how to read those values from the Run configuration

import org.testng.annotations.Test;

public class HelloWorldTestClass {

    @Test
    public void testMethod() {
        //This is how we read values provided via the Environment tab section of the run configuration.
        String environment = System.getenv("env");
        //This is how we read values provided via the VM arguments section 
        String browser = System.getProperty("browser");
        System.err.println("Running on [" + browser + "] in the environment [" + environment + "]");
    }
}

Below is the output of the execution:

[RemoteTestNG] detected TestNG version 6.14.3
Running on [Opera] in the environment [Production]
PASSED: testMethod

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66