* Added validation for required command line options in the `CommandLine` class to ensure necessary parameters are provided. * Updated `TestConfiguration` to store and expose the logging level from command line options. * Refactored `BrowserstackApi` to improve method naming and added content type headers for API requests. * Changed `SupportedBrowser` type to be exported for better accessibility. * Updated `Page` and `SubscribingPage` classes to use a consistent browser import and improved constructor parameters.
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import {browser as wdio} from '@wdio/globals';
|
|
|
|
export type PageOptions = {
|
|
browser?: typeof wdio; // MultiRemote usecase
|
|
};
|
|
|
|
export type PageOpenOptions = {
|
|
queryParameters?: Record<string, string | number>;
|
|
isNewTabRequest?: boolean;
|
|
requestPath?: string;
|
|
};
|
|
|
|
export default class Page {
|
|
private readonly _baseUrl: string;
|
|
private readonly _browser: typeof wdio;
|
|
|
|
constructor(baseUrl: string, browser: typeof wdio) {
|
|
this._baseUrl = baseUrl;
|
|
this._browser = browser;
|
|
}
|
|
|
|
public async open(options: PageOpenOptions = {}): Promise<void> {
|
|
const {queryParameters, isNewTabRequest, requestPath} = options;
|
|
|
|
let pageUrl = this._baseUrl;
|
|
|
|
if (requestPath) {
|
|
pageUrl += `/${requestPath}`;
|
|
}
|
|
|
|
if (queryParameters && Object.keys(queryParameters).length > 0) {
|
|
const queryString = Object.entries(queryParameters)
|
|
.map(([queryParameterName, queryParameterValue]) => `${queryParameterName}=${queryParameterValue}`)
|
|
.join('&');
|
|
pageUrl += `?${queryString}`;
|
|
}
|
|
|
|
if (isNewTabRequest) {
|
|
await (this._browser as any).newWindow(pageUrl);
|
|
} else {
|
|
await (this._browser as any).url(pageUrl);
|
|
}
|
|
}
|
|
}
|