Enhance CommandLine and TestConfiguration for improved option validation and logging
* 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.
This commit is contained in:
@@ -1,36 +1,33 @@
|
||||
import {browser} from '@wdio/globals';
|
||||
import {browser as wdio} from '@wdio/globals';
|
||||
|
||||
export type PageOptions = {
|
||||
browser?: typeof browser; // MultiRemote usecase
|
||||
browser?: typeof wdio; // MultiRemote usecase
|
||||
};
|
||||
|
||||
export type PageOpenOptions = {
|
||||
queryParameters?: Record<string, string | number>;
|
||||
isNewTabRequest?: boolean;
|
||||
endpoint?: string;
|
||||
requestPath?: string;
|
||||
};
|
||||
|
||||
export default class Page {
|
||||
private readonly _baseUrl: string;
|
||||
private readonly _browser: typeof wdio;
|
||||
|
||||
constructor(baseUrl: string) {
|
||||
constructor(baseUrl: string, browser: typeof wdio) {
|
||||
this._baseUrl = baseUrl;
|
||||
this._browser = browser;
|
||||
}
|
||||
|
||||
public async open(options: PageOpenOptions = {}): Promise<void> {
|
||||
const {queryParameters, isNewTabRequest, endpoint, requestPath} = options;
|
||||
const {queryParameters, isNewTabRequest, requestPath} = options;
|
||||
|
||||
// Build the URL path properly
|
||||
let pageUrl = this._baseUrl;
|
||||
if (endpoint) {
|
||||
pageUrl += `/${endpoint}`;
|
||||
}
|
||||
|
||||
if (requestPath) {
|
||||
pageUrl += `/${requestPath}`;
|
||||
}
|
||||
|
||||
// Add query parameters if they exist
|
||||
if (queryParameters && Object.keys(queryParameters).length > 0) {
|
||||
const queryString = Object.entries(queryParameters)
|
||||
.map(([queryParameterName, queryParameterValue]) => `${queryParameterName}=${queryParameterValue}`)
|
||||
@@ -39,9 +36,9 @@ export default class Page {
|
||||
}
|
||||
|
||||
if (isNewTabRequest) {
|
||||
await (browser as any).newWindow(pageUrl);
|
||||
await (this._browser as any).newWindow(pageUrl);
|
||||
} else {
|
||||
await (browser as any).url(pageUrl);
|
||||
await (this._browser as any).url(pageUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {$} from '@wdio/globals';
|
||||
import {browser as wdio, $} from '@wdio/globals';
|
||||
import Page, {PageOpenOptions} from './Page';
|
||||
|
||||
export class SubscribingPage extends Page {
|
||||
constructor(baseUri: string) {
|
||||
super(baseUri);
|
||||
constructor(baseUri: string, browser: typeof wdio) {
|
||||
super(baseUri, browser);
|
||||
}
|
||||
|
||||
get videoElement() {
|
||||
@@ -13,4 +13,4 @@ export class SubscribingPage extends Page {
|
||||
public override async open(options?: PageOpenOptions): Promise<void> {
|
||||
await super.open(options);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user