Monday, September 8, 2014

Running Selenium Test Case in Eclipse using Junit

Running Selenium Test Case in Eclipse using Junit

1à Open Selenium test case in selenium IDE

2à Export Test Case in Junit4 Format(in Latest IDE, it looks like Java/Junit4/RemoteControl

3à Open that exported file and copy its content.

                                             NOW MOVE TO ECLIPSE

4à Open Eclipse; create a java project, package and java class.

After Creating Project, Go to Src folder , right click and create package

After creating package, right click on package and create a class

5à pick data copied in Step 3 and place it in Java class created in Step 4(after the all existing lines of code)

Note:
 Lot of Red(x) are display on left of line of code so to remove that
è  first , replace class name of java project(class name coming from IDE replaces class name here in Eclipse) 

è Now remove code which is actually generated in java class(left the code which is copy from selenium IDE)
           Few red(X) will be removed
Note:: Still lot of Red Cross(x) is available, it’s because we need to add selenium client libraries for java here in project. Actually in coding we are using selenium class, creating object for that but libraries does not exist in build path of the project.

6à Right Click on Java Projectà Build Path à Configure Build Path

Go to Libraries Tab, Click on Add External Jar Button at right side

Now Selenium server RC jar which we have downloaded while installing selenium server

Close this window, Save, Here we will find that all Red Cross(x) are removed from code lines.
Everything is set now to run test case.
NOW get ready to execute test cases

7à Go to Runà Run as Junit

Here we will find that test case still gets failed it’s because selenium server is down, start selenium server and then run test case as junit.

To Start Selenium Server:  Open command prompt, move to place where jar of selenium server exist
Now write command:   java-jar seleniumserver_jar_name.jar

Test case will run successfully.

No comments:

Post a Comment