7o. Selenium IDE – Export test cases in desired language

Did you realize the fact that you are no more a newbie to Selenium now? The best part is, you have come a long way with Selenium IDE and you are very close to touching its borders! So, with the same zeal, let us continue and make sure that in this wonderful journey we don’t leave any stones unturned!

Today, let us get all geeky and find out how to export our automated test code in the programming language we desire to work with. Trust me, you wouldn’t realize how convenient this is until you actually use it. So, what are we waiting for? Let’s get started!

Scenario:

  1. Open ‘Google Accounts – Sign In’ page, https://accounts.google.com.
  2. Enter the email id, [email protected]
  3. Click next and enter password as, test.
  4. Click next and assert if the text “The email and password you entered don’t match.” appears on the screen.
  5. Assert if the title of the current page is, Gmail.

Below image shows the test case in the default Table format view.

Table format

Export Test Case As:

Click on File -> Export Test Case As… -> Choose desired combination of the programming language to which the chosen test case should be converted/unit testing framework/the tool in the suite with which the code will be used.

Export_testcase

Save the file in the desired local path. In this case, file will be saved with “.java” extension. Double clicking the saved file will open as below,

Junit_Code

Please note that the exported test case may have warnings or errors once imported or pasted to IDE such as Eclipse, NetBeans etc. in this case. There can also be unnecessary code that is not really required for this individual test case to run in the chosen combination. We will look in detail on how to edit the file accordingly in Selenium WebDriver blogs (upcoming). As automation testers, I would always suggest to code rather than recording and generating the test case. All this being said, “Export Test Case As…” might not seem like a killer feature and to be honest, it could use some improvement, but for beginners to understand and get a hold on the tool, this serves as a good starting point.

Clipboard Format:

Another alternative is “Clipboard Format”, which is available in the Options menu.

Export_ClipboardFormat

This helps us to choose the format in which we would like the code snippet to appear upon performing paste operation. HTML is the default selection. In this case, let us select ‘Java/ Junit4/ WebDriver’. When all the commands from the test script pane are chosen (Ctrl + a) and a copy (Ctrl + c) is performed, a code snippet of the chosen combination can be obtained with paste (Ctrl + v). The result after performing paste is as below,

Clipboard code

Thus, might-be-so-complex-to-achieve is made simple with Selenium IDE’s ‘Export Test Case As’ and ‘Clipboard Format’ options. Now it’s your turn to explore these features and get back with any doubts that may arise in the comments section.

See you again in another post. Have a great day!

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.