Skip to content

Commit e995785

Browse files
authored
Merge pull request #276 from greydaemon/DOT-5128-prod
DOT-5128 : Changes for custom user agent and bumped cli version to 8
2 parents 4f0673a + 31e1588 commit e995785

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/smartui-cli",
3-
"version": "4.1.7",
3+
"version": "4.1.8",
44
"description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
55
"files": [
66
"dist/**/*"

src/lib/ctx.ts

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

src/lib/schemaValidation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ const WebStaticConfigSchema: JSONSchemaType<WebStaticConfig> = {
211211
maximum: 30000,
212212
errorMessage: "waitForTimeout must be > 0 and <= 30000"
213213
},
214+
userAgent: {
215+
type: "string",
216+
errorMessage: "User Agent value must be a valid string"
217+
},
214218
execute: {
215219
type: "object",
216220
properties: {

src/lib/screenshot.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ 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';
@@ -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
skipBuildCreation?: boolean;
3535
tunnel?: boolean;
3636
tunnelName?: string;
37+
userAgent?: string;
3738
};
3839
uploadFilePath: string;
3940
webStaticConfig: WebStaticConfig;
@@ -173,7 +174,8 @@ export interface MobileConfig {
173174
export type WebStaticConfig = Array<{
174175
name: string;
175176
url: string;
176-
waitForTimeout?: number
177+
waitForTimeout?: number;
178+
userAgent?: string;
177179
}>;
178180

179181
export type FigmaConfigItem = {

0 commit comments

Comments
 (0)