De
Python- und Java-Programmcode-Beispiele, die objektorientierte Prinzipien in der Softwareentwicklung veranschaulichen
Automation

6 Schritte zur Erstellung und Export von Selenium IDE-Tests (English)

Dieser Blog ist nur in englischer Sprache verfügbar.

Die genannten Expleo Academy Trainings sind entweder auf Deutsch oder Englisch verfügbar.

The aim of this blog is to show you in 6 steps how to install the Selenium IDE Add-on, create basic Selenium IDE automation tests by recording, execute them and export them into a programming language (e.g. C#, Java, Python).

What is Selenium IDE?

Selenium IDE is a Firefox/Chrome Add-on that helps create Selenium test cases and test suites against web applications. It is a useful tool to create the bulk of your Selenium scripts, but it does also have its limitations.

For this blog, we will concentrate on just Firefox, although Chrome is pretty much the same.

1. Install the Selenium IDE Add-on

The first step is to download the Selenium IDE which – at the time of writing – is via the following URL:

Just click on the browser you are interested in (for these notes we are going to use Firefox, although Chrome is really not that different).

Selenium IDE

This should take you to the actual Add-on page.

Firefox Browser Addons Selenium IDE

Clicking the Add to Firefox button will start installation.

Add Selenium IDE? Install Browser Plugin

After accepting all the defaults, it will appear on your browser toolbar.

Selenium Browser Plugin HowTo

2. Record a script to create tests using the Selenium IDE

To record a test case:

Ensure you have browsed to the Application under Test (AUT) that you wish to record against.

For these notes we have our own website.

From the Firefox Tool bar, select the Selenium IDE icon.

localhost lampmusicstore - Selenium Browser Plugin

The Selenium IDE Application will start by displaying a menu:

Welcome to Selenium IDE!

As we have never used it before, the above screen is selecting the first option.

When creating a new project, it will ask for the name. For these notes we have used the imaginative name of demo.

Name your new Project (in Selenium IDE)
It will then want to run a test, and will prompt you for the project’s base URL. You can get this by copying the main URL from the original browser window and pasting it across.
Copy 6 Paste Base URL in Selenium

Selenium will then open a new browser window which you use to record your steps for your test.

Selenium IDE is recording

From this point forward the IDE monitors all mouse interactions and keyboard inputs and records them in the Selenium IDE interface. Until you stop the recorder.

Selenium IDE does have a habit of placing the web page in a window in front of the Selenium IDE and will record the action of moving it in your script.

Demo Shop Lamp Music Store - Selenium IDE is recording

The Selenium IDE table tab will then display all actions captured by the recorder. It is possible to view, modify or delete commands from this view. To delete a command, right click on the command and select delete from the menu.

When all recorded steps are complete, stop the recorder by clicking on the red circle.

Extension (Selenium IDE) Stop Recording Step

To save your test, you will need to save the entire project, click on the Save project button in the top right-hand corner of the IDE screen.

Save Projects in Selenium IDE

3. Replay the script in the Selenium IDE

Once all the required test steps have been captured, you can now replay the test by clicking on the Run current test icon.

Run current Test in Selenium IDE

If you have closed the window Selenium used to record the test, the IDE will now open it again.

On successful execution of the test the captured tests steps will turn green:

Project: demo* setup in Selenium IDE

Should the test fail, the failed line (usually highlighted in red) and the failure count on the left-hand side will increment by one.

Setup Selenium IDE Browser Extension

Any errors also appear in the log tab at the bottom of the Selenium IDE interface.

Inserting Commands

When using Selenium IDE as an automated test tool it is inevitable that you are going to need to modify the recorded steps to include an additional step e.g. an extra click, some synchronisation or an Assertion (A method of passing or failing a test).

To insert a new command:

Select the point in the script where you wish to place the new command. Right click the Selenium IDE interface and select Insert New Command
Setup Selenium IDE Browser Extension

Initially the new command will appear in the script as a blank line.

Structure of a line in the test case

Each command requires up to three inputs:

  • Command
  • Target
  • Value
Setup Selenium IDE Browser Extension command

To insert a new command:

Command is the action the Selenium Script is to perform. Commands range in functionality from Navigation e.g. Click a Button, Synchronisation e.g. Wait for text to appear on the screen and Assertions e.g. ensure the correct text has appeared on the screen.

To select a command, click on the black arrow to expand the drop-down list of available commands.

Target

Target refers to the Object or “WebElement” that you wish to record the action. For example, if the Selenium IDE script was required to click on a link a “description” of the object would be included in the target field.

Value

The value is an optional field used when the command needs some additional information. For example, if you want to type in a text box, then this field would contain the text you wished to type.

4. Replay all tests in the Selenium IDE

If the Selenium IDE project has more than one test, we can run them all sequentially.

In the screenshot below, we have a couple of tests sitting in the IDE…

Setup Selenium IDE Browser Extension - search
A Selenium test suite wA Selenium IDE test suite with more than one test case.

To execute all tests in the test suite, select the Run all tests button:

Setup Selenium IDE Browser Extension - run all tests

The test cases show up as green when the tests have executed successfully:

Setup Selenium IDE Browser Extension - search

5. Export the tests from Selenium IDE

The Selenium IDE enables recorded test cases to be exported to a range of programming languages and their respective testing frameworks.

To do this:

Either right-click on the test name or hover the mouse near the end of the test name field until three dots appear.

Setup Selenium IDE Browser Extension demo1

Click on this and select export.

Setup Selenium IDE Browser Extension Export

Selenium will then prompt you to select the language (in this example we have selected C# NUnit).

Setup Selenium IDE Browser Extension C# NUnit

Give a filename and save it in the desired location.

Setup Selenium IDE Browser Extension - Save As CS file

The choice of programming language and test framework would be either be a personal preference or an organisational norm and would depend on tools and skills of the tester or developers available.

6. Running Selenium IDE test cases from the command line

Once you add the test cases into a Selenium IDE test suite, it is possible to execute them from the command line.

Open a new instance of File Manager (“Win + E”).

Navigate to the folder where you saved your project (the file with the extension “side”).

Setup Selenium IDE Browser Extension - file system

Hold down Control & Shift and then Right click the mouse and select Open PowerShell window Here:

Selenium Screenshot

Run the tests from the command line

In the terminal window, type in the following:

selenium-side-runner *.side

This will run selenium from the command line.
Command Line Selenium

To exit out of the terminal window, type in exit.

Want to find out more?

Want find out more about setting up the Selenium IDE, exporting test cases to other languages and running them as actual code?

Well, at the Expleo Academy we deliver courses on Selenium and many other subjects. Feel free to visit the Academy website.

  • If you are interested in learning all about how to use Selenium with Java then feel free to have a look at out Using Selenium with Workshop course.
  • If you are interested in learning all about how to use Selenium with Cucumber then feel free to have a look at out Using Selenium with Cucumber course.


More information on the Selenium IDE can be found at the following location:

https://selenium.dev/selenium-ide/docs/en/introduction/getting-started

John Kurowski has been delivering training for over 10 years specialising in Automation, Agile and ISTQB. John also develops the courseware and creates virtual machines in AWS for automation courses.
John has been working in IT for over 30 years and has also been a tester, test manager, developer, development manager, project manager, support consultant (the list goes on…)