Skip to content

Commit f399628

Browse files
Merge branch 'stage' into Dot-4961
2 parents f3073c5 + 220aa1c commit f399628

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

src/lib/ctx.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ export default (options: Record<string, string>): Context => {
104104
useGlobalCache: config.useGlobalCache ?? false,
105105
ignoreHTTPSErrors: config.ignoreHTTPSErrors ?? false,
106106
skipBuildCreation: config.skipBuildCreation ?? false,
107-
tunnel: tunnelObj
107+
tunnel: tunnelObj,
108+
userAgent: config.userAgent || ''
108109
},
109110
uploadFilePath: '',
110111
webStaticConfig: [],

src/lib/processSnapshot.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
180180
ctx.log.debug(`Resource had a disallowed status for retry as well ${requestUrl} disallowed status [${responseOfRetry.status()}]`);
181181
if (responseOfRetry && responseOfRetry.headers()) {
182182
const responseHeadersRetry = responseOfRetry.headers();
183-
ctx.log.debug(`Response headers for ${requestUrl}: ${JSON.stringify(responseHeadersRetry, null, 2)}`);
183+
ctx.log.debug(`Response headers for retry ${requestUrl}: ${JSON.stringify(responseHeadersRetry, null, 2)}`);
184184
}
185185

186186
let data = {
@@ -203,8 +203,6 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
203203
discoveryErrors.browsers[globalBrowser][globalViewport]?.push(data);
204204
}
205205
}
206-
207-
208206
} else {
209207
ctx.log.debug(`Handling request ${requestUrl}\n - content-type ${response.headers()['content-type']}`);
210208

src/lib/schemaValidation.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ const ConfigSchema = {
244244
required: ["type"],
245245
additionalProperties: false
246246
},
247+
userAgent: {
248+
type: "string",
249+
errorMessage: "User Agent value must be a valid string"
250+
},
247251
},
248252
anyOf: [
249253
{ required: ["web"] },
@@ -274,6 +278,10 @@ const WebStaticConfigSchema: JSONSchemaType<WebStaticConfig> = {
274278
maximum: 30000,
275279
errorMessage: "waitForTimeout must be > 0 and <= 30000"
276280
},
281+
userAgent: {
282+
type: "string",
283+
errorMessage: "User Agent value must be a valid string"
284+
},
277285
execute: {
278286
type: "object",
279287
properties: {

src/lib/screenshot.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ async function captureScreenshotsForConfig(
1616
): Promise<void> {
1717
ctx.log.debug(`*** urlConfig ${JSON.stringify(urlConfig)}`);
1818

19-
let {name, url, waitForTimeout, execute, pageEvent} = urlConfig;
19+
let {name, url, waitForTimeout, execute, pageEvent, userAgent} = urlConfig;
2020
let afterNavigationScript = execute?.afterNavigation;
2121
let beforeSnapshotScript = execute?.beforeSnapshot;
2222
let waitUntilEvent = pageEvent || process.env.SMARTUI_PAGE_WAIT_UNTIL_EVENT || 'load';
2323

24-
let pageOptions = { waitUntil: waitUntilEvent, timeout: ctx.config.waitForPageRender || constants.DEFAULT_PAGE_LOAD_TIMEOUT };
24+
let pageOptions = { waitUntil: waitUntilEvent, timeout: ctx.config.waitForPageRender || constants.DEFAULT_PAGE_LOAD_TIMEOUT};
2525
ctx.log.debug(`url: ${url} pageOptions: ${JSON.stringify(pageOptions)}`);
2626
let ssId = name.toLowerCase().replace(/\s/g, '_');
2727
let context: BrowserContext;
@@ -31,6 +31,14 @@ async function captureScreenshotsForConfig(
3131
else if (browserName == constants.FIREFOX) contextOptions.userAgent = constants.FIREFOX_USER_AGENT;
3232
else if (browserName == constants.SAFARI) contextOptions.userAgent = constants.SAFARI_USER_AGENT;
3333
else if (browserName == constants.EDGE) contextOptions.userAgent = constants.EDGE_USER_AGENT;
34+
if (ctx.config.userAgent || userAgent) {
35+
if(ctx.config.userAgent !== ""){
36+
contextOptions.userAgent = ctx.config.userAgent;
37+
}
38+
if (userAgent && userAgent !== "") {
39+
contextOptions.userAgent = userAgent;
40+
}
41+
}
3442

3543
try {
3644
const browser = browsers[browserName];

src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface Context {
3434
ignoreHTTPSErrors : boolean;
3535
skipBuildCreation?: boolean;
3636
tunnel: tunnelConfig | undefined;
37+
userAgent?: string;
3738
};
3839
uploadFilePath: string;
3940
webStaticConfig: WebStaticConfig;
@@ -175,7 +176,8 @@ export interface MobileConfig {
175176
export type WebStaticConfig = Array<{
176177
name: string;
177178
url: string;
178-
waitForTimeout?: number
179+
waitForTimeout?: number;
180+
userAgent?: string;
179181
}>;
180182

181183
export type FigmaConfigItem = {

0 commit comments

Comments
 (0)