after(async function() { await server.kill(); // Clean shutdown });
Here is a setup.js file that starts the server before your tests run and kills it after: selenium-standalone
await browser.url('https://example.com'); const title = await browser.getTitle(); console.log( Page title is: ${title} ); await browser.deleteSession(); })(); after(async function() { await server
Run your test while selenium-standalone start is running in another terminal. They will connect automatically. The CLI is great, but the real power is using the API inside your test setup hooks. after(async function() { await server.kill()
// setup.js const { start, install } = require('selenium-standalone'); let server;
before(async function() { // Ensure drivers are installed (safe to call every time) await install(); // Start the server server = await start(); console.log('Selenium ready'); });