testng-team / testng

TestNG testing framework
https://testng.org
Apache License 2.0
1.99k stars 1.02k forks source link

Running TestNG dependent test in Logical OR #1092

Open gaganangrish opened 8 years ago

gaganangrish commented 8 years ago

Issue: Not able to run dependent tests with logical OR. TestNG is only running as in logical AND.

Use Case: In below code example, Test3 should only be executed if either of Test1 or Test2 has successfully passed.

     @Test(priority = 10)
     public void Test1() {
           System.out.println("+++++++++Running Test1++++++++++++");
           throw new SkipException("Skipping the test");
     }

     @Test(priority = 20)
     public void Test2() {
           System.out.println("+++++++++Running Test2++++++++++++");
     }

     @Test(priority = 30, dependsOnMethods  = {"Test1","Test2"})
     public void Test3() {
           System.out.println("+++++++++Running Test3++++++++++++");
    }

by using dependsOnMethods = {"Test1","Test2"} on Test3, it checks if both Test1 and Test2 have passed i.e. in logical AND. There is no way (other then programmatically) in TestNG that it should check the dependent test in logical OR and then execute the test.

As Test1 has been set to skip, Test3 is never running as not both of Test1 and Test2 are passing. I want to execute Test3 if either of Test1 or Test2 has been passed.

juherr commented 8 years ago

Maybe you should wait to have more response on http://stackoverflow.com/questions/38364471/running-dependent-tests-in-testng-in-logical-or

What is the real life usecase behind your request?

gaganangrish commented 8 years ago

I am testing some dynamic content on the web page which appears/don't appear based on the user data. The user flow is:

  1. Login to home page. (Home page test)
  2. Click on my bookings page My booking page can have 2 variations 2A. Displaying the current bookings to the user (My Booking page current booking test) 2B. No current bookings and displaying a button to book flights. (My Booking page no current booking test)
  3. User proceeds for the new booking. (New booking test)

So in this case Test Case 3 should execute if either of Test Case 2A or 2B is passed. I have used dependsOnMethods in my tests so I was assuming that I could use dependsOnMethods to actually execute a test case based on Logical OR but seems like this is not possible.

The only possible solution for me atm is to change the structure of my tests (which would take lot of rework) but if this can be implemented in TestNG it'd be great.

Let me know if more information is needed. Thanks. Gagan

On Thu, Jul 14, 2016 at 5:22 PM, Julien Herr notifications@github.com wrote:

Maybe you should wait to have more response on http://stackoverflow.com/questions/38364471/running-dependent-tests-in-testng-in-logical-or

What is the real life usecase behind your request?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/cbeust/testng/issues/1092#issuecomment-232583060, or mute the thread https://github.com/notifications/unsubscribe/AK0QYYvvXIQI01vRaUR03rmB9PAJuygmks5qVeOegaJpZM4JMIeB .

arham-jain commented 3 years ago

@juherr Should I spend time adding this feature? Or should it be closed as it can be handled programmatically?

juherr commented 3 years ago

@arham-jain Why not but in my opinion it is more important to fix current features than adding new ones.