Skip to content

Commit

Permalink
Added TestUtil.js; added methods for video/audio present/not present …
Browse files Browse the repository at this point in the history
…verification, added methods video active/not active verification
  • Loading branch information
jwrobdolby committed Oct 21, 2024
1 parent 573000e commit f40d47c
Show file tree
Hide file tree
Showing 6 changed files with 702 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Feature: Connect Feature
And the "viewer1" connected stream should be LIVE
And the "viewer1" should be able to view media tracks for the connected stream

Scenario: EXPECTED FAIL - Publisher Connects With disableVideo as <disableVideo> and disableAudio as <disableAudio>
Scenario: Publisher Connects With disableVideo as <disableVideo> and disableAudio as <disableAudio> - Expected Fail: DIOS-7279
Given the "publisher1" opens "Publisher" app
When the "publisher1" starts the stream with the specified options
| disableVideo | <disableVideo> |
Expand Down Expand Up @@ -121,8 +121,3 @@ Feature: Connect Feature
Scenario: Viewer Reconnects During The Stream
Given the "publisher1" starts the stream and should be LIVE
Given the "viewer1" connects to the published stream and should be LIVE

# Scenario: Publisher Connects with simulcast: true
# Then viewer1 verify if all layers are available
# Scenario: Publisher Connects with sourceId defined
# Scenario: Publisher Connects with recording enabled
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export async function openViewerApp(
],
scenarioWorld,
);

const jsFile = 'packages/millicast-sdk/integration-tests/src/support-utils/TestUtil.js'
await runStep(`the ${actor} adds the "${jsFile}" JavaScript file to the page`, scenarioWorld)
}

export async function openPublisherApp(
Expand All @@ -28,4 +31,7 @@ export async function openPublisherApp(
],
scenarioWorld,
);

const jsFile = 'packages/millicast-sdk/integration-tests/src/support-utils/TestUtil.js'
await runStep(`the ${actor} adds the "${jsFile}" JavaScript file to the page`, scenarioWorld)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DataTable } from "@cucumber/cucumber";
import { runStep, runSteps, ScenarioWorld } from "cucumber-playwright-framework";
import { retryUntilFalse, retryUntilTrue } from "../support-utils/generic";

export async function verifyViewerIsLive(
scenarioWorld: ScenarioWorld,
Expand All @@ -23,14 +24,93 @@ export async function verifyViewerIsNotLive(
], scenarioWorld);
}

async function verifyVideoIsActive(scenarioWorld: ScenarioWorld, actor: string, playerId: string) {
const verifyMethod = async (): Promise<boolean> => {
return (await runStep(
`the ${actor} executes the "TestUtil.isVideoActive('${playerId}')" JavaScript function on the page`,
scenarioWorld
)) as boolean
}
const isPlaying = await retryUntilTrue(verifyMethod)
if (!isPlaying) {
throw Error(`Stream is not playing - for ${playerId} playerID and isPlaying is ${isPlaying}`)
}
}

async function verifyVideoIsNotActive(scenarioWorld: ScenarioWorld, actor: string, playerId: string) {
const verifyMethod = async (): Promise<boolean> => {
return (await runStep(
`the ${actor} executes the "TestUtil.isVideoActive('${playerId}')" JavaScript function on the page`,
scenarioWorld
)) as boolean
}
const isPlaying = await retryUntilFalse(verifyMethod)
if (isPlaying) {
throw Error(`Stream is playing - for ${playerId} playerID and isPlaying is ${isPlaying}`)
}
}

export async function verifyVideoPresent(scenarioWorld: ScenarioWorld, actor: string, playerId: string) {
const verifyMethod = async (): Promise<boolean> => {
return (await runStep(
`the ${actor} executes the "TestUtil.isVideoPresent('${playerId}')" JavaScript function on the page`,
scenarioWorld
)) as boolean
}
const isVideoPresent = await retryUntilTrue(verifyMethod)
if (!isVideoPresent) {
throw Error(`Stream does not have a video - for ${playerId} playerID and isVideoPresent is ${isVideoPresent}`)
}
}

async function verifyVideoNotPresent(scenarioWorld: ScenarioWorld, actor: string, playerId: string) {
const verifyMethod = async (): Promise<boolean> => {
return (await runStep(
`the ${actor} executes the "TestUtil.isVideoPresent('${playerId}')" JavaScript function on the page`,
scenarioWorld
)) as boolean
}
const isVideoPresent = await retryUntilFalse(verifyMethod)
if (isVideoPresent) {
throw Error(`Stream have a video - for ${playerId} playerID and isVideoPresent is ${isVideoPresent}`)
}
}

async function verifyAudioPresent(scenarioWorld: ScenarioWorld, actor: string, playerId: string) {
const verifyMethod = async (): Promise<boolean> => {
return (await runStep(
`the ${actor} executes the "TestUtil.isAudioPresent('${playerId}')" JavaScript function on the page`,
scenarioWorld
)) as boolean
}
const isAudioPresent = await retryUntilTrue(verifyMethod)
if (!isAudioPresent) {
throw Error(`Stream does not has a audio - for ${playerId} playerID and isAudioPresent is ${isAudioPresent}`)
}
}

async function verifyAudioNotPresent(scenarioWorld: ScenarioWorld, actor: string, playerId: string) {
const verifyMethod = async (): Promise<boolean> => {
return (await runStep(
`the ${actor} executes the "TestUtil.isAudioPresent('${playerId}')" JavaScript function on the page`,
scenarioWorld
)) as boolean
}
const isAudioPresent = await retryUntilFalse(verifyMethod)
if (isAudioPresent) {
throw Error(`Stream has a audio - for ${playerId} playerID and isAudioPresent is ${isAudioPresent}`)
}
}

export async function verifyMediaTracksEnabled(
scenarioWorld: ScenarioWorld,
actor: string,
) {
await runStep(`the ${actor} switch to the "Viewer" app`, scenarioWorld);
const videoElement = 'document.getElementsByTagName("video")[0]';
const srcObject = `${videoElement}.srcObject`;
const playerId = await scenarioWorld.page.evaluate(`${videoElement}.id`);

const srcObject = 'document.getElementsByTagName("video")[0].srcObject'
await runSteps([
`the "${srcObject}.active" JavaScript function result should be true`,
`the "${srcObject}.getVideoTracks()[0].kind" JavaScript function result should be "video"`,
Expand All @@ -39,6 +119,9 @@ export async function verifyMediaTracksEnabled(
`the "${srcObject}.getVideoTracks()[0].readyState" JavaScript function result should be "live"`,
], scenarioWorld);

await verifyVideoPresent(scenarioWorld, actor, playerId);
await verifyVideoIsActive(scenarioWorld, actor, playerId);
await verifyAudioPresent(scenarioWorld, actor, playerId);
}

export async function verifyViewerMediaTracksDisabled(
Expand All @@ -49,27 +132,38 @@ export async function verifyViewerMediaTracksDisabled(
const options = dataTable.rowsHash();
const disableVideo = options.disableVideo;
const disableAudio = options.disableAudio;
const videoElement = 'document.getElementsByTagName("video")[0]';
const playerId = await scenarioWorld.page.evaluate(`${videoElement}.id`);

await runStep([
`the ${actor} switch to the "Viewer" app`,
`the "document.getElementsByTagName("video")[0].srcObject.active" JavaScript function result should be true`
], scenarioWorld);

if (disableVideo === "true" || disableAudio === "true") {
if (disableAudio === "true") {
await runStep(`the "document.getElementsByTagName("video")[0].srcObject.getTracks().length" JavaScript function result should be 1`, scenarioWorld);
await verifyAudioNotPresent(scenarioWorld, actor, playerId)
}

if (disableVideo === "true") {
await runStep(`the "document.getElementsByTagName("video")[0].srcObject.getTracks().length" JavaScript function result should be 1`, scenarioWorld);
await verifyVideoNotPresent(scenarioWorld, actor, playerId)
}

if (disableVideo === "false") {
await runSteps([
`the "document.getElementsByTagName("video")[0].srcObject.getVideoTracks()[0].kind" JavaScript function result should be "video"`,
`the "document.getElementsByTagName("video")[0].srcObject.getVideoTracks()[0].readyState" JavaScript function result should be "live"`,
], scenarioWorld);
await verifyVideoPresent(scenarioWorld, actor, playerId);
await verifyVideoIsActive(scenarioWorld, actor, playerId);
}

if (disableAudio === "false") {
await runSteps([
`the "document.getElementsByTagName("video")[0].srcObject.getAudioTracks()[0].kind" JavaScript function result should be "audio"`,
`the "document.getElementsByTagName("video")[0].srcObject.getAudioTracks()[0].readyState" JavaScript function result should be "live"`,
], scenarioWorld);
], scenarioWorld);
await verifyAudioPresent(scenarioWorld, actor, playerId)
}
}
}
Loading

0 comments on commit f40d47c

Please sign in to comment.