Selenium Testing
No edit summary
No edit summary
Line 1: Line 1:
=== Setting up testing with Selenium ===
=== Setting up testing with Selenium ===
====== Background ======
This is not a MDriven specific instruction, it's a page with short instructions and links to other pages to make it easy to know one way to follow to set up testing towards your system.
This is not a MDriven specific instruction, it's a page with short instructions and links to other pages to make it easy to know one way to follow to set up testing towards your system.


Line 6: Line 8:
Selenium is a very widely used framework for running scripted web tests. You can use it both for application testing and for load testing. Load testing though will be for a small number of clients, because it takes a lot of CPU and memory on the test server to run parallel web browsers.  
Selenium is a very widely used framework for running scripted web tests. You can use it both for application testing and for load testing. Load testing though will be for a small number of clients, because it takes a lot of CPU and memory on the test server to run parallel web browsers.  


The easiest way we recommend is using the Selenium IDE plug-in for your browser, for example Chrome. With the IDE you can create, edit and run a script without any setup on your local development machine.
The easiest way to get going is using the Selenium IDE plug-in for your browser, for example Chrome. With the IDE you can create, edit and run a script without any setup on your local development machine. https://chromewebstore.google.com
 
Search in the Chrome web store for "Selenium IDE". Add it, and then click on the browser extension to start it.
 
You save your test scripts to a local folder of your choice.


Most of what you run you run from the Selenium command line runner, read[https://www.selenium.dev/selenium-ide/docs/en/introduction/command-line-runner here]
===== Running your tests separate from your Desktop browser =====
You run tests on the Grid from the Selenium command line runner, read[https://www.selenium.dev/selenium-ide/docs/en/introduction/command-line-runner here]


====== Here is a quick summary; ======
Install the Selenium command line runner [https://www.selenium.dev/selenium-ide/docs/en/introduction/command-line-runner Command Line Runner]
Install the Selenium command line runner [https://www.selenium.dev/selenium-ide/docs/en/introduction/command-line-runner Command Line Runner]
* The command line runner uses node.js.
* The command line runner uses node.js.
Line 17: Line 23:
When you have a script that does what you want it to do, as simple and complex as that need to be, you install a Selenium Grid execution environment to run many copies of your test either after each other, or probably more important, in parallel to ensure good overall performance.
When you have a script that does what you want it to do, as simple and complex as that need to be, you install a Selenium Grid execution environment to run many copies of your test either after each other, or probably more important, in parallel to ensure good overall performance.


Installing a Selenium Grid is surprisingly simple, and we recommend this configuration (there are any number of different ways)
Installing a Selenium Grid is surprisingly simple, and we recommend this configuration (there are any number of ways, this is just a simple way on Windows)


* Install WSL2 on Windows (add feature to Windows)
* Install WSL2 on Windows (add feature to Windows, Windows Subsystem for Linux)
** Make sure that your machine has vCPU turned on in BIOS.
** Make sure that your machine has vCPU turned on in BIOS.
* Install Docker Desktop
* Install Docker Desktop
**
**
*
*Use the docker-selenium images/containers provided to run a whole grid setup without any effort
**https://github.com/SeleniumHQ/docker-selenium<nowiki/>This page is surprisingly detailed and well written, please read it carefully, it gives most answers to which setup to run.
 
===== Running your test script =====
In the folder you have saved you tests (they are files with the extension .side) create a file called .side.yml, which will be used for all .side files, regardless of name. This file is used by the command line runner.
# this is how your .side.yml should or could look like
capabilities:
    browserName: "chrome"
    se:recordVideo: "true"
    se:screenResolution: "1920x1080"
server: "<nowiki>http://localhost:4444/wd/hub</nowiki>"
Note that for example the browser name needs to be with without capital letters, it's case sensetive, and nothing will work if you have "Chrome" there instead of "chrome".
 
===== Which Grid setup to use? =====
There are grid setups that has only one node, or one node for each of the big browsers, Chrome, Firefox and Edge, but there are also a dynamic grid setup which we find very easy to use. It automatically will scale up to the number of CPU cores that your machine has.
 
To set up the entire dynamic grid, you create a "config.toml" file with configuration next to your test script files ".side" and the ".side.yml" file, that configures browser selection and where to find the grid.
 
Shortend example;
[docker]
# Configs have a mapping between the Docker image to use and the capabilities that need to be matched to
# start a container with the given image.
configs = [
    "selenium/standalone-firefox:4.16.1-20231219", '{"browserName": "firefox"}',
    "selenium/standalone-chrome:4.16.1-20231219", '{"browserName": "chrome"}',
    "selenium/standalone-edge:4.16.1-20231219", '{"browserName": "MicrosoftEdge"}'
]
# Windows: make sure Docker Desktop exposes the daemon via tcp, and use <nowiki>http://host.docker.internal:2375</nowiki>.
url = "<nowiki>http://127.0.0.1:2375</nowiki>"
# Docker image used for video recording
video-image = "selenium/video:ffmpeg-6.1-20231219"
 
 
 
ds
 
Adding video recording to your .side.yml file: if you want video recording of all your executions, add  se:recordVideo: "true" to the .side.yml file in your local folder.


Show the local Selenium grid UI:http://localhost:4444/ui#


Show the local Selenium grid UI: http://localhost:4444/ui#





Revision as of 16:09, 1 January 2024

Setting up testing with Selenium

Background

This is not a MDriven specific instruction, it's a page with short instructions and links to other pages to make it easy to know one way to follow to set up testing towards your system.

Selenium does testing of web sites, so it's targeting a TurnKey application. These instruction and testing has all been done on Windows 11.

Selenium is a very widely used framework for running scripted web tests. You can use it both for application testing and for load testing. Load testing though will be for a small number of clients, because it takes a lot of CPU and memory on the test server to run parallel web browsers.

The easiest way to get going is using the Selenium IDE plug-in for your browser, for example Chrome. With the IDE you can create, edit and run a script without any setup on your local development machine. https://chromewebstore.google.com

Search in the Chrome web store for "Selenium IDE". Add it, and then click on the browser extension to start it.

You save your test scripts to a local folder of your choice.

Running your tests separate from your Desktop browser

You run tests on the Grid from the Selenium command line runner, readhere

Install the Selenium command line runner Command Line Runner

  • The command line runner uses node.js.
  • Once node.js is installed, run npm install -g selenium-side-runner

When you have a script that does what you want it to do, as simple and complex as that need to be, you install a Selenium Grid execution environment to run many copies of your test either after each other, or probably more important, in parallel to ensure good overall performance.

Installing a Selenium Grid is surprisingly simple, and we recommend this configuration (there are any number of ways, this is just a simple way on Windows)

  • Install WSL2 on Windows (add feature to Windows, Windows Subsystem for Linux)
    • Make sure that your machine has vCPU turned on in BIOS.
  • Install Docker Desktop
  • Use the docker-selenium images/containers provided to run a whole grid setup without any effort
Running your test script

In the folder you have saved you tests (they are files with the extension .side) create a file called .side.yml, which will be used for all .side files, regardless of name. This file is used by the command line runner.

# this is how your .side.yml should or could look like
capabilities:
    browserName: "chrome"
    se:recordVideo: "true"
    se:screenResolution: "1920x1080"
server: "http://localhost:4444/wd/hub"

Note that for example the browser name needs to be with without capital letters, it's case sensetive, and nothing will work if you have "Chrome" there instead of "chrome".

Which Grid setup to use?

There are grid setups that has only one node, or one node for each of the big browsers, Chrome, Firefox and Edge, but there are also a dynamic grid setup which we find very easy to use. It automatically will scale up to the number of CPU cores that your machine has.

To set up the entire dynamic grid, you create a "config.toml" file with configuration next to your test script files ".side" and the ".side.yml" file, that configures browser selection and where to find the grid.

Shortend example;

[docker]
# Configs have a mapping between the Docker image to use and the capabilities that need to be matched to
# start a container with the given image.
configs = [
    "selenium/standalone-firefox:4.16.1-20231219", '{"browserName": "firefox"}',
    "selenium/standalone-chrome:4.16.1-20231219", '{"browserName": "chrome"}',
    "selenium/standalone-edge:4.16.1-20231219", '{"browserName": "MicrosoftEdge"}'
]
# Windows: make sure Docker Desktop exposes the daemon via tcp, and use http://host.docker.internal:2375.
url = "http://127.0.0.1:2375"
# Docker image used for video recording
video-image = "selenium/video:ffmpeg-6.1-20231219"


ds

Adding video recording to your .side.yml file: if you want video recording of all your executions, add se:recordVideo: "true" to the .side.yml file in your local folder.

Show the local Selenium grid UI:http://localhost:4444/ui#



Useful links

Main Selenium site: https://www.selenium.dev/

This page was edited 21 days ago on 04/08/2024. What links here