Demonstration of Selenium JavaScript end-to-end tests, using a simple test runner script that calls test files.
Setup:
node install
Syntax:
./test.js
Example using a typical top level project directory:
./test/e2e/test.js
Environment variables:
PORT
: the base port number for opening browsers; default is 10000
This repository has three essential areas:
-
test.js
is the test runner that reads individual test files -
test_*.js
are the individual test files for end-to-end tests -
support.js
has helpers and utilties for launching browsers
This script reads its directory to find test files to require; test files must have names that begin with "test_" and end with ".js".
For each test file, this script launches a new driver, in parallel,
then calls the test file's function test(…)
with this signature:
module.exports = async function test(index) …
Example test file:
const support = require('./support')
const assert = require('assert')
const {By, Key} = require('selenium-webdriver')
module.exports = async function test(index){
// Launch a web browser
let driver = await support.makeDriver()
// Go to a web page
await driver.get("https://example.com")
// Verify the headline
let headline = await driver.findElement(By.tagName("h1")).getText()
assert.equal(headline, "Example search page")
// Find the search box, then type "kittens", then press return.
await driver.findElement(By.name("q")).sendKeys("kittens", Key.RETURN)
// Is the results page title correct?
let title = await driver.getTitle()
assert.equal(title, "Example results for kittens")
}
Install Node and NPM as usual.
If you need help with this, then see demo-selenium-javascript
Install Selenium WebDriver:
npm install --save selenium-webdriver
Install Google Chrome driver:
npm install --save chromedriver
Recursive read directory with streams:
npm install --save readdirp
Construct pipes of streams of events:
npm install --save event-stream
Run:
./test.js
Or you can run with Node explicity:
node test.js
- Package: demo-selenium-javasript-e2e-tests
- Version: 2.0.0
- Created: 2019-11-02T00:00:00Z
- Updated: 2021-10-08T00:19:55Z
- License: GPL-2.0-or-greater or for custom license contact us
- Contact: Joel Parker Henderson (joel@joelparkerhenderson.com)