Skip to content

Commit 3a81ac0

Browse files
Merge branch 'stage' into Dot-4961
2 parents 3c48a4f + 220aa1c commit 3a81ac0

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

src/lib/ctx.ts

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export default (options: Record<string, string>): Context => {
106106
skipBuildCreation: config.skipBuildCreation ?? false,
107107
tunnel: tunnelObj,
108108
tunnelName: config.tunnelName || ''
109+
userAgent: config.userAgent || ''
109110
},
110111
uploadFilePath: '',
111112
webStaticConfig: [],

src/lib/processSnapshot.ts

+1-3
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

+8
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ const ConfigSchema = {
248248
type: "string",
249249
errorMessage: "Invalid config; tunnelName must be string"
250250
},
251+
userAgent: {
252+
type: "string",
253+
errorMessage: "User Agent value must be a valid string"
254+
},
251255
},
252256
anyOf: [
253257
{ required: ["web"] },
@@ -278,6 +282,10 @@ const WebStaticConfigSchema: JSONSchemaType<WebStaticConfig> = {
278282
maximum: 30000,
279283
errorMessage: "waitForTimeout must be > 0 and <= 30000"
280284
},
285+
userAgent: {
286+
type: "string",
287+
errorMessage: "User Agent value must be a valid string"
288+
},
281289
execute: {
282290
type: "object",
283291
properties: {

src/lib/screenshot.ts

+10-2
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

+3-1
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)