Webdriver Server
webdriver-server is a foundational package within the Macaca.js ecosystem, designed to provide a standalone server that implements the WebDriver protocol. As of its current stable version, 1.3.1, it enables UI automation by allowing WebDriver clients (like testing frameworks) to connect and execute commands against various browsers and mobile applications, provided the necessary drivers are configured. The project appears to be in a maintenance phase, with the last notable activity indicated by its README update in late 2022 and npm last publish 2 years ago. It serves a specific role within the broader Macaca.js framework, offering a tailored environment for Macaca-based test automation. While not a direct competitor to general-purpose, feature-rich solutions like Selenium Grid or Appium in isolation, its strength lies in its tight integration and consistent operational model within the Macaca suite, making it a suitable choice for users already invested in that platform. Its release cadence is not rapid, reflecting a stable and mature, albeit slowly evolving, component.
Common errors
-
Error: listen EADDRINUSE: address already in use :::4444
cause The specified port (e.g., 4444) is already being used by another application or another instance of webdriver-server.fixChange the `port` option in your server configuration to an unused port, or terminate the process currently occupying the port. -
WebDriverError: A session is either terminated or not started
cause The WebDriver client attempted to interact with a session that either doesn't exist, has already been closed, or failed to initialize correctly on the server side.fixEnsure the client correctly establishes a new session before sending commands. Check server logs for errors during session creation (e.g., driver not found, capabilities mismatch). -
Error: No driver found for the requested capabilities.
cause The `webdriver-server` could not find the necessary browser driver (e.g., `chromedriver`, `geckodriver`) to fulfill the desired capabilities specified by the client. This typically means the driver is not installed or not in the system's PATH.fixInstall the required browser driver(s) (e.g., `npm install -g chromedriver`). Verify the driver executable is available in your system's PATH environment variable. If applicable, explicitly configure the driver path in the `webdriver-server` options.
Warnings
- gotcha The WebDriver protocol is continuously evolving. While `webdriver-server` aims for compliance, significant updates to the W3C WebDriver specification or browser driver implementations (e.g., ChromeDriver, GeckoDriver) may require updates to `webdriver-server` or its dependencies.
- gotcha Like any network service, `webdriver-server` requires an available port. Attempting to start the server on a port already in use will result in an `EADDRINUSE` error.
- gotcha `webdriver-server` itself provides the WebDriver protocol endpoint but typically relies on external browser-specific drivers (like ChromeDriver for Chrome or GeckoDriver for Firefox) to interact with actual browsers. These drivers must be installed and accessible in the system's PATH, or their paths must be explicitly configured.
- gotcha As `webdriver-server` is specifically part of the Macaca.js ecosystem, its standalone features might be less extensive or actively developed compared to dedicated, general-purpose WebDriver servers (e.g., Selenium Grid Standalone or Appium). Its primary design intent is often to integrate within Macaca's broader automation solutions.
Install
-
npm install webdriver-server -
yarn add webdriver-server -
pnpm add webdriver-server
Imports
- Server
const Server = require('webdriver-server');import { Server } from 'webdriver-server'; - start
import Server from 'webdriver-server'; const server = new Server(); server.start();
import { start } from 'webdriver-server'; - WebdriverServerOptions
import type { WebdriverServerOptions } from 'webdriver-server';
Quickstart
import { Server } from 'webdriver-server';
import path from 'path';
// Ensure necessary browser drivers (e.g., chromedriver, geckodriver)
// are available in your system's PATH or explicitly configured.
// For example, you might install them globally or manage them with a tool like `webdriver-manager`.
async function startWebdriverServer() {
const options = {
port: 4444,
host: 'localhost',
logLevel: 'info', // Can be 'info', 'warn', 'error', 'debug'
// Additional options for driver paths, capabilities, etc., would be configured here
// based on the specific WebDriver client (e.g., Macaca, Selenium, Appium).
// Example (if server directly manages drivers, which is not typical for a generic server):
// chromeDriverPath: '/usr/local/bin/chromedriver',
};
try {
const server = new Server(options); // Instantiate the WebDriver server
await server.start(); // Start the server, making it listen for connections
console.log(`WebDriver Server started successfully on http://${options.host}:${options.port}`);
console.log('Press Ctrl+C to stop the server.');
// Keep the process alive indefinitely, typically for a CI/CD environment or background service
process.on('SIGINT', async () => {
console.log('\nShutting down WebDriver Server...');
await server.stop(); // Assuming a .stop() method exists for graceful shutdown
process.exit(0);
});
process.on('SIGTERM', async () => {
console.log('\nShutting down WebDriver Server...');
await server.stop();
process.exit(0);
});
} catch (error: any) {
console.error('Failed to start WebDriver Server:', error.message);
process.exit(1);
}
}
startWebdriverServer();