Sureshmani Kalirajan
Sureshmani Kalirajan

Reputation: 1938

If one test case failed, how to move on to next case automatically and execute in selenium webdriver?

I have created 3 seperate test cases in selenium webdriver ( not TestNG) - separate java files. I would like to execute all three test cases one by one. If one test case failed, I would like to continue executing the next test case. What are my options here ? any suggestions? ( I am new to Selenium).

Upvotes: 0

Views: 2543

Answers (2)

Sureshmani Kalirajan
Sureshmani Kalirajan

Reputation: 1938

I have actually found a solution after doing some research. I have a data driven excel framework (Apache POI) and each row is a test data for a test case. My code looks like this and working fine now. if there is a exception in one of the test, it captures it and skip to next test automatically. If exception such as nosuchobjectelement occurs, then it captures the exception and send the exception to log file & fails the test case. Since for loop is still active, it goes to next test and start executing it again.

For( test 1 to n) { Try { //Steps to perform tests } Catch (Exception e) { Log.Output(e.description); }

}

Upvotes: 1

user7627726
user7627726

Reputation:

I made what I'd like to call a "skeleton" for you. I do not know what exactly your scenario is because you did not explain, so you will have to fill in the lines. Pretty much all you have to do is make a boolean variable(I called mine valid) and use an if statement to keep running tests. If whatever your condition is is not met, it will print, "You failed the test." If one of the conditions is met it will say, "You passed the test." This is written in Java:

public class Test {  
    static boolean ConditionIsMet = false;
    static boolean valid = false;

    public static void main(String[] args) throws Exception {
        if (!valid) {
            TestOne();
            TestTwo();
            TestThree();
            System.out.println("You failed the test");
        } else {
            System.out.println("You passed the test");
        }
    }
    private static void TestOne() {
        //Go through a test
        if(ConditionIsMet) {
            valid = true;
        }
    }   

    private static void TestTwo() {
        //Go through a different test
        if(ConditionIsMet) {
            valid = true;
        }
    }

    private static void TestThree() {
        //Go through another different test
        if(ConditionIsMet) {
            valid = true;
        }
    }
}

Upvotes: 1

Related Questions