Business Insights · February 7, 2024 · Serhiy Sokorenko · 1,728 views

Successful Testing: First Positive Results for Video Streaming Apps

Successful Testing: First Positive Results for Video Streaming Apps

In a previous article “Getting Started with Playwright for Automation Testing” we discussed an easy way to start with automation testing and all needed adjustments during installation. Today, we will continue this topic and dive into the PlayWrite tool more deeply and learn more about it with examples of testing video streaming application. You can find all the example code below and can in your own projects or test-suites.

Quick Guide: What to expect in this practice article:

  • Short guide for PlayWright and IDE (Visual Studio Code) Setup: We’ll start by installing the IDE, Visual Studio Code, which serves our digital workspace.
  • Test case decision analysis: explanations of the approaches used.
  • Working with dates in JavaScript: will use the “Date” object and functions getMinutes/setMinutes/addMinutes (or their UTC-options: getUTCMinutes/setUTCMinutes/addUTCMinutes).
  • Authentication: will consider various types of usage.
  • Test urls: we will clarify how that works.
  • Using various browser contexts in one test case: we will understand and clarify how this works.
  • Test Run: Finally, we’ll run tests to see everything in action.

Let’s start!

1. Test setup

1.1 Install IDE.

1.2 Install Node.js (or npm, if you need specific versions of node for another of your projects).

1.3 Install Playwright.

For more information please see our detailed guide.

2. Test-case analysis and execution details

2.1 Full code of test case. 

test(‘testCreateFullEvent’, async({request}) => {
// Dates
    // Current date and time
        const eventStartsInMinutes = 1
        const eventDurationMinutes = eventStartsInMinutes + 25

    // Current date and time
        const now = new Date();
            console.log(“now =”, now);

    // Create startDateTime
    function addUTCMinutes(now, minutes) {
        now.setUTCMinutes(now.getUTCMinutes() + minutes);
        return now;
    }
    const startDateTime = addUTCMinutes(new Date(), eventStartsInMinutes);
        console.log(“startDateTime =”, startDateTime);

    // Create endDateTime
    function addUTCMinutes1(now, minutes) {
        now.setUTCMinutes(now.getUTCMinutes() + minutes);
        return now;
    }
    const endDateTime = addUTCMinutes1(new Date(), eventDurationMinutes);
        console.log(“endDateTime =”, endDateTime);

    // EventID creation
        const response = await request.post(eventsEndpoint, {
            data: {
                “title”: “Auto Test Event (“ + now + “)”,
                “start_time”: startDateTime,
                “end_time”: endDateTime,
                “theme_title”: “Auto test title”,
                “theme_body”: “Auto test body”,
                “type”: “Speaking” //”Speaking”, “Grammar”
            }, headers: {
                “apikey”: apiKey,
                “Content-Type”: “application/json”,
                “Authorization”: authorizationToken,
                “Prefer”: “return=representation”,
            }
        });
            expect(response.status()).toBe(201);
            expect(response.ok()).toBeTruthy();
                console.log(await response.json());

            const eventIdData = await response.json();
            const eventId = eventIdData[0]?.id;
                console.log(eventId);
       
    // Token creation
    // Token creation for User1
        const response1 = await request.post(createJoinUrlEndpoint, {
            data: {
                “name”: “Test Auto User Name 1”,
                “eventId”: eventId,
                “userId”: 11111,
                “secret”: RSAPrivateKey,
            }, headers: {
                “Content-Type”: “application/json”,
            }
        });
            expect(response1.status()).toBe(201);
            expect(response1.ok()).toBeTruthy();
                // console.log(await response.json());

            const userTokenData1 = await response1.json();
                // console.log(userTokenData)
            const userToken1 = userTokenData1.token;
                console.log(userToken1);

    // Token creation for User2
        const response2 = await request.post(createJoinUrlEndpoint, {
            data: {
                “name”: “Test Auto User Name 2”,
                “eventId”: eventId,
                “userId”: 22222,
                “secret”: RSAPrivateKey,
            }, headers: {
                “Content-Type”: “application/json”,
            }
        });
            expect(response2.status()).toBe(201);
            expect(response2.ok()).toBeTruthy();
                // console.log(await response.json());

            const userTokenData2 = await response1.json();
                // console.log(userTokenData)
            const userToken2 = userTokenData2.token;
                console.log(userToken2);

    // URL creation
    //Join URL creation for User1
    const eventJoinURL1 = baseEventUrl+eventId+“?token=”+userToken1;
        console.log(eventJoinURL1);
    //Join URL creation for User2
    const eventJoinURL2 = baseEventUrl+eventId+“?token=”+userToken2;
        console.log(eventJoinURL2);
   
    // Definition various windows for each participant
    // Browser context for User1
        const browser1 = await chromium.launch();
        const context1 = await browser1.newContext();
    // Browser context for User2
        const browser2 = await chromium.launch();
        const context2 = await browser2.newContext();

    //Opening browser windows
        // Open browser1 for User1
            const page = await context1.newPage();
                await page.goto(eventJoinURL1);
        // Open browser1 for User2
            const page1 = await context2.newPage();
                await page1.goto(eventJoinURL2);       
});

 

2.2 Preconditions.

2.2.1 Some of the constants we defined previously (like “apiKey”, “authorizationToken”, “RSAPrivateKey”), because of course it is confidential information for API access.

2.3 Dates. 

2.3.1 To get the current day and time in JavaScript, we used the built-in “Date” object. For our test-case at first we need to define main dates for next usage.

2.3.2 For our example we defined that our event started in 1 minute from the current date (“eventStartsInMinutes”) and the event ended 25 minutes after start (“eventDurationMinutes”).

2.3.3 Then we define “now” as equivalent to the current date and time.

2.3.4 In the next similar steps we are working on adding minutes to our already existing current date (“now”).

adding minutes to our already existing current date

2.4 EventID creation. 

EventID was created via POST-request (“.post”) to “eventsEndpoint” with request information “data” and “headers” according to the data scheme.

2.4.1 “.post” – its built request method.

2.4.2 “eventsEndpoint” – endpoint (or url in other words) for actions with events.

2.4.3 “data” includes main info about the entity, which we want to create – like title, start date, end date, type of event etc.

2.4.4 “header” includes main info for authorization to access to eventID create endpoint – “apiKey” and “authorizationToken”.

2.4.5 At the next step we check the status code and status of our response.

2.4.6 Finally we processed the received date from response and separate from .json needed “EventID” field.

“EventID” field

2.5 Token creation. 

UserToken we created via POST-request (“.post”) to “tokenCreationEndpoint” with request information “data” and “headers” according to the data scheme.

2.5.1 “Data” includes main info about the entity, which we want to create – like “name”, “eventID”, “userID”, “secret” key etc.

2.5.2 “Header” includes only the main info about the type of content.

2.5.3 Finally we processed the received date from response and separate from .json needed “UserToken1” and “UserToken2”  fields.

“UserToken1” and “UserToken2”  fields.

“UserToken1” and “UserToken2”  fields2

2.6 URL creation.

Event join url consist of main parts, which we need to gather in this step:

2.6.1 base url part: “https://example.web.app/event/

2.6.2 event ID part: “4a8453b2a-346a-41e4-9gdg-f4ffdhhdr3a5” (hash event ID example)

2.6.3 user token part: “dfEfl352435Kdllehs98iklsxEhgQofYtGier3gsdggkoum884okIJfglKJHEFL” (user token example)

URL creation

2.7 Definition of separate windows for each participant. 

Here, we utilize various contexts and browsers to simulate actions of different users, keeping them separate from each other.

Definition of separate windows for each participant

2.8 Opening browser windows.

Separate windows for each user, simulating opening application by various users.

Opening browser windows

3. Test Run.

Lets run the test by usual command “npx playwright test -g “test-case name example” –headed”, where:

3.1 “npx playwright test -g” – command for running our test.

3.2 “test-case name example” – the name of the runned test.

3.3 “–headed” – browser mode.

Conclusion

In this article, attention is given to practice and I have described in some detail how one of the positive tests works. This is only a small part of the automated tests that are carried out on our project (an educational platform with audio and video communication between students), among which are API tests. Of course, the minimum set of tests covers all the basic functionality of the application and expands in terms of feature priority and product development.

If you require a more comprehensive solution for integrating with your existing or future applications, feel free to contact us for detailed information and services.

Serhiy Sokorenko
Written by Serhiy Sokorenko QA Engineer

Related Articles

Ready to start?

Let Us Work Together

Tell us about your project and we'll get back within 24 hours.

Get in Touch