Skip to content

Commit d24dc6f

Browse files
committed
added support for custom userAgent in cli capture
1 parent cbf7d4b commit d24dc6f

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

src/lib/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export default {
3131
{
3232
"name": "lambdatest-home-page",
3333
"url": "https://www.lambdatest.com",
34-
"waitForTimeout": 1000
34+
"waitForTimeout": 1000,
35+
"userAgent" : ""
3536
},
3637
{
3738
"name": "example-page",

src/lib/schemaValidation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ const WebStaticConfigSchema: JSONSchemaType<WebStaticConfig> = {
230230
maximum: 30000,
231231
errorMessage: "waitForTimeout must be > 0 and <= 30000"
232232
},
233+
userAgent: {
234+
type: "string",
235+
errorMessage: "User Agent value must be a valid string"
236+
},
233237
execute: {
234238
type: "object",
235239
properties: {

src/lib/screenshot.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ 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 if (ctx.config.userAgent || urlConfig.userAgent) {
35-
contextOptions.userAgent = ctx.config.userAgent;
36-
if (urlConfig.userAgent !== null) {
37-
contextOptions.userAgent = urlConfig.userAgent;
34+
if (ctx.config.userAgent || urlConfig.userAgent) {
35+
if(ctx.config.userAgent !== ""){
36+
contextOptions.userAgent = ctx.config.userAgent;}
37+
if (urlConfig.userAgent !== "") {
38+
contextOptions.userAgent = userAgent;
3839
}
3940
}
4041

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ export interface MobileConfig {
175175
export type WebStaticConfig = Array<{
176176
name: string;
177177
url: string;
178-
waitForTimeout?: number
178+
waitForTimeout?: number;
179+
userAgent?: string;
179180
}>;
180181

181182
export type FigmaConfigItem = {

0 commit comments

Comments
 (0)