Skip to content

Commit 5d04ea0

Browse files
karanshah-browserstackfrancisf
authored andcommitted
Modify to override page fixture instead of override browser
1 parent a278d2f commit 5d04ea0

11 files changed

+17
-25
lines changed

playwright-test/fixtures.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ exports.BS_LOCAL_ARGS = {
2929
};
3030

3131
// Patching the capabilities dynamically according to the project name.
32-
const patchCaps = (name) => {
32+
const patchCaps = (name, title) => {
3333
let combination = name.split(/@browserstack/)[0];
3434
let [browerCaps, osCaps] = combination.split(/:/);
3535
let [browser, browser_version] = browerCaps.split(/@/);
@@ -40,32 +40,23 @@ const patchCaps = (name) => {
4040
caps.browser_version = browser_version ? browser_version : 'latest';
4141
caps.os = os ? os : 'osx';
4242
caps.os_version = os_version ? os_version : 'catalina';
43-
caps.name = name;
43+
caps.name = title;
4444
};
4545

4646
const isHash = (entity) => Boolean(entity && typeof(entity) === "object" && !Array.isArray(entity));
4747
const nestedKeyValue = (hash, keys) => keys.reduce((hash, key) => (isHash(hash) ? hash[key] : undefined), hash);
4848

4949
exports.test = base.test.extend({
50-
browser: async ({ playwright, browser }, use, workerInfo) => {
50+
page: async ({ page, playwright }, use, testInfo) => {
5151
// Use BrowserStack Launched Browser according to capabilities for cross-browser testing.
52-
if (workerInfo.project.name.match(/browserstack/)) {
53-
patchCaps(workerInfo.project.name);
52+
if (testInfo.project.name.match(/browserstack/)) {
53+
patchCaps(testInfo.project.name, `${testInfo.file} - ${testInfo.title}`);
5454
const vBrowser = await playwright.chromium.connect({
5555
wsEndpoint:
5656
`wss://cdp.browserstack.com/playwright?caps=` +
5757
`${encodeURIComponent(JSON.stringify(caps))}`,
5858
});
59-
await use(vBrowser);
60-
} else {
61-
// Use Local Browser for testing.
62-
await use(browser);
63-
}
64-
},
65-
page: async ({ page, browser }, use, testInfo) => {
66-
// Overriding page function to mark the status on BrowserStack.
67-
if (testInfo.project.name.match(/browserstack/)) {
68-
const vPage = await browser.newPage();
59+
const vPage = await vBrowser.newPage();
6960
await use(vPage);
7061
const testResult = {
7162
action: 'setSessionStatus',
@@ -77,6 +68,7 @@ exports.test = base.test.extend({
7768
await vPage.evaluate(() => {},
7869
`browserstack_executor: ${JSON.stringify(testResult)}`);
7970
await vPage.close();
71+
await vBrowser.close();
8072
} else {
8173
use(page);
8274
}

playwright-test/tests/test_1.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { test } = require('../fixtures');
22
const { expect } = require('@playwright/test');
33
test.describe('feature foo', () => {
4-
test('my test', async ({ page }) => {
4+
test('test 1', async ({ page }) => {
55
// Assertions use the expect API.
66
await page.goto('https://www.google.com/ncr');
77
const element = await page.$('[aria-label="Search"]');

playwright-test/tests/test_10.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { test } = require('../fixtures');
22
const { expect } = require('@playwright/test');
33
test.describe('feature foo', () => {
4-
test('my test', async ({ page }) => {
4+
test('test 10', async ({ page }) => {
55
// Assertions use the expect API.
66
await page.goto('https://www.duckduckgo.com');
77
const element = await page.$('[name="q"]');

playwright-test/tests/test_2.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { test } = require('../fixtures');
22
const { expect } = require('@playwright/test');
33
test.describe('feature foo', () => {
4-
test('my test', async ({ page }) => {
4+
test('test 2', async ({ page }) => {
55
// Assertions use the expect API.
66
await page.goto('https://www.duckduckgo.com');
77
const element = await page.$('[name="q"]');

playwright-test/tests/test_3.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { test } = require('../fixtures');
22
const { expect } = require('@playwright/test');
33
test.describe('feature foo', () => {
4-
test('my test', async ({ page }) => {
4+
test('test 3', async ({ page }) => {
55
// Assertions use the expect API.
66
await page.goto('https://www.duckduckgo.com');
77
const element = await page.$('[name="q"]');

playwright-test/tests/test_4.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { test } = require('../fixtures');
22
const { expect } = require('@playwright/test');
33
test.describe('feature foo', () => {
4-
test('my test', async ({ page }) => {
4+
test('test 4', async ({ page }) => {
55
// Assertions use the expect API.
66
await page.goto('https://www.duckduckgo.com');
77
const element = await page.$('[name="q"]');

playwright-test/tests/test_5.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { test } = require('../fixtures');
22
const { expect } = require('@playwright/test');
33
test.describe('feature foo', () => {
4-
test('my test', async ({ page }) => {
4+
test('test 5', async ({ page }) => {
55
// Assertions use the expect API.
66
await page.goto('https://www.duckduckgo.com');
77
const element = await page.$('[name="q"]');

playwright-test/tests/test_6.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { test } = require('../fixtures');
22
const { expect } = require('@playwright/test');
33
test.describe('feature foo', () => {
4-
test('my test', async ({ page }) => {
4+
test('test 6', async ({ page }) => {
55
// Assertions use the expect API.
66
await page.goto('https://www.duckduckgo.com');
77
const element = await page.$('[name="q"]');

playwright-test/tests/test_7.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { test } = require('../fixtures');
22
const { expect } = require('@playwright/test');
33
test.describe('feature foo', () => {
4-
test('my test', async ({ page }) => {
4+
test('test 7', async ({ page }) => {
55
// Assertions use the expect API.
66
await page.goto('https://www.duckduckgo.com');
77
const element = await page.$('[name="q"]');

playwright-test/tests/test_8.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { test } = require('../fixtures');
22
const { expect } = require('@playwright/test');
33
test.describe('feature foo', () => {
4-
test('my test', async ({ page }) => {
4+
test('test 8', async ({ page }) => {
55
// Assertions use the expect API.
66
await page.goto('https://www.duckduckgo.com');
77
const element = await page.$('[name="q"]');

playwright-test/tests/test_9.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { test } = require('../fixtures');
22
const { expect } = require('@playwright/test');
33
test.describe('feature foo', () => {
4-
test('my test', async ({ page }) => {
4+
test('test 9', async ({ page }) => {
55
// Assertions use the expect API.
66
await page.goto('https://www.duckduckgo.com');
77
const element = await page.$('[name="q"]');

0 commit comments

Comments
 (0)