As described in my previous post, We can create junit test suite to execute multiple test cases from one place. See example of my previous post. junittest2 class have two @Test methods. Now If I wants to exclude/Ignore 1st @Test method from execution and wants to execute only 2nd @Test method then how can I do It? Ignoring specific test in junit test is very easy.
@Ignore annotation
We can use JUnit's has inbuilt @Ignore annotation before @Test method to Ignore that specific webdriver test from execution. Let we apply @Ignore annotation practically in our test and then observe its execution result.
My scenario is to ignore 1st @Test method from execution so i need to put @Ignore annotation in my test before 1st @Test method as bellow.
@Ignore
@Test
public void test1() throws InterruptedException{
}
Here, @Ignore annotation will exclude test1() method from execution.
Copy bellow given Ignoring @Test method(test1()) part with @Ignore annotation and replace it will @Test method part given on Step 3 (Create 2nd test case) of THIS EXAMPLE (Note : @Test method part which needs to replace is marked with pink color in that example post).
//To ignore this @Test method from execution
@Ignore
@Test
public void test1() throws InterruptedException{
driver.findElement(By.xpath("//input[@name='fname']")).sendKeys("junittest2 class-test1");
System.out.print("\njunittest2 class-test1 method is executed");
Thread.sleep(2000);
}
Now when you run full test suite(junittestsuite.java) then on completion of junit test suite execution, you will get bellow given result in console.
junittest1 class is executed
junittest2 class-test2 method is executed
As per console result, ignored test(test1()) is not executed.
JUnit test execution report will looks like bellow.
This way, Junit's @Ignore annotation will help us to ignore specific test from execution.
i was wondering if u can use selenium ide and export it as java/junit/webserver - would that code work?
ReplyDeletesir the pink box did not appear plz help plz plz ele my boss will fire me i have 2 kids and 1 wife to feed plzzzz
ReplyDelete