diff --git a/package-lock.json b/package-lock.json index b65a43a19..2d7a2324c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,7 @@ }, "devDependencies": { "@babel/eslint-parser": "^7.16.5", + "@playwright/test": "^1.44.1", "@wdio/browserstack-service": "^8.29.0", "@wdio/cli": "^8.29.0", "@wdio/concise-reporter": "^8.29.0", @@ -94,6 +95,7 @@ "morgan": "^1.10.0", "node-html-parser": "^6.1.5", "opn": "^5.4.0", + "playwright": "^1.44.1", "resolve-from": "^5.0.0", "sinon": "^4.1.3", "through2": "^4.0.2", diff --git a/package.json b/package.json index b7a1e1baf..06bee5a0b 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ }, "devDependencies": { "@babel/eslint-parser": "^7.16.5", + "@playwright/test": "^1.44.1", "@wdio/browserstack-service": "^8.29.0", "@wdio/cli": "^8.29.0", "@wdio/concise-reporter": "^8.29.0", @@ -104,6 +105,7 @@ "morgan": "^1.10.0", "node-html-parser": "^6.1.5", "opn": "^5.4.0", + "playwright": "^1.44.1", "resolve-from": "^5.0.0", "sinon": "^4.1.3", "through2": "^4.0.2", diff --git a/playwright.config.js b/playwright.config.js new file mode 100644 index 000000000..b15af2e18 --- /dev/null +++ b/playwright.config.js @@ -0,0 +1,79 @@ +// @ts-check +const { defineConfig, devices } = require('@playwright/test'); + +/** + * Read environment variables from file. + * https://github.com/motdotla/dotenv + */ +// require('dotenv').config(); + +/** + * @see https://playwright.dev/docs/test-configuration + */ +module.exports = defineConfig({ + testDir: './tests', + /* Run tests in files in parallel */ + 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: 'html', + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use: { + /* Base URL to use in actions like `await page.goto('/')`. */ + // baseURL: 'http://127.0.0.1:3000', + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: 'on-first-retry', + }, + + /* Configure projects for major browsers */ + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + + { + name: 'firefox', + use: { ...devices['Desktop Firefox'] }, + }, + + { + name: 'webkit', + use: { ...devices['Desktop Safari'] }, + }, + + /* Test against mobile viewports. */ + // { + // name: 'Mobile Chrome', + // use: { ...devices['Pixel 5'] }, + // }, + // { + // name: 'Mobile Safari', + // use: { ...devices['iPhone 12'] }, + // }, + + /* Test against branded browsers. */ + // { + // name: 'Microsoft Edge', + // use: { ...devices['Desktop Edge'], channel: 'msedge' }, + // }, + // { + // name: 'Google Chrome', + // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, + // }, + ], + + /* Run your local dev server before starting the tests */ + // webServer: { + // command: 'npm run start', + // url: 'http://127.0.0.1:3000', + // reuseExistingServer: !process.env.CI, + // }, +}); + diff --git a/tests/prebid.test.js b/tests/prebid.test.js new file mode 100644 index 000000000..847cf68d6 --- /dev/null +++ b/tests/prebid.test.js @@ -0,0 +1,42 @@ +const {test, expect} = require('@playwright/test'); + +test('win events', async ({page}) => { + + // Set up a listener for network requests + let networkEventFound = false; + let requestUrl = ''; + let responseStatus = null; + + page.on('request', (request) => { + if (request.url().includes('recommendations.notify-win-nurl')) { + networkEventFound = true; + requestUrl = request.url(); + } + }); + + page.on('response', async (response) => { + if (response.url().includes('recommendations.notify-win-nurl')) { + responseStatus = response.status(); + } + }); + + // Navigate to the URL + await page.goto('http://prebid.audex.svc.kube.taboolasyndication.com:9999/integrationExamples/gpt/hello_world.html'); + + // Wait for some time to ensure all network requests are captured + await page.waitForTimeout(5000); // Wait for 5 seconds or adjust as needed + + // Check if the network event was found and its status + if (networkEventFound) { + if (responseStatus !== null) { + console.log(`Network event with "recommendations.notify-win-nurl" found Status: ${responseStatus}`); + await expect(responseStatus).toEqual(204); + } else { + console.log('Network event with "recommendations.notify-win-nurl" found, but no response status captured.'); + } + } else { + console.log('Network event with "recommendations.notify-win-nurl" not found.'); + } + +}); +