1

Method1 has one parameter named as "Param1", if Param1 value is equal to 'True', it means execute the below method. Otherwise, skip this method and execute next method 'Method2'.

@Parameters({"Param1"})
    public void Method1(String Param1) 
    {
        //Perform Some operations
    }

//Method2 has one parameter named as "Param2"               
@Parameters({"Param2"})
    public void Method2(String Param1) 
    {
        //Perform Some operations
    }

For Example: If Param1 value will be true, it means that method Method1 will be executed. Otherwise, it will skip method Method1.

1 Answers1

2

Code sample:

 @Test
 @Parameters("testStatus")
  public void testMethod1(boolean testStatus) {
     System.out.println("TestStatus: "+testStatus);
     System.out.println();
     if(testStatus == true){
         throw new SkipException("This test is being skipped...");
     }
      System.out.println("test 333333");
  }

 @Test
  public void testMethod2() {
      System.out.println("test 2222");
  }

TestNG XML:

<suite name="Suite1" verbose="1" >

<test name="Test1">
  <parameter name="testStatus" value="true"/> 
  <classes>
    <class name="packagename.ClassName"/>
  </classes>
</test>

</suite>

In the above code, if parameter is true then the testMethod1 will be skipped and otherwise it will run as it is. I hope this will fill your requirement.

optimistic_creeper
  • 2,739
  • 3
  • 23
  • 37