Skip to content

Commit e726054

Browse files
authored
Merge pull request #275 from greydaemon/DOT-5128
[DOT-5128] added support for userAgent in cli capture
2 parents a43a778 + 31dfb43 commit e726054

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
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: 8 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"] },
@@ -226,6 +230,10 @@ const WebStaticConfigSchema: JSONSchemaType<WebStaticConfig> = {
226230
maximum: 30000,
227231
errorMessage: "waitForTimeout must be > 0 and <= 30000"
228232
},
233+
userAgent: {
234+
type: "string",
235+
errorMessage: "User Agent value must be a valid string"
236+
},
229237
execute: {
230238
type: "object",
231239
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 (urlConfig.userAgent !== "" && urlConfig.userAgent !== undefined) {
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
@@ -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;
@@ -174,7 +175,8 @@ export interface MobileConfig {
174175
export type WebStaticConfig = Array<{
175176
name: string;
176177
url: string;
177-
waitForTimeout?: number
178+
waitForTimeout?: number;
179+
userAgent?: string;
178180
}>;
179181

180182
export type FigmaConfigItem = {

0 commit comments

Comments
 (0)