@astraload/asl-webdriver
v1.0.3
Published
A custom Selenium-webdriver dedicated to being used with Astraload SaaS
Downloads
232
Readme
AslWebDriver
AslWebDriver is a custom Selenium-webdriver dedicated to being used with Astraload SaaS.
Installation
npm install @astraload/asl-webdriver
Setup
Download and place on your system PATH an executable of chromedriver corresponding to a version of the Chrome browser installed on your system.
API
constructor(params)
params:
isHeadless
(boolean
): Flag whether to run chrome in headless mode. Defaults tofalse
. Set totrue
in order to run load test on Astraload SaaS.windowSize
({ height (number), width (number)}
optional): Browser window size.logLevel
(number
optional): Level of extended logging of network activity. Can be set toLogLevel.Verbose
and/orLogLevel.Debug
.LogLevel.Verbose
flag enables logging ofdataReceived
network events.LogLevel.Debug
flag enables logging of unfinished network requests. Use Bitwise OR operator to combine both flags.
Example:
const { AslWebDriver } = require('@astraload/asl-webdriver');
const aslWebDriver = new AslWebDriver({
isHeadless: true,
windowSize: {
widht: 1280,
height: 960,
},
logLevel: AslWebDriver.LogLevel.Verbose | AslWebDriver.LogLevel.Debug,
});
loadBrowser() / async loadBrowserAsync()
Method takes no parameters. It loads Selenium WebDriver, wraps it for capturing performance data, and returns its instance.
Example:
There are 2 ways to integrate AslWebDriver with your tests, depending on whether you use async/await in your tests or not.
Using async/await:
let driver;
(async function() {
try {
driver = await aslWebDriver.loadBrowserAsync();
await driver.get(url);
await driver.wait(until.titleContains('SomeTitle'), timeout);
await driver.quit();
} catch (error) {
await aslWebDriver.handleTestFail(error);
// you need to call handleTestFail method to let the agent properly handle failed test,
// otherwise the agent will considers this test as successfully passed.
// handleTestFail method will automatically quit the browser after handling the failed test.
}
})();
WITHOUT using async/await:
const driver = aslWebDriver.loadBrowser();
driver.get(url);
driver.wait(until.titleContains('SomeTitle'), timeout);
driver.quit();
// if error happens during the test execution
// AslWebDriver will catch it for you, properly handle it
// and then quit the browser.
async handleTestFail(error)
Method takes a single parameter - an error
object. Method is intended to be used in tests which are written is async/await manner to let agent properly handle failed test. Method automatically closes the browser after handling failed test.
Example:
(async function() {
try {
// your test steps
// ...
} catch (error) {
await aslWebDriver.handleTestFail(error);
}
})();
userId (number
). Let's say you run a test for 100 users. In that case, each aslWebDriver
instance will have its own unique userId
which is a user index in a range from 0 to 99.
Example:
const { AslWebDriver } = require('@astraload/asl-webdriver');
const aslWebDriver = new AslWebDriver();
const { userId } = AslWebDriver;
Notes
The @astraload/asl-webdriver
package mirrors all the exports of the selenium-webdriver
package; so if you need to import anything from the selenium-webdriver
package to use in your load test, import it from @astraload/asl-webdriver
package instead:
const { AslWebDriver, By, Condition, until } = require("@astraload/asl-webdriver");