From 719bb0af5d2906f3f7766f69f5052573dfc9d2d4 Mon Sep 17 00:00:00 2001 From: jwrob Date: Thu, 7 Nov 2024 17:20:39 +0100 Subject: [PATCH] waiting for event with 3 layers added; also improved event collecting --- .../features/simulcast.feature | 2 +- .../src/stepsImpl/viewerSelect.step.impl.ts | 4 ++ .../stepsImpl/viewerVerification.step.impl.ts | 3 +- .../src/support-utils/events.ts | 47 ++++++++++++++----- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/packages/millicast-sdk/integration-tests/features/simulcast.feature b/packages/millicast-sdk/integration-tests/features/simulcast.feature index 180eb849..c7c421e6 100644 --- a/packages/millicast-sdk/integration-tests/features/simulcast.feature +++ b/packages/millicast-sdk/integration-tests/features/simulcast.feature @@ -1,7 +1,7 @@ Feature: Simulcast Feature - Scenario: Publisher connects with simulcast and viewer subscribes to layers event + Scenario: Publisher connects with simulcast and viewer select layers Given the "publisher1" opens "Publisher" app When the "publisher1" starts the stream with the specified options | codec | h264 | diff --git a/packages/millicast-sdk/integration-tests/src/stepsImpl/viewerSelect.step.impl.ts b/packages/millicast-sdk/integration-tests/src/stepsImpl/viewerSelect.step.impl.ts index d1730c7c..837b4c36 100644 --- a/packages/millicast-sdk/integration-tests/src/stepsImpl/viewerSelect.step.impl.ts +++ b/packages/millicast-sdk/integration-tests/src/stepsImpl/viewerSelect.step.impl.ts @@ -1,4 +1,5 @@ import { ScenarioWorld, logger, runStep } from "cucumber-playwright-framework"; +import { getListOfActorsEvents, waitForEventLayers } from "../support-utils/events"; export async function viewerSelectLayer( scenarioWorld: ScenarioWorld, @@ -7,6 +8,9 @@ export async function viewerSelectLayer( ) { logger.debug(`viewerSelectLayer function was called`); + await getListOfActorsEvents(scenarioWorld,actor) + await waitForEventLayers(scenarioWorld,actor) + await runStep([ `the ${actor} switch to the "Viewer" app`, `the ${actor} executes the "window.millicastView.select({encodingId:"${encodingId}"})" JavaScript function on the page`, diff --git a/packages/millicast-sdk/integration-tests/src/stepsImpl/viewerVerification.step.impl.ts b/packages/millicast-sdk/integration-tests/src/stepsImpl/viewerVerification.step.impl.ts index 23ea63f8..3fb92b1e 100644 --- a/packages/millicast-sdk/integration-tests/src/stepsImpl/viewerVerification.step.impl.ts +++ b/packages/millicast-sdk/integration-tests/src/stepsImpl/viewerVerification.step.impl.ts @@ -187,9 +187,10 @@ export async function verifyViwerVideoResolutionForLayer( width = layer["width"] } } - + if (!height || !width) {throw Error(`Resolution values are missing for layer with encodingId ${encodingId}`)} await runStep([ `the ${actor} switch to the "Viewer" app`, + `the ${actor} waits for "5" seconds`, `the "TestUtil.getResolution('${playerId}')[0]" JavaScript function result should be ${height}`, `the "TestUtil.getResolution('${playerId}')[1]" JavaScript function result should be ${width}`, ], scenarioWorld); diff --git a/packages/millicast-sdk/integration-tests/src/support-utils/events.ts b/packages/millicast-sdk/integration-tests/src/support-utils/events.ts index 2e6bf837..c90ae599 100644 --- a/packages/millicast-sdk/integration-tests/src/support-utils/events.ts +++ b/packages/millicast-sdk/integration-tests/src/support-utils/events.ts @@ -1,27 +1,48 @@ import { ScenarioWorld } from "cucumber-playwright-framework"; import { WebSocket } from "playwright"; +import { retryUntilTrue } from "./generic"; export async function collectWsEvents(scenarioWorld:ScenarioWorld, actor:string) { + //init events collection (array) for actor + scenarioWorld.localDataStore.save(actor+"_eventsList",[]) + scenarioWorld.page.on('websocket', (ws:WebSocket) => { ws.on('framereceived', (event:any) => { const payloadJson = JSON.parse(event.payload); - if (payloadJson["name"] === "active") { - scenarioWorld.localDataStore.save(actor+"_event_"+Date.now(), payloadJson); - } - if (payloadJson["name"] === "layers") { - scenarioWorld.localDataStore.save(actor+"_event_"+Date.now(), payloadJson); + if (payloadJson["name"] === "active" || payloadJson["name"] === "layers") { + const actorsEventList: Array = scenarioWorld.localDataStore.load(actor+"_eventsList") + actorsEventList.push(payloadJson) + scenarioWorld.localDataStore.save(actor+"_eventsList", actorsEventList) } }); } )} +export async function getListOfActorsEvents(scenarioWorld: ScenarioWorld, actor: string) { + return scenarioWorld.localDataStore.load(actor+"_eventsList") +} + +export async function waitForEventLayers(scenarioWorld: ScenarioWorld, actor: string) { + const verifyMethod = async (): Promise => { + const eventsList: any = await getListOfActorsEvents(scenarioWorld, actor); + let eventPresent = false; + for (const myEvent of eventsList) { + if(myEvent["name"] === "layers" && myEvent["data"]["medias"]["0"]["layers"].length === 3) { + eventPresent = true + console.log("3 Layers Found") + } + } return(eventPresent) as boolean + } + await retryUntilTrue(verifyMethod, 20) +} + export async function getLayersFromEvent(scenarioWorld: ScenarioWorld, actor: string) { - const allevents: Map = scenarioWorld.localDataStore.getAllData(); + const eventsList: any = await getListOfActorsEvents(scenarioWorld, actor); let layers:Array = []; - allevents.forEach((value, key) => { - if(key.includes("event") && value["name"] === "layers"){ - layers = value["data"]["medias"]["0"]["layers"] - } - }); - return layers; - } \ No newline at end of file + for (const myEvent of eventsList) { + if(myEvent["name"] === "layers" && myEvent["data"]["medias"]["0"]["layers"].length === 3) { + layers = myEvent["data"]["medias"]["0"]["layers"] + } + } if (layers) {return layers} + else {throw Error('No layers found')} +} \ No newline at end of file