UNPKG

@appium/base-driver

Version:

Base driver class for Appium drivers

83 lines 3.11 kB
import type { AppiumLogger, HTTPBody, HTTPHeaders, HTTPMethod, ProxyOptions, ProxyResponse } from '@appium/types'; import { PROTOCOLS } from '../constants'; import { ProtocolConverter } from './protocol-converter'; import http from 'node:http'; import https from 'node:https'; import type { Request, Response } from 'express'; type Protocol = (typeof PROTOCOLS)[keyof typeof PROTOCOLS]; export declare class JWProxy { readonly scheme: string; readonly server: string; readonly port: number; readonly base: string; readonly reqBasePath: string; sessionId: string | null; timeout: number; readonly headers: HTTPHeaders | undefined; readonly httpAgent: http.Agent; readonly httpsAgent: https.Agent; readonly protocolConverter: ProtocolConverter; private _downstreamProtocol; private _activeRequests; private readonly _log; constructor(opts?: ProxyOptions); get log(): AppiumLogger; /** * Gets the protocol used by the downstream server (W3C or MJSONWP). */ get downstreamProtocol(): Protocol | null | undefined; /** * Sets the protocol used by the downstream server (W3C or MJSONWP). */ set downstreamProtocol(value: Protocol | null | undefined); /** * Returns the number of active downstream HTTP requests. */ getActiveRequestsCount(): number; /** * Cancels all currently active downstream HTTP requests. */ cancelActiveRequests(): void; /** * Builds a full downstream URL (including base path and session) for a given upstream URL. */ getUrlForProxy(url: string, method?: HTTPMethod): string; /** * Proxies a raw WebDriver command to the downstream server. */ proxy(url: string, method: string, body?: HTTPBody): Promise<[ProxyResponse, HTTPBody]>; /** * Detects the downstream protocol from a response body. */ getProtocolFromResBody(resObj: Record<string, unknown>): Protocol | undefined; /** * Proxies a command identified by its HTTP method and URL to the downstream server. */ proxyCommand(url: string, method: HTTPMethod, body?: HTTPBody): Promise<[ProxyResponse, HTTPBody]>; /** * Executes a WebDriver command and returns the unwrapped `value` field (or throws). */ command(url: string, method: HTTPMethod, body?: HTTPBody): Promise<HTTPBody>; /** * Extracts a session id from a WebDriver-style URL. */ getSessionIdFromUrl(url: string): string | null; /** * Proxies an Express `Request`/`Response` pair to the downstream server, * converting any downstream errors into a proper W3C HTTP response. * * This method must not throw; it always writes a response. */ proxyReqRes(req: Request, res: Response): Promise<void>; /** * Performs requests to the downstream server * * @private - Do not call this method directly, * it uses client-specific arguments and responses! */ private request; private _parseUrl; private _toNormalizedPathname; } export {}; //# sourceMappingURL=proxy.d.ts.map