Adapters
What is an Adapter?
In software development, an adapter serves a similar purpose to its physical counterpart. Just like power sockets in different countries have varying shapes, adapters help bridge the gap. This is especially true when dealing with different technologies or platforms.
If you've traveled to various countries, you might have encountered power sockets with shapes that don't match your device's plug. An adapter allows you to connect your device to these sockets by changing the plug's form.
Test Maker classifies adapters into 3 categories:
- Web-based
- Mobile-based
- Unit-Based
Unit-Based Adapters
Unit-based adapters are designed to interact with various units in your application.
Configuration Example:
// Add your configuration example here for unit-based adapter
import { adapters, Configuration } from "test-maker";
const testMakerLocalConfig: Configuration = {
runner: {
adapters:[
adapters.unit,
]
},
};
export default testMakerLocalConfig;
Unit adapter is using node as a client. It has no visual interface. It's suitable to perform your API rest request.
Web-based Adapter: Playwright
Playwright is a web-based adapter that facilitates browser automation. It supports various browsers and provides powerful automation capabilities.
Configuration Example:
import { adapters, Configuration } from "test-maker";
const testMakerLocalConfig: Configuration = {
runner: {
adapters:[
adapters.playwright,
]
},
};
export default testMakerLocalConfig;
Example 2:
import { PlaywrightAdapterOptions, Configuration } from "test-maker";
const testMakerLocalConfig: Configuration = {
runner: {
adapters: [
{
name: `playwright`,
options: <PlaywrightAdapterOptions>{
default: true,
files: [
"./src/specs/tests/**/*-spec.ts",
],
clients: [
'chrome',
{
name: `safari`,
options: {
features: [`Safari client`],
files: [`./src/specs/browser-tests/*-spec.ts`]
}
}
]
}
}]
}
};
export default testMakerLocalConfig;
Advantages of Playwright
- Cross-Browser Compatibility: Playwright supports all modern rendering engines, making it easy to automate tests across different browsers like Chromium, Firefox, and WebKit.
- Concurrent Execution: Playwright allows you to run tests in parallel, significantly reducing the time needed to execute a suite of tests.
- Multi-Platform Support: Playwright supports major operating systems, including Windows, macOS, and Linux, allowing you to test your applications across different platforms.
Mobile-based Adapter: Appium
Appium is a mobile-based adapter for automating mobile applications, supporting both Android and iOS.
Configuration Example:
adapters: [
{
name: `appium`,
options: {
clients: [
{
name: `android:chrome`,
options: {
"appium:deviceName": `emulator-5556`,
}
}
]
}
}
]
Web-based Adapter: Selenium
Selenium is a web-based adapter commonly used for web automation, known for its popularity and widespread use.
Configuration Example:
// Add your configuration example here for Selenium
SauceLabs Adapter
SauceLabs is a cloud-based service that provides mobile-based testing solutions.
Configuration Example:
// Add your configuration example here for SauceLabs
adapters:[
{
name:`sauceLabs`,
options: {
connectionRetryTimeout: 120000,
connectionRetryCount: 0,
user: /*Saucelabs User*/,
key: /*Saucelabs Key*/,
region: `eu`,
clients: [
{
name: `android:chrome`,
options:{
"appium:deviceName": "Samsung_Galaxy_Tab_S8_real", //real device
"appium:platformVersion": "Android 12",
"sauce:options": {
appiumVersion: "1.22.1"
}
}
}
]
}
}
]
Interface Definitions
By organizing your content with subtitles and Markdown lists, you can enhance the readability and structure of your "Adapters" section. Adjust the
formatting and content as needed to fit your preferences and style guide.
TestMakerAdapterOptions
Property | Type | Description |
---|---|---|
default | boolean | Set as true for default options. |
clients | string[] | Client[] | List of clients or instances for the adapter. |
files | string[] | List of files for the adapter. |
features | string[] | List of features for the adapter. |
scenarios | string[] | List of scenarios for the adapter. |
steps | string[] | List of steps for the adapter. |
Client Interface
export interface Client extends Record<any, any> {
name: string;
alias?: string;
headless?: boolean;
args?: string[];
executablePath?: string;
options?: {
[key: string]: any;
} & AdapterClientFilter & {
proxy?: {
server: string;
bypass?: string[];
username?: string;
password?: string;
};
device?: Device;
};
}
Device Interface
export interface Device {
'name': string;
'userAgent': string;
'viewport': {
'width': number;
'height': number;
};
'deviceScaleFactor': number;
'isMobile': boolean;
'hasTouch': boolean;
'defaultBrowserType': string;
}
AdapterClientFilter Interface
export interface AdapterClientFilter {
files?: string[];
features?: string[];
scenarios?: string[];
steps?: string[];
}
Devices Type
export type Devices = {
[key in keyof typeof devicesList]: {
'name': string;
'userAgent': string;
'viewport': {
'width': number;
'height': number;
};
'deviceScaleFactor': number;
'isMobile': boolean;
'hasTouch': boolean;
'defaultBrowserType': string;
};
};
Devices List
The list of supported devices can be consulted on the following page: Device List.
PlaywrightAdapterOptions
Property | Type | Description |
---|---|---|
browser | object | Browser configuration options. |
customVersion | string | Custom version of Playwright. |
AppiumAdapterOptions
Property | Type | Description |
---|---|---|
host | string | Appium server host. |
path | string | Appium server path. |
port | number | Appium server port. |
protocol | string | Appium server protocol. |
logLevel | string | Log level for Appium. |
connectionRetryTimeout | number | Connection retry timeout for Appium. |
connectionRetryCount | number | Connection retry count for Appium. |
video | object | Video recording options. |
SeleniumAdapterOptions
Property | Type | Description |
---|---|---|
host | string | Selenium server host. |
path | string | Selenium server path. |
port | number | Selenium server port. |
protocol | string | Selenium server protocol. |
logLevel | string | Log level for Selenium. |
connectionRetryTimeout | number | Connection retry timeout for Selenium. |
connectionRetryCount | number | Connection retry count for Selenium. |