* Added `@wdio/cli` as a development dependency for improved test command handling. * Refactored URL construction in the `Page` class to enhance clarity and maintainability. * Updated import statements in `Subscribing.page.ts` for consistency and removed unnecessary options in the constructor.
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import {browser} from '@wdio/globals';
|
|
|
|
export type PageOptions = {
|
|
browser?: typeof browser; // MultiRemote usecase
|
|
};
|
|
|
|
export type PageOpenOptions = {
|
|
queryParameters?: Record<string, string | number>;
|
|
isNewTabRequest?: boolean;
|
|
endpoint?: string;
|
|
requestPath?: string;
|
|
};
|
|
|
|
export default class Page {
|
|
private readonly _baseUrl: string;
|
|
|
|
constructor(baseUrl: string) {
|
|
this._baseUrl = baseUrl;
|
|
}
|
|
|
|
public async open(options: PageOpenOptions = {}): Promise<void> {
|
|
const {queryParameters, isNewTabRequest, endpoint, 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}`)
|
|
.join('&');
|
|
pageUrl += `?${queryString}`;
|
|
}
|
|
|
|
if (isNewTabRequest) {
|
|
await (browser as any).newWindow(pageUrl);
|
|
} else {
|
|
await (browser as any).url(pageUrl);
|
|
}
|
|
}
|
|
}
|