Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/types/src/browser-proxy/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ export const enum BrowserProxyActions {
isStable = 'isStable',
waitForEnabled = 'waitForEnabled',
waitForStable = 'waitForStable',
setCustomBrowserClientConfig = 'setCustomBrowserClientConfig',
getCustomBrowserClientConfig = 'getCustomBrowserClientConfig',
}
1 change: 1 addition & 0 deletions core/types/src/web-application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface IWebApplicationConfig {
screenshotsEnabled: boolean;
screenshotPath: string;
devtool: null | IDevtoolRuntimeConfiguration;
seleniumConfig?: any;
}

export type WindowFeatureBoolean = 'yes' | 'no';
Expand Down
1,542 changes: 781 additions & 761 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions packages/e2e-test-app/src/mock-web-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const upload = multer({storage: multer.memoryStorage()});

export class MockWebServer {
private httpServerInstance: Http.Server;
private static seleniumHubHeaders: Http.IncomingHttpHeaders[] = [];

start(): Promise<void> {
return new Promise<void>((resolve) => {
Expand Down Expand Up @@ -39,6 +40,29 @@ export class MockWebServer {
});
});

// mock any request that contains /wd/hub
app.all('/wd/hub/*', (req, res) => {
// get request headers
const headers = req.headers;
// store headers for later use
MockWebServer.seleniumHubHeaders.push(headers);
res.status(200).json({
status: 0,
value: {
sessionId: 'mock-session-id',
capabilities: {
browserName: 'mock-browser',
platformName: 'mock-platform',
},
},
});
});

// endpoint to retrieve stored headers
app.get('/selenium-headers', (req, res) => {
res.status(200).json(MockWebServer.seleniumHubHeaders);
});

return app;
}
}
30 changes: 30 additions & 0 deletions packages/e2e-test-app/test/selenium/test/set-custom-config.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {run} from 'testring';

run(async (api) => {
const app = api.application;
await app.client.setCustomBrowserClientConfig({
hostname: 'localhost',
port: 8080,
headers: {
'X-Testring-Custom-Header': 'TestringCustomValue',
},
});
const config = await app.client.getCustomBrowserClientConfig();
await app.assert.equal(
config.headers['X-Testring-Custom-Header'],
'TestringCustomValue',
);
await app.url('https://example.com');
// make api request to localhost:8080/selenium-headers to retrieve captured headers
const response = await api.http.get({
url: 'http://localhost:8080/selenium-headers',
});
const parsedResponse = JSON.parse(response);
await app.assert.isAbove(parsedResponse.length, 0);
for (let capturedHeaders of parsedResponse) {
await app.assert.equal(
capturedHeaders['x-testring-custom-header'],
'TestringCustomValue',
);
}
});
22 changes: 22 additions & 0 deletions packages/plugin-selenium-driver/src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {ClickOptions, MockFilterOptions} from 'webdriverio';
import type {JsonCompatible} from '@wdio/types';
import type {RespondWithOptions} from 'webdriverio/build/utils/interception/types';
import webdriver from 'webdriver';
import {WebdriverIOConfig} from '@wdio/types/build/Capabilities';

type BrowserObjectCustom = WebdriverIO.Browser & {
sessionId: string;
Expand Down Expand Up @@ -75,6 +76,8 @@ export class SeleniumPlugin implements IBrowserProxyPlugin {

private browserClients: Map<string, browserClientItem> = new Map();

private customBrowserClientsConfigs: Map<string, WebdriverIOConfig> = new Map();

private waitForReadyState: Promise<void> = Promise.resolve();

private localSelenium: ChildProcess;
Expand Down Expand Up @@ -268,6 +271,22 @@ export class SeleniumPlugin implements IBrowserProxyPlugin {
}
}

public setCustomBrowserClientConfig(
applicant: string,
config: WebdriverIOConfig,
) {
this.customBrowserClientsConfigs.set(
applicant,
config
);
}

public getCustomBrowserClientConfig(
applicant: string,
) {
return this.customBrowserClientsConfigs.get(applicant);
}

private async createClient(
applicant: string,
config?: Partial<WebdriverIO.Config>,
Expand All @@ -294,6 +313,7 @@ export class SeleniumPlugin implements IBrowserProxyPlugin {
{},
this.config,
(config as any) || {},
this.customBrowserClientsConfigs.get(applicant) || {},
]);
const client = await remote(_config);

Expand Down Expand Up @@ -425,6 +445,7 @@ export class SeleniumPlugin implements IBrowserProxyPlugin {
await delay(this.config.delayAfterSessionClose);
}
this.browserClients.delete(applicant);
this.customBrowserClientsConfigs.delete(applicant);
}

public async kill() {
Expand Down Expand Up @@ -1109,6 +1130,7 @@ export class SeleniumPlugin implements IBrowserProxyPlugin {

await client.deleteSession();
this.browserClients.delete(applicant);
this.customBrowserClientsConfigs.delete(applicant);
await this.createClient(applicant, {
capabilities: {
'goog:chromeOptions': {
Expand Down
5 changes: 5 additions & 0 deletions packages/web-application/src/web-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export class WebApplication extends PluggableModule {
return `Wait for stable ${this.formatXpath(xpath)} for ${timeout}`;
},
};
private initPromise: Promise<any> = Promise.resolve();

constructor(
protected testUID: string,
Expand All @@ -317,6 +318,9 @@ export class WebApplication extends PluggableModule {
super();
this.config = this.getConfig(config);
this.decorateMethods();
if (config.seleniumConfig) {
this.initPromise = this.client.setCustomBrowserClientConfig(this.config.seleniumConfig);
}
}

protected getConfig(
Expand Down Expand Up @@ -348,6 +352,7 @@ export class WebApplication extends PluggableModule {

// eslint-disable-next-line no-async-promise-executor
const promise = new Promise(async (resolve, reject) => {
await this.initPromise;
const logger = self.logger;
const message = logFn.apply(self, args);
let result;
Expand Down
8 changes: 8 additions & 0 deletions packages/web-application/src/web-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ export class WebClient implements IWebApplicationClient {
return this.makeRequest(BrowserProxyActions.refresh, []);
}

public setCustomBrowserClientConfig(config) {
return this.makeRequest(BrowserProxyActions.setCustomBrowserClientConfig, [config]);
}

public getCustomBrowserClientConfig() {
return this.makeRequest(BrowserProxyActions.getCustomBrowserClientConfig, []);
}

public getHubConfig() {
return this.makeRequest(BrowserProxyActions.getHubConfig, []);
}
Expand Down