Showing posts with label JUint. Show all posts
Showing posts with label JUint. Show all posts

Thursday, February 4, 2016

Adding JUnit 4 libraries

Create a Java project, create a package and a class

Note: Don't import any libraries

Add a method and mention "@Test" above the method.

Bring the mouse over the "@Test"  and click on "Add JUnit 4 library...." option


JUnit Library will be added



 

Wednesday, February 3, 2016

Reports generation with Selenium, JUNIT and ANT

 


Step1: Create two classes with first class having two test cases, second having one test case.  Create ”MyTestSuite”.


 

Step2: Go to Windows>Preferences and add the "JUNIT" jar through external jars as shown below.





Step3: On TestCases package, right click and select Export option
 
 

Step4: Select “ANT Build Files” and click Next
 
 
Step5: Select the project name and click “Finish”, The Build.xml file will be generated.

 
 

Step6: Open the build.xml and remove the Target xml section created for the first two classes. Don’t remove the MyTestSuite related Target. Save the file.
Step7: Right click on build.xml, select “Run As” and “Ant Build” option
 
Step8: Select “build[default], MyTestSuite, juintreport” and click “Run”.
 
Step9: MyTestSuite executes and report will be available in “junit” folder.
 
Step10: Open “Index.html” in Web Browser.
 
Step11: Click on “MyTestSuite” for detailed results.
 

JUNIT with SELENIUM

Sample Script to use JUNIT with Selenium

import org.junit.After;

import org.junit.Assert;


import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class junitsample {
        WebDriver ie = null;
        @Before
        public void initiation(){
       System.setProperty("webdriver.ie.driver", "D:\\Hemanth\\IEDriverServer_x64_2.50.0\\IEDriverServer.exe");
       ie= new InternetExplorerDriver();
        }
        @After
        public void last(){
               ie.close();
               System.out.println("completed");       
        }
        @Test
        public void testing(){
               ie.get("http://stlc4u.blogspot.in/");
                String s = ie.getTitle();
                System.out.println(s);
                ie.findElement(By.linkText("2014")).click();
                s = ie.getCurrentUrl();
                Assert.assertTrue(ie.getTitle().equals("Software Testing"));
                }
}
The “Before” method will be executed before each “Test” method and “After”method will be executed after each “Test” method. Assert is used for  verification purpose.here assert is verifying whether the “2014” link related page name is “Software testing”or not. Run this as JUNIT Test, the result would  mentioned below

If you change the Assert to “Software” instead of “Software Testing”, it will fail.