Skip Exception | Selenium Forum
M
Posted on 24/09/2015
when i am adding skip exception in ant test then code written before skip exception are executed. Let take a example

@Test()
public void checkB(){
System.out.println("Before Skip");
throw new SkipException("skip checkB");
}


when i am looking on console after executing this through testng.xml, i am looking that "Before Skip" is printing on console.
i wants to ask you that i have written a long code and at last i put <throw new skipexception("");>means i skipped this test. After executing i am looking that all the code are running before this skip statement and when i am checking in result, it is considering as skipped.

Is there any way that all the code did not run before skip statement when i skip any test.

M
Replied on 24/09/2015

no there is no other way you have to put exception at the top.


M
Replied on 29/09/2015

when i am trying to define skip exception at begin of code then its throwing error. i am attaching image.

Pleaes suggest

Responsive image

M
Replied on 29/09/2015

i don't think thats an error. it might be warning.

basically its saying is your code throws exception at line 3 and stop execution. it won't execute line line 4.


M
Replied on 29/09/2015

but when i am running program, its displaying error.
Please look in image its clearly displaying error.

Responsive image

M
Replied on 29/09/2015

ok its an error.

like I wrote in my last reply

basically its saying is your code throws exception at line 57 and stop execution. it won't execute line line 58. put a try catch bloack on exception or change the location of line 58.


M
Replied on 29/09/2015

i understand your point but in every condition it will run if i put syso statement in try or catch.
Can you code it which you are saying.

Thanks...


M
Replied on 29/09/2015

in all 3 condition syso statement will run.

Condition 1-
try {
throw new SkipException("skip checkB");
} catch (Exception e) {
System.out.println("Exception thrown checkB");
}

Condition 2-
try {
System.out.println("Exception thrown checkB");
throw new SkipException("skip checkB");
} catch (Exception e) {
}

Condition 3-
try {
throw new SkipException("skip checkB");
} catch (Exception e) {
}
System.out.println("Exception thrown checkB");


M
Replied on 29/09/2015

all 3 condition should run just fine.

watch module 5 for further clarity. but first one you should use.