From ac6dd8ea1ff354dfb6ec0c5041c1d4c280a1055f Mon Sep 17 00:00:00 2001 From: ismail Date: Fri, 19 Apr 2024 12:05:34 +0200 Subject: [PATCH] Changes on playwright test --- tests/openvidu-angular-web-tutorial.spec.js | 3 +- tests/openvidu-getaroom-test.spec.js | 4 +- tests/openvidu-hello-world-test.spec.js | 6 +- tests/openvidu-iframe-tutorial.spec.js | 3 +- .../openvidu-js-screen-share-tutorial.spec.js | 6 +- tests/openvidu-js-web-tutorial.spec.js | 13 ++- tests/openvidu-react-web-tutorial.spec.js | 3 +- .../openvidu-recording-java-tutorial.spec.js | 3 +- .../openvidu-recording-node-tutorial.spec.js | 2 +- tests/openvidu-vue-tutorial.spec.js | 85 +++++++++++-------- 10 files changed, 76 insertions(+), 52 deletions(-) diff --git a/tests/openvidu-angular-web-tutorial.spec.js b/tests/openvidu-angular-web-tutorial.spec.js index 4aa95fa9..0cb9c872 100644 --- a/tests/openvidu-angular-web-tutorial.spec.js +++ b/tests/openvidu-angular-web-tutorial.spec.js @@ -6,7 +6,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a const browser = await chromium.launch({ headless: true, deviceScaleFactor: 1, - userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36', + userAgent: 'Chrome/88.0.4324.182', args: ["--use-fake-ui-for-media-stream", "--use-fake-device-for-media-stream"] }); @@ -20,6 +20,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a const page2 = await context.newPage(); try { + // Navigate to the specified URL on page1. await page1.goto('http://localhost:4200'); diff --git a/tests/openvidu-getaroom-test.spec.js b/tests/openvidu-getaroom-test.spec.js index 97705078..40e2f935 100644 --- a/tests/openvidu-getaroom-test.spec.js +++ b/tests/openvidu-getaroom-test.spec.js @@ -5,7 +5,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a const browser = await chromium.launch({ headless: true, deviceScaleFactor: 1, - userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36', + userAgent: 'Chrome/88.0.4324.182', args: ["--use-fake-ui-for-media-stream", "--use-fake-device-for-media-stream"] }); @@ -20,7 +20,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a try { // Navigate to the specified URL on page1. - await page1.goto('http://127.0.0.1:8080'); + await page1.goto('http://localhost:8080'); // Wait for the 'button.btn-success' to be present on the page, with a timeout of 10 seconds. await page1.waitForSelector('button.btn-success', { timeout: 10000 }); diff --git a/tests/openvidu-hello-world-test.spec.js b/tests/openvidu-hello-world-test.spec.js index 2da5c82a..59bf061e 100644 --- a/tests/openvidu-hello-world-test.spec.js +++ b/tests/openvidu-hello-world-test.spec.js @@ -5,7 +5,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a const browser = await chromium.launch({ headless: true, deviceScaleFactor: 1, - userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36', // Specify the user agent + userAgent: 'Chrome/88.0.4324.182', // Specify the user agent args: ["--use-fake-ui-for-media-stream", "--use-fake-device-for-media-stream"] }); @@ -20,7 +20,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a try { // Navigate to a specific URL on page 1. - await page1.goto('http://127.0.0.1:8080'); + await page1.goto('http://localhost:8080'); // Interact with page1, such as clicking a button and waiting for a specific element to become visible, then wait for a timeout.. @@ -32,7 +32,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a await page1.screenshot({ path: '../results/screenshots/page1_screenshot.png' }); // Navigate to a specific URL on page 1. - await page2.goto('http://127.0.0.1:8080'); + await page2.goto('http://localhost:8080'); // Interact with page2 and wait for a specific element to become visible, then wait for a timeout. await page2.click('#join input[type="submit"]'); diff --git a/tests/openvidu-iframe-tutorial.spec.js b/tests/openvidu-iframe-tutorial.spec.js index faaf9858..a405edff 100644 --- a/tests/openvidu-iframe-tutorial.spec.js +++ b/tests/openvidu-iframe-tutorial.spec.js @@ -5,7 +5,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a const browser = await chromium.launch({ headless: true, deviceScaleFactor: 1, // Specify the page's scale factor - userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36', // Specify the user agent + userAgent: 'Chrome/88.0.4324.182', // Specify the user agent args: ["--use-fake-ui-for-media-stream", "--use-fake-device-for-media-stream"] }); @@ -19,6 +19,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a const page2 = await context.newPage(); try { + // Navigate to the specified URL on page1. await page1.goto('http://localhost:8081/'); diff --git a/tests/openvidu-js-screen-share-tutorial.spec.js b/tests/openvidu-js-screen-share-tutorial.spec.js index d6eede6c..7b4a3057 100644 --- a/tests/openvidu-js-screen-share-tutorial.spec.js +++ b/tests/openvidu-js-screen-share-tutorial.spec.js @@ -5,7 +5,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a const browser = await chromium.launch({ headless: true, deviceScaleFactor: 1, // Specify the page's scale factor - userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36', // Specify the user agent + userAgent: 'Chrome/88.0.4324.182', // Specify the user agent args: ["--use-fake-ui-for-media-stream", "--use-fake-device-for-media-stream"] }); @@ -20,7 +20,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a try { // Navigate to the specified URL on page1. - await page1.goto('http://127.0.0.1:8080'); + await page1.goto('http://localhost:8080'); // Fill in the '#userName' field with 'Page1', click the 'JOIN' button, and wait for the '#session' element to become visible. await page1.fill('#userName', 'Page1'); @@ -32,7 +32,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a await page1.screenshot({ path: '../results/screenshots/page1.png' }); // Navigate to the specified URL on page2. - await page2.goto('http://127.0.0.1:8080'); + await page2.goto('http://localhost:8080'); // Fill in the '#userName' field with 'Page2', click the 'JOIN' button, wait for the '#buttonScreenShare' element to become visible, and click it. await page2.fill('#userName', 'Page2'); diff --git a/tests/openvidu-js-web-tutorial.spec.js b/tests/openvidu-js-web-tutorial.spec.js index ee5ef1f9..0045a59c 100644 --- a/tests/openvidu-js-web-tutorial.spec.js +++ b/tests/openvidu-js-web-tutorial.spec.js @@ -5,9 +5,9 @@ const { test, expect, chromium } = require('@playwright/test'); test('Checking for the presence of two active webcams in an OpenVidu session', async () => { // Launch a headless Chromium browser with specific settings. const browser = await chromium.launch({ - headless: true, + headless: false, deviceScaleFactor: 1, // Specify the page's scale factor - userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36', // Specify the user agent + userAgent: 'Chrome/88.0.4324.182', // Specify the user agent args: ["--use-fake-ui-for-media-stream", "--use-fake-device-for-media-stream"] }); @@ -30,9 +30,16 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a await page1.waitForSelector('#session', { visible: true }); await page1.waitForTimeout(5000); + // Find HTML elements within page2 that contain video streams. + var videoElements = await page1.$$('video'); + + expect(videoElements.length).toEqual(2); + // Capture a screenshot of page1 and save it to a specific location. await page1.screenshot({ path: '../results/screenshots/page1.png' }); + + // Navigate to a specific URL on page2. await page2.goto('http://localhost:8080'); @@ -46,7 +53,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a await page2.screenshot({ path: '../results/screenshots/page2.png' }); // Find HTML elements within page2 that contain video streams. - const videoElements = await page2.$$('video'); + videoElements = await page2.$$('video'); // Check that there are exactly three elements found. expect(videoElements.length).toEqual(3); diff --git a/tests/openvidu-react-web-tutorial.spec.js b/tests/openvidu-react-web-tutorial.spec.js index 4d933d00..04730358 100644 --- a/tests/openvidu-react-web-tutorial.spec.js +++ b/tests/openvidu-react-web-tutorial.spec.js @@ -7,7 +7,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a const browser = await chromium.launch({ headless: true, deviceScaleFactor: 1, // Specify the page's scale factor - userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36', // Specify the user agent + userAgent: 'Chrome/88.0.4324.182', // Specify the user agent args: ["--use-fake-ui-for-media-stream", "--use-fake-device-for-media-stream"] }); @@ -21,6 +21,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a const page2 = await context.newPage(); try { + // Navigate to a specific URL on page1. await page1.goto('http://localhost:3000'); diff --git a/tests/openvidu-recording-java-tutorial.spec.js b/tests/openvidu-recording-java-tutorial.spec.js index 31b2080b..82c7486b 100644 --- a/tests/openvidu-recording-java-tutorial.spec.js +++ b/tests/openvidu-recording-java-tutorial.spec.js @@ -4,7 +4,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a const browser = await chromium.launch({ headless: true, deviceScaleFactor: 1, - userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36', + userAgent: 'Chrome/88.0.4324.182', args: ["--use-fake-ui-for-media-stream", "--use-fake-device-for-media-stream", "--ignore-certificate-errors"] }); @@ -19,6 +19,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a const page2 = await context2.newPage(); try { + await page1.goto('https://localhost:5000'); await page1.click('#join-btn'); diff --git a/tests/openvidu-recording-node-tutorial.spec.js b/tests/openvidu-recording-node-tutorial.spec.js index ac6ff398..b8ae5b03 100644 --- a/tests/openvidu-recording-node-tutorial.spec.js +++ b/tests/openvidu-recording-node-tutorial.spec.js @@ -4,7 +4,7 @@ test('Checking for the presence of two active webcams in an OpenVidu session', a const browser = await chromium.launch({ headless: true, deviceScaleFactor: 1, - userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36', + userAgent: 'Chrome/88.0.4324.182', args: ["--use-fake-ui-for-media-stream", "--use-fake-device-for-media-stream", "--ignore-certificate-errors"] }); diff --git a/tests/openvidu-vue-tutorial.spec.js b/tests/openvidu-vue-tutorial.spec.js index 39b484c6..11c53c21 100644 --- a/tests/openvidu-vue-tutorial.spec.js +++ b/tests/openvidu-vue-tutorial.spec.js @@ -3,40 +3,53 @@ const { test, expect, chromium } = require('@playwright/test'); test('Checking for the presence of two active webcams in an OpenVidu session', async () => { -const browser = await chromium.launch({ headless: true , deviceScaleFactor: 1, - userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36', - args : ["--use-fake-ui-for-media-stream", "--use-fake-device-for-media-stream"] - }); - - const context = await browser.newContext({ - permissions: ['camera', 'microphone'], - }); - - const page1 = await context.newPage(); - await page1.goto('http://localhost:8080'); - await page1.fill('input[type="text"]', 'User1'); - await page1.click('button.btn.btn-lg.btn-success'); - await page1.waitForSelector('#session', { visible: true }); - - const page2 = await context.newPage(); - - await page2.goto('http://localhost:8080'); - await page2.fill('input[type="text"]', 'User2'); - await page2.click('button.btn.btn-lg.btn-success'); - await page2.waitForSelector('#session', { visible: true }); - await page2.waitForTimeout(5000); - - await page1.screenshot({ path: 'page1.png' }); - await page2.screenshot({ path: 'page2.png' }); - - // Buscar los elementos HTML que contienen los streams de video - const videoElements = await page2.$$('video'); - - // Comprobar que hay exactamente dos elementos encontrados - expect(videoElements.length).toEqual(3); - - // Cerrar las páginas y el navegador. - - await Promise.all([page1.close(), page2.close()]); - await browser.close(); + const browser = await chromium.launch({ + headless: true, deviceScaleFactor: 1, + userAgent: 'Chrome/88.0.4324.182', + args: ["--use-fake-ui-for-media-stream", "--use-fake-device-for-media-stream"] + }); + + const context = await browser.newContext({ + permissions: ['camera', 'microphone'], + }); + + const page1 = await context.newPage(); + const page2 = await context.newPage(); + + try { + await page1.goto('http://localhost:8080'); + await page1.fill('input[type="text"]', 'User1'); + await page1.click('button.btn.btn-lg.btn-success'); + await page1.waitForSelector('#session', { visible: true }); + + + await page2.goto('http://localhost:8080'); + await page2.fill('input[type="text"]', 'User2'); + await page2.click('button.btn.btn-lg.btn-success'); + await page2.waitForSelector('#session', { visible: true }); + await page2.waitForTimeout(5000); + + await page1.screenshot({ path: 'page1.png' }); + await page2.screenshot({ path: 'page2.png' }); + + // Buscar los elementos HTML que contienen los streams de video + const videoElements = await page2.$$('video'); + + // Comprobar que hay exactamente dos elementos encontrados + expect(videoElements.length).toEqual(3); + + // Cerrar las páginas y el navegador. + + await Promise.all([page1.close(), page2.close()]); + await browser.close(); + + } catch (error) { + + // En caso de error, captura las pantallas y registra el error + await page1.screenshot({ path: '../results/screenshots/error_page1_screenshot.png' }); + await page2.screenshot({ path: '../results/screenshots/error_page2_screenshot.png' }); + throw error; // Lanza el error nuevamente para que el test falle + } + + });