Remove browserstack harness, run playwright directly

ua-device-type
Uku Taht 4 years ago
parent 42c45e131a
commit 8d3bc09c06

@ -7,27 +7,18 @@ on:
- 'tracker/**'
jobs:
build:
name: Build and test
test:
timeout-minutes: 15
runs-on: buildjet-4vcpu-ubuntu-2004
steps:
- uses: actions/checkout@v2
- name: Read .tool-versions
uses: marocchino/tool-versions-action@v1
id: versions
- name: Set up Node
uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{steps.versions.outputs.nodejs}}
- name: 'BrowserStack Env Setup'
uses: 'browserstack/github-actions/setup-env@master'
with:
username: ${{ secrets.BROWSERSTACK_USERNAME }}
access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
build-name: 'BUILD_INFO'
- run: npm install --prefix ./tracker
- run: npm run deploy --prefix ./tracker
- name: "Install Playwright dependencies"
node-version: 16
- name: Install dependencies
run: npm --prefix ./tracker ci
- name: Install Playwright Browsers
working-directory: ./tracker
run: npx playwright install-deps
- run: npm --prefix ./tracker test
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npm --prefix ./tracker test

File diff suppressed because it is too large Load Diff

@ -1,16 +1,15 @@
{
"scripts": {
"deploy": "node compile.js",
"test": "npm run deploy && BROWSERSTACK_LOCAL=true npx playwright test --config=./test/support/playwright.config.js"
"test": "npm run deploy && npx playwright test --config=./test/support/playwright.config.js",
"start": "node test/support/server.js"
},
"license": "MIT",
"dependencies": {
"@playwright/test": "^1.22.2",
"browserstack-local": "^1.4.8",
"@playwright/test": "^1.31.0",
"express": "^4.18.1",
"generatorics": "^1.1.0",
"handlebars": "^4.7.7",
"playwright": "^1.22.2",
"uglify-js": "^3.9.4"
},
"devDependencies": {

@ -1,6 +1,5 @@
const { test } = require('./support/harness');
const { mockRequest, mockManyRequests, expectCustomEvent } = require('./support/test-utils');
const { expect } = require('@playwright/test');
const { expect, test } = require('@playwright/test');
const { LOCAL_SERVER_ADDR } = require('./support/server');

@ -1,17 +1,16 @@
const { test } = require('./support/harness');
const { mockRequest, expectCustomEvent, isMac, mockManyRequests } = require('./support/test-utils');
const { expect } = require('@playwright/test');
const { mockRequest, expectCustomEvent, mockManyRequests } = require('./support/test-utils');
const { expect, test } = require('@playwright/test');
const { LOCAL_SERVER_ADDR } = require('./support/server');
test.describe('file-downloads extension', () => {
test('sends event and does not start download when link opens in new tab', async ({ page }, workerInfo) => {
test('sends event and does not start download when link opens in new tab', async ({ page }) => {
await page.goto('/file-download.html')
const downloadURL = await page.locator('#link').getAttribute('href')
const plausibleRequestMock = mockRequest(page, '/api/event')
const downloadRequestMock = mockRequest(page, downloadURL)
await page.click('#link', { modifiers: [isMac(workerInfo) ? 'Meta' : 'Control'] })
await page.click('#link', { modifiers: ['Meta'] })
expectCustomEvent(await plausibleRequestMock, 'File Download', { url: downloadURL })
expect(await downloadRequestMock, "should not make download request").toBeNull()

@ -1,6 +1,5 @@
const { test } = require('./support/harness');
const { mockRequest } = require('./support/test-utils')
const { expect } = require('@playwright/test');
const { expect, test } = require('@playwright/test');
test.describe('combination of hash and exclusions script extensions', () => {
test('excludes by hash part of the URL', async ({ page }) => {

@ -1,17 +1,16 @@
const { test } = require('./support/harness')
const { mockRequest, isMac, expectCustomEvent } = require('./support/test-utils')
const { expect } = require('@playwright/test');
const { mockRequest, expectCustomEvent } = require('./support/test-utils')
const { expect, test } = require('@playwright/test');
test.describe('outbound-links extension', () => {
test('sends event and does not navigate when link opens in new tab', async ({ page }, workerInfo) => {
test('sends event and does not navigate when link opens in new tab', async ({ page }) => {
await page.goto('/outbound-link.html')
const outboundURL = await page.locator('#link').getAttribute('href')
const plausibleRequestMock = mockRequest(page, '/api/event')
const navigationRequestMock = mockRequest(page, outboundURL)
await page.click('#link', { modifiers: [isMac(workerInfo) ? 'Meta' : 'Control'] })
await page.click('#link', { modifiers: ['Meta'] })
expectCustomEvent(await plausibleRequestMock, 'Outbound Link: Click', { url: outboundURL })
expect(await navigationRequestMock, "should not have made navigation request").toBeNull()

@ -1,6 +1,5 @@
const { test } = require('./support/harness');
const { mockRequest } = require('./support/test-utils')
const { expect } = require('@playwright/test');
const { expect, test } = require('@playwright/test');
test.describe('Basic installation', () => {
test('Sends pageview automatically', async ({ page }) => {

@ -1,16 +0,0 @@
const BrowserStackLocal = require('browserstack-local');
exports.bsLocal = new BrowserStackLocal.Local();
exports.BS_LOCAL_ARGS = {
key: process.env.BROWSERSTACK_ACCESS_KEY
};
exports.ensureCredentials = function() {
if (!process.env.BROWSERSTACK_ACCESS_KEY) {
throw 'Please configure process.env.BROWSERSTACK_ACCESS_KEY'
}
if (!process.env.BROWSERSTACK_USERNAME) {
throw 'Please configure process.env.BROWSERSTACK_USERNAME'
}
}

@ -1,30 +0,0 @@
// global-setup.js
const { bsLocal, ensureCredentials, BS_LOCAL_ARGS } = require('./browserstack');
const { promisify } = require('util');
const { runLocalFileServer } = require('./server')
const sleep = promisify(setTimeout);
const redColour = '\x1b[31m';
const whiteColour = '\x1b[0m';
ensureCredentials()
module.exports = async () => {
console.log('Starting BrowserStackLocal ...');
runLocalFileServer()
// Starts the Local instance with the required arguments
let localResponseReceived = false;
bsLocal.start(BS_LOCAL_ARGS, (err) => {
if (err) {
console.error(
`${redColour}Error starting BrowserStackLocal${whiteColour}`
);
} else {
console.log('BrowserStackLocal Started');
}
localResponseReceived = true;
});
while (!localResponseReceived) {
await sleep(1000);
}
};

@ -1,19 +0,0 @@
// global-teardown.js
const { bsLocal } = require('./browserstack');
const { promisify } = require('util');
const sleep = promisify(setTimeout);
module.exports = async () => {
// Stop the Local instance after your test run is completed, i.e after driver.quit
let localStopped = false;
if (bsLocal && bsLocal.isRunning()) {
bsLocal.stop(() => {
localStopped = true;
console.log('Stopped BrowserStackLocal');
});
while (!localStopped) {
await sleep(1000);
}
}
};

@ -1,92 +0,0 @@
const base = require('@playwright/test');
const cp = require('child_process');
const clientPlaywrightVersion = cp
.execSync('npx playwright --version')
.toString()
.trim()
.split(' ')[1];
// BrowserStack Specific Capabilities.
const caps = {
browser: 'chrome',
os: 'osx',
os_version: 'catalina',
name: 'My first playwright test',
build: process.env.BROWSERSTACK_BUILD_NAME || `local-build-${new Date().getTime()}`,
'browserstack.username': process.env.BROWSERSTACK_USERNAME || 'YOUR_USERNAME',
'browserstack.accessKey':
process.env.BROWSERSTACK_ACCESS_KEY || 'YOUR_ACCESS_KEY',
'browserstack.local': process.env.BROWSERSTACK_LOCAL || false,
'client.playwrightVersion': clientPlaywrightVersion,
'browserstack.debug': true,
'browserstack.networkLogs': true,
'browserstack.networkLogsOptions': {
"captureContent": "true"
}
};
// Patching the capabilities dynamically according to the project name.
const patchCaps = (name, title) => {
let combination = name.split(/@browserstack/)[0];
let [browerCaps, osCaps] = combination.split(/:/);
let [browser, browser_version] = browerCaps.split(/@/);
let osCapsSplit = osCaps.split(/ /);
let os = osCapsSplit.shift();
let os_version = osCapsSplit.join(' ');
caps.browser = browser;
if (browser.includes('playwright-')) {
caps['browserstack.playwrightVersion'] = browser_version;
} else {
caps.browser_version = browser_version;
}
caps.os = os;
caps.os_version = os_version;
caps.name = title;
};
const isHash = (entity) => Boolean(entity && typeof(entity) === "object" && !Array.isArray(entity));
const nestedKeyValue = (hash, keys) => keys.reduce((hash, key) => (isHash(hash) ? hash[key] : undefined), hash);
const isUndefined = val => (val === undefined || val === null || val === '');
const evaluateSessionStatus = (status) => {
if (!isUndefined(status)) {
status = status.toLowerCase();
}
if (status === "passed") {
return "passed";
} else if (status === "failed" || status === "timedout") {
return "failed";
} else {
return "";
}
}
exports.test = base.test.extend({
page: async ({ page, playwright }, use, testInfo) => {
// Use BrowserStack Launched Browser according to capabilities for cross-browser testing.
if (testInfo.project.name.match(/browserstack/)) {
patchCaps(testInfo.project.name, `${testInfo.file} - ${testInfo.title}`);
const vBrowser = await playwright.chromium.connect({
wsEndpoint:
`wss://cdp.browserstack.com/playwright?caps=` +
`${encodeURIComponent(JSON.stringify(caps))}`,
});
const vContext = await vBrowser.newContext(testInfo.project.use);
const vPage = await vContext.newPage();
await use(vPage);
const testResult = {
action: 'setSessionStatus',
arguments: {
status: evaluateSessionStatus(testInfo.status),
reason: nestedKeyValue(testInfo, ['error', 'message'])
},
};
await vPage.evaluate(() => {},
`browserstack_executor: ${JSON.stringify(testResult)}`);
await vPage.close();
await vBrowser.close();
} else {
use(page);
}
},
});

@ -1,102 +1,46 @@
// playwright.config.js
// @ts-check
const { LOCAL_SERVER_ADDR } = require('./server')
const { devices } = require('@playwright/test');
/** @type {import('@playwright/test').PlaywrightTestConfig} */
const config = {
/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = {
testDir: '../',
testMatch: '**/*.spec.js',
// Use globalSetup & globalTearedown only if browserstack.local = true
globalSetup: require.resolve('./global-setup'),
globalTeardown: require.resolve('./global-teardown'),
timeout: 60000,
retries: 2,
timeout: 30 * 1000,
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'list',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
viewport: null,
baseURL: LOCAL_SERVER_ADDR
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://localhost:3000',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},
projects: [
// -- BrowserStack Projects --
// name should be of the format 'browser@browser_version:os os_version@browserstack'
// use playwright version (or '1.latest') instead of browser version for `playwright-browser`.
// see which playwright versions use which browser versions:
// https://www.browserstack.com/docs/automate/playwright/playwright-browser-compatibility
//
// supported os and browser options:
// https://www.browserstack.com/docs/automate/playwright/browsers-and-os
// Chrome on Mac
{
name: 'chrome@latest:OSX Monterey@browserstack',
use: {
browserName: 'chromium',
channel: 'chrome'
},
},
{
name: 'chrome@86:OSX Mojave@browserstack',
use: {
browserName: 'chromium',
channel: 'chrome'
},
},
// Chrome on Windows
{
name: 'chrome@latest:Windows 11@browserstack',
use: {
browserName: 'chromium',
channel: 'chrome'
},
},
{
name: 'chrome@86:Windows 10@browserstack',
use: {
browserName: 'chromium',
channel: 'chrome'
},
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
// Firefox on Mac
{
name: 'playwright-firefox@1.latest:OSX Big Sur@browserstack',
use: {
browserName: 'firefox',
},
},
{
name: 'playwright-firefox@1.18.1:OSX Catalina@browserstack',
use: {
browserName: 'firefox',
},
},
// Firefox on Windows
{
name: 'playwright-firefox@1.latest:Windows 11@browserstack',
use: {
browserName: 'firefox',
},
},
{
name: 'playwright-firefox@1.18.1:Windows 10@browserstack',
use: {
browserName: 'firefox',
},
},
// Safari on Mac
{
name: 'playwright-webkit@1.latest:OSX Monterey@browserstack',
use: {
browserName: 'webkit',
},
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
{
name: 'playwright-webkit@1.19.1:OSX Big Sur@browserstack',
use: {
browserName: 'webkit',
},
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
],
};
module.exports = config;
webServer: {
command: 'npm run start',
port: 3000,
},
}

@ -32,10 +32,6 @@ exports.mockManyRequests = function(page, path, numberOfRequests) {
})
}
exports.isMac = function (workerInfo) {
return workerInfo.project.name.includes('OSX')
}
exports.expectCustomEvent = function (request, eventName, eventProps) {
const payload = request.postDataJSON()

@ -1,6 +1,5 @@
const { test } = require('./support/harness')
const { mockRequest, mockManyRequests, isMac, expectCustomEvent } = require('./support/test-utils')
const { expect } = require('@playwright/test')
const { mockRequest, mockManyRequests, expectCustomEvent } = require('./support/test-utils')
const { expect, test } = require('@playwright/test')
test.describe('tagged-events extension', () => {
test('tracks a tagged link click with custom props + url prop', async ({ page }) => {
@ -37,14 +36,14 @@ test.describe('tagged-events extension', () => {
expectCustomEvent(requests[0], "Form Submit", {})
});
test('tracks click and auxclick on any tagged HTML element', async ({ page }, workerInfo) => {
test('tracks click and auxclick on any tagged HTML element', async ({ page }) => {
await page.goto('/tagged-event.html')
const plausibleRequestMockList = mockManyRequests(page, '/api/event', 3)
await page.click('#button')
await page.click('#span')
await page.click('#div', { modifiers: [isMac(workerInfo) ? 'Meta' : 'Control'] })
await page.click('#div', { modifiers: ['Meta'] })
const requests = await plausibleRequestMockList
expect(requests.length).toBe(3)
@ -68,12 +67,12 @@ test.describe('tagged-events extension', () => {
expect((await navigationRequestMock).url()).toContain(linkURL)
});
test('tracks tagged HTML elements when their child element is clicked', async ({ page }, workerInfo) => {
test('tracks tagged HTML elements when their child element is clicked', async ({ page }) => {
await page.goto('/tagged-event.html')
const plausibleRequestMockList = mockManyRequests(page, '/api/event', 2)
await page.click('#h2-with-link-parent', { modifiers: [isMac(workerInfo) ? 'Meta' : 'Control'] })
await page.click('#h2-with-link-parent', { modifiers: ['Meta'] })
await page.click('#link-with-div-parent')
const requests = await plausibleRequestMockList

Loading…
Cancel
Save