We have several examples available to help you get started with Selenium WebDriver testing on RedLine13. In this brief post, we’ll go about constructing a Selenium script from scratch. We will also review the basic necessities and also common pitfalls when deploying on RedLine13.
Selenium supports several languages for scripting, with JavaScript being a popular choice. The first line in our script should be instantiating the redline WebDriver instance:
const redline = require('redline13-webdriver');
We will want to define a constant for the browser type that we want to use. The recommended browser for RedLine13 is Chrome, however Mozilla FireFox is also supported. Here we define the browser we will use as Chrome:
const BROWSER = 'chrome';
Next we will want to define our main()
method. As the name suggests, this is where the main logic of the test will run:
const main = () => { ... }; main();
Inside the main function, the first thing we will want to do is define the actual WebDriver object. This can be set as follows:
const driver = redline.loadBrowser(BROWSER);
Now let’s do something useful by defining the main actions of our script:
driver.get(‘https://demoqa.com/’).then(_ => { redline.snap('capture1.png'); driver.get(‘https://demoqa.com/webtables’).then(_ => { redline.snap('capture2.png'); }); });
In the above example, we instruct WebDriver to load an endpoint (https://demoqa.com/
) and once that is loaded, obtain a screen capture. Then it loads another endpoint (https://demoqa.com/webtables
) and performs a second screen capture.
The last statement that should be included in any Selenium script is a call to driver.quit()
. This will ensure that the WebDriver instance terminates normally and allows for the test to end expectedly.
To put all of the above pieces together, our entire script should appear as follows:
const redline = require('redline13-webdriver'); const BROWSER = 'chrome'; const main = () => { const driver = redline.loadBrowser(BROWSER); driver.get(‘https://demoqa.com/’).then(_ => { redline.snap('capture1.png'); driver.get(‘https://demoqa.com/webtables’).then(_ => { redline.snap('capture2.png'); }); }); driver.quit(); }; main();
This represents a very simple example of a WebDriver script, however it covers all of the basic concepts required to run such a test on RedLine13. You can expand the body of the main()
method to make your script perform more complex tasks to achieve your testing goals.
JMeter as an Alternative to Selenium
Even though Selenium WebDriver most closely simulates the end user experience recreating it with high accuracy, it is resource intensive. If we are more concerned with stress testing our target test application we can do this more efficiently with a scripted framework such as JMeter. This is especially true when massively scaled load testing is indicated into the thousands or millions of virtual users and beyond. In these cases, JMeter will almost always be the superior choice.
Did you know that we offer a full-featured free trial? Sign up now and start your Selenium WebDriver testing on RedLine13 today!