среда, 7 октября 2015 г.

Software testing tutorials and automation: How To Create And Run JUnit Test Suit For WebDriver Test - Step By Step


How To Create And Run JUnit Test Suit For WebDriver Test - Step By Step

If you are planning to perform regression testing of any application using webdriver then obviously there will be multiple test cases or test classes under your webdriver project. Example - There are 2 junit test cases under your project's package. Now if you wants to run both of them then how will you do it? Simple and easy solution is creating JUnit test suite. If your project has more than 2 test cases then you can create test suite for all those test cases to run all test cases from one place.



Step 1 - Create new project and package

Create new project in eclipse with name = junitproject and then add new package = junitpack under your project. VIEW THIS POST to know how to create new project and add package in eclipse. Add required external jar files for selenium webdriver.


Step 2 - Create 1st Test Case

Now create JUnit test case under junitpack package with class name = junittest1 as bellow. VIEW THIS post to know how to create junit test case in eclipse.
package junitpack;    import org.junit.Test;  import org.openqa.selenium.By;  import org.openqa.selenium.WebDriver;  import org.openqa.selenium.firefox.FirefoxDriver;    public class junittest1 {      WebDriver driver = new FirefoxDriver();     @Test   public void test() throws InterruptedException {    driver.manage().window().maximize();    driver.get("http://only-testing-blog.blogspot.in/2013/11/new-test.html");    driver.findElement(By.xpath("//input[@name='fname']")).sendKeys("junittest1 executed");    Thread.sleep(2000);    System.out.print("junittest1 class is executed");    driver.quit();   }  }

Step 3 - Create 2nd test case
Same way, Create 2nd test class with name = junittest2 under package = junitpack as bellow.
package junitpack;    import org.junit.After;  import org.junit.Before;  import org.junit.Test;  import org.junit.Ignore;  import org.openqa.selenium.By;  import org.openqa.selenium.WebDriver;  import org.openqa.selenium.firefox.FirefoxDriver;    public class junittest2 {      WebDriver driver = new FirefoxDriver();     @Before  public void setup () {   driver.manage().window().maximize();   driver.get("http://only-testing-blog.blogspot.in/2013/11/new-test.html");  }    @After  public void aftertest() {   driver.quit();   }     @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);   }      @Test   public void test2() throws InterruptedException {   driver.findElement(By.xpath("//input[@name='fname']")).sendKeys("junittest2 class-test2");   Thread.sleep(2000);   System.out.print("\njunittest2 class-test2 method is executed");   }  }

Step 4 - Create test suite for both test cases
Now we have 2 test cases(junittest1.java and junittest2.java) under package = junitpack.
To create test suite, Right click on junitpack package folder and Go to -> New -> Other -> Java -> Junit ->  Select 'JUnit Test Suite' as shown in bellow image.



Now click on Next button.On next screen, add junit test suite name = junittestsuite and select both test cases as shown bellow image and then click on Finish button.


It will add new test suite class = junittestsuite.java under your package as bellow.

Комментариев нет:

Отправить комментарий