Files
ChannelTests-TS/test/config/Browserstack/BrowserstackApi.ts
Alexander Zinn e93eb5fe84 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.
2025-08-18 22:07:37 -04:00

30 lines
973 B
TypeScript

import type {SupportedBrowser} from './SupportedBrowser';
// Source: https://github.com/browserstack/api
export class BrowserstackApi {
private readonly _baseUrl: string = 'https://api.browserstack.com/5';
private readonly _authorizationHeader: string;
constructor(username: string, accessKey: string) {
this._authorizationHeader = `Basic ${Buffer.from(`${username}:${accessKey}`).toString('base64')}`;
}
public async getListOfSupportedBrowsers(): Promise<SupportedBrowser[]> {
const requestPath = `${this._baseUrl}/browsers?flat=true`;
const headers = {
Authorization: this._authorizationHeader,
'Content-Type': 'application/json',
Accept: 'application/json'
};
const response = await fetch(requestPath, {headers});
if (!response.ok) {
throw new Error(`Failed to fetch BrowserStack supported browsers due to [${response.statusText}]`);
}
return response.json() as Promise<SupportedBrowser[]>;
}
}