Monday, 7 April 2014

Export Selenium Test from IDE to Eclipse| First Selenium WebDriver Program in Java | Eclipse, WebDriver, JUnit 4

By the end of WebDriver Tutorial you will be able to write your first Selenium WebDriver Script in Java. We will export the Selenium IDE recorded script and can use it with any other IDE like Eclipse.

To install Selenium IDE, please read my post 'Installing Selenium IDE'

Now, record the sequence you want to automate using Selenium IDE.  To learn more about how Record | Play and Modify script in Selenium IDE please read my post 'Record | Play | Modify script in Selenium IDE'.

Export Test case from Selenium IDE to Eclipse in Java and JUnit:
I have used  login sequence to Gmail as an example  in this post.  
  1. Now once you have recorded the steps/sequence, you will observe few Commands with their Targets/ Values in Selenium IDE Table Tab.


  2. From Menu click on File > Export Test Case As… > select Java/ JUnit 4 / WebDriver


  3. Save that file as .java


Import script in Eclipse: (Eclipse| WebDriver | JUnit 4)
If you don't have your Eclipse environment ready then please refer my post 'Configure Selenium WebDriver, Java and Eclipse'
  1. Launch eclipse.

  2. Right click on ‘Project name’ > Select ‘Import


  3. Select ‘File System’ and click ‘Next’


  4. From directory’ > click on ‘Browse’ and provide the location of the saved script .java file.

  5. Into Folder > click on ‘Browse’ and select ‘src’ folder of the project.


  6. Click Finish.

Fix Errors and Warnings in script:

Fix Error:
  • After importing the .java file you will see an error appearing in the code at 1st line. (as com.example.tests package doesn't exists)
  • Mouse over the error or click on ‘x’ icon in 'red' > it will open suggestion to fix it.
  • Select option to move the *.java to the given package. (You can select other option too)


Fix Warnings:
  • Mouse over on the warnings or click on Warning icons > it will open suggestion to fix unused imports, methods and values




Finally code will look like this: (Eclipse| WebDriver | JUnit 4)



1 comment:

  1. Hello Shivraj ,
    The Article on Export Selenium Test from IDE to Eclipse is nice. It give detail information about it .Thanks for Sharing the information Selenium Web Driver. Software Testing Company

    ReplyDelete