I've developed some automation in the seleniumIDE

How do I export that code to eclipse as java files and what other configuration will I need to do in order to run those files.

  • What do you mean by "export code from selenium to eclipse" ?? – Helping Hands Jan 21 '15 at 12:27
  • Made an attempt at guessing meaning and made the question answerable. Original OP may be long gone. – Michael Durrant Mar 31 '17 at 14:54
  • accepted answer referenced seleniumIDE so I think that guess was ok (question didn't mention it until I edited it and added the reference you now see). – Michael Durrant Mar 31 '17 at 14:56

Copy+Paste from my blog:

Problem – Selenium Popup You need to test an anchor whose target is _blank.


Solution in IDE

  • Open Firefox
  • Click the Selenium icon to the right of the address bar
  • Enter http://www.htmlcodetutorial.com/ as your Base URL
  • Click the record button
  • Navigate to http://www.htmlcodetutorial.com/linking/_A_TARGET_95y98y108y97y110y107y.html
  • Left-click the a new window link
  • Right-click on the page and select verifyTitle A Whole New Window – HTML Code Tutorial
  • Close the new window/tab
  • Right-click on the original window/tab page and select verifyTitle HTML _blank – HTML Code Tutorial
  • In Selenium IDE, click the record button to stop recording
  • Add a pause 1000 step after the click step to give the window/tab time to load
  • Add a selectWindow A Whole New Window – HTML Code Tutorial step after the pause to connect to the new window/tab
  • Add a close step after the verifyTitle A Whole New Window – HTML Code Tutorial step
  • Add a selectWindow HTML _blank – HTML Code Tutorial step after the close step
  • Select Play Current Test Case to verify the test

Solution in Java

  • Export the test from the IDE solution (above)
  • Click File -> Export Test Case As… and select Java/JUnit4/Webdriver
  • Save as test01.java in your project’s src folder
  • Refresh your project in Eclipse (F5)
  • Fix any errors in the code and save
  • Remove package com.example.tests;
  • Open Test01.java
  • Scroll down some and you will see some comments, like // ERROR: Caught exception [ERROR: Unsupported command [selectWindow | A Whole New Window – HTML Code Tutorial | ]]
  • Some of Selenium IDE’s functions don’t have WebDriver equivalents just yet
  • Before the link click event add String parentHandle = driver.getWindowHandle();
  • This will get the parent window handle
  • After the link click event add for (String winHandle : driver.getWindowHandles()) {driver.switchTo().window(winHandle);}
  • This will switch us to the child window
  • After the close event add driver.switchTo().window(parentHandle);
  • This will switch us back to the parent window
  • Right-click somewhere in the code file and select Run As -> JUnit Test Or, click the green run button on the Eclipse toolbar
  • A browser window should open and run the test
  • The test results should display on the left pane of the Eclipse window
| improve this answer | |
  • This seems an answer to a different question? – ECiurleo Mar 31 '17 at 8:54
  • Apparently the OP thinks otherwise. It does kind of answer the question, in a roundabout way. – Kate Paulk Mar 31 '17 at 11:56
  • Fair enough :). I do think the answer would benefit by being made more concise to respond to the question. So others who need the answer can find it quickly. – ECiurleo Mar 31 '17 at 14:49

In my Selenium IDE version it is very easy to export:

  1. Record testcase in Selenium IDE

  2. Click File - Export Testcase As - Java / JUnit4 / WebDriver

  3. Save File as .java

Your testcase is now java and can be opened and managed and run in eclipse.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.