Skip to content

Commit

Permalink
Merge pull request #70 from LambdaTest/stage
Browse files Browse the repository at this point in the history
Release v3.0.3
  • Loading branch information
riteshcgk authored Apr 12, 2024
2 parents f6d4a72 + d9b3ca3 commit c0b272d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lambdatest/smartui-cli",
"version": "3.0.2",
"version": "3.0.3",
"description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
"files": [
"dist/**/*"
Expand Down
6 changes: 6 additions & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export default {
EDGE_CHANNEL: 'msedge',
WEBKIT: 'webkit',

// user agents
CHROME_USER_AGENT: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.6312.107 Safari/537.3',
FIREFOX_USER_AGENT: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:112.0) Gecko/20100101 Firefox/112.0',
SAFARI_USER_AGENT: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15',
EDGE_USER_AGENT: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35',

// viewports
MIN_VIEWPORT_HEIGHT: 1080,

Expand Down
3 changes: 2 additions & 1 deletion src/lib/processSnapshot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Snapshot, Context, ProcessedSnapshot } from "../types.js";
import { scrollToBottomAndBackToTop, getRenderViewports } from "./utils.js"
import { chromium, Locator } from "@playwright/test"
import constants from "./constants.js";

const MAX_RESOURCE_SIZE = 5 * (1024 ** 2); // 5MB
var ALLOWED_RESOURCES = ['document', 'stylesheet', 'image', 'media', 'font', 'other'];
Expand All @@ -12,7 +13,7 @@ export default async (snapshot: Snapshot, ctx: Context): Promise<Record<string,
ctx.log.debug(`Processing snapshot ${snapshot.name}`);

if (!ctx.browser) ctx.browser = await chromium.launch({ headless: true });
const context = await ctx.browser.newContext()
const context = await ctx.browser.newContext({userAgent: constants.CHROME_USER_AGENT})
const page = await context.newPage();
let cache: Record<string, any> = {};

Expand Down
7 changes: 6 additions & 1 deletion src/lib/screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ async function captureScreenshotsForConfig(
let pageOptions = { waitUntil: process.env.SMARTUI_PAGE_WAIT_UNTIL_EVENT || 'load' };
let ssId = name.toLowerCase().replace(/\s/g, '_');
let context: BrowserContext;
let contextOptions: Record<string, any> = {};
let page: Page;
if (browserName == constants.CHROME) contextOptions.userAgent = constants.CHROME_USER_AGENT;
else if (browserName == constants.FIREFOX) contextOptions.userAgent = constants.FIREFOX_USER_AGENT;
else if (browserName == constants.SAFARI) contextOptions.userAgent = constants.SAFARI_USER_AGENT;
else if (browserName == constants.EDGE) contextOptions.userAgent = constants.EDGE_USER_AGENT;

try {
const browser = browsers[browserName];
context = await browser?.newContext();
context = await browser?.newContext(contextOptions);
page = await context?.newPage();

await page?.goto(url.trim(), pageOptions);
Expand Down

0 comments on commit c0b272d

Please sign in to comment.