What is @appium/base-driver?
@appium/base-driver is a foundational package for creating Appium drivers. It provides a base class and a set of utilities that can be extended to create custom drivers for different platforms and automation needs.
What are @appium/base-driver's main functionalities?
BaseDriver Class
The BaseDriver class provides the core functionality for creating and managing sessions. By extending this class, you can implement custom logic for session creation and deletion.
const { BaseDriver } = require('@appium/base-driver');
class CustomDriver extends BaseDriver {
async createSession(capabilities) {
// Custom session creation logic
return super.createSession(capabilities);
}
async deleteSession() {
// Custom session deletion logic
return super.deleteSession();
}
}
module.exports = CustomDriver;
Command Handling
Command handling allows you to define custom endpoints and their corresponding logic. This is useful for implementing specific commands that your driver needs to support.
const { BaseDriver } = require('@appium/base-driver');
class CustomDriver extends BaseDriver {
constructor(opts) {
super(opts);
this.handlers = {
'/session/:sessionId/element': this.findElement.bind(this),
// Add more command handlers here
};
}
async findElement(sessionId, params) {
// Custom element finding logic
return { ELEMENT: 'element-id' };
}
}
module.exports = CustomDriver;
Proxying Commands
Proxying commands allows your driver to forward requests to another server. This is useful for scenarios where your driver needs to interact with an existing WebDriver server.
const { BaseDriver } = require('@appium/base-driver');
class CustomDriver extends BaseDriver {
constructor(opts) {
super(opts);
this.proxyReqRes = true; // Enable proxying
}
async proxyCommand(url, method, body) {
// Custom proxy logic
return await this.jwproxy.command(url, method, body);
}
}
module.exports = CustomDriver;
Other packages similar to @appium/base-driver
webdriverio
WebdriverIO is a popular automation framework that provides a high-level API for interacting with WebDriver servers. Unlike @appium/base-driver, which is focused on creating custom drivers, WebdriverIO is designed for writing and running tests.
selenium-webdriver
Selenium WebDriver is a widely-used library for browser automation. It provides a set of bindings for various programming languages to interact with WebDriver servers. While @appium/base-driver is focused on creating custom drivers, Selenium WebDriver is aimed at end-users writing automation scripts.
wd
The 'wd' package is a Node.js client for WebDriver/Selenium. It provides a promise-based API for interacting with WebDriver servers. Unlike @appium/base-driver, which is for creating drivers, 'wd' is for writing automation scripts.
@appium/base-driver
Base class for creating other Appium drivers
This is the parent class that all Appium drivers inherit from. This driver should not be installed
directly as it does nothing on its own. Instead, you should extend this driver when creating your
own Appium drivers. Check out the Building Drivers
documentation for more details.
Each included utility is documented in its own README:
License
Apache-2.0