Skip to content

Commit 6fcdd91

Browse files
committed
added support for userAgent in cli capture
1 parent a43a778 commit 6fcdd91

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

src/lib/ctx.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ export default (options: Record<string, string>): Context => {
101101
ignoreHTTPSErrors: config.ignoreHTTPSErrors ?? false,
102102
skipBuildCreation: config.skipBuildCreation ?? false,
103103
tunnel: config.tunnel ?? false,
104-
tunnelName: config.tunnelName || ''
104+
tunnelName: config.tunnelName || '',
105+
userAgent: config.userAgent || '',
105106
},
106107
uploadFilePath: '',
107108
webStaticConfig: [],

src/lib/schemaValidation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ const ConfigSchema = {
196196
type: "string",
197197
errorMessage: "Invalid config; tunnelName must be string"
198198
},
199+
userAgent: {
200+
type: "string",
201+
errorMessage: "Invalid config; userAgent must be string"
202+
},
199203
},
200204
anyOf: [
201205
{ required: ["web"] },

src/lib/screenshot.ts

Lines changed: 8 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 , userAgent : ctx.config.userAgent};
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,12 @@ 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+
else {
35+
contextOptions.userAgent = pageOptions.userAgent;
36+
if(pageOptions.userAgent === null) {
37+
contextOptions.userAgent = userAgent;
38+
}
39+
}
3440

3541
try {
3642
const browser = browsers[browserName];

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface Context {
3535
skipBuildCreation?: boolean;
3636
tunnel?: boolean;
3737
tunnelName?: string;
38+
userAgent?: string;
3839
};
3940
uploadFilePath: string;
4041
webStaticConfig: WebStaticConfig;

0 commit comments

Comments
 (0)