I've been playing a little bit with Selenium for testing purposes. Here's a tiny example.
Create a package.json file manually or via. npm init. You could run the npm commands separately but why not just run them one time and let npm do the rest.
{
"name": "selenium-tests",
"homepage": "https://engbjerg.dk",
"version": "1.0.0",
"private": true,
"description": "Run tests on [WEBSITE] with selenium",
"dependencies": {
"assert": "2.0.0",
"chromedriver": "^87.0.4",
"chrome-modheader": "^1.0.6",
"mocha": "^8.2.1",
"selenium-webdriver": "^4.0.0-alpha.8"
},
"author": "Willam <my@mail>",
"main": "main.js",
"devDependencies": {},
"scripts": {
"test": "mocha *.js",
"test-single": "mocha *.js --grep $npm_config_feature"
}
}
Write your first script
This hasn't been fully tested. Just an example.
it('TEST_URL', async function() {
let link = await driver.wait(until.elementLocated(By.css('button')), 300);
let clicked = await link.click();
assert.strictEqual(await clicked, true, "No click was attempted");
});
Execute test-scripts
# Test Commands
$ npm test FILENAME
# Run a single function from it
$ npm run test FILENAME --func="TEST_URL"