Getting started with automation testing for webrtc applications

WebRTC is a free, open project that provides browsers and mobile applications with Real-Time Communications (RTC) capabilities via simple APIs.

Automating WebRTC application brings unique sets of challenges. Most of the times, it requires to have multiple clients ( either browser, mobile, desktop ) open at the same time and doing context switching between those. Because you want to do a certain action on one client and verify that other WebRTC client received that action. For example, in a video chat application implemented using webRTC, you want to verify when a client one shares his video feed, the second client receives the video feed. Here, I will talk specifically about opening multiple chrome browser windows and doing context switching between those.

Actions to automate

  • opening multiple browser windows
  • switching to browser window for client one then sharing the video feed
  • switching to browser window for client two then checking the video feed did appear

Sounds ambitious but actually it’s simple. You can achieve it by using nightwatch.js. The key here is when you open a new window you need to set its name. In future, you can switch to that window by specifying the name of that window in .switchWindow().

Open multiple windows

To open a new window and set its name you can use the following snippet of code.

  • .execute function takes callback which is invoked immediately with arguments [URL1, WINDOW1].
  • opens the url in a new window with specified properties and sets the window name to window1.

To open another window, you can use the same code and pass different arguments. It’s that simple!

In fact, you can open as many windows as you want and do context switching between those.

Context switching between mutiple windows

Now, in your test suite you can context switch between windows by using .switchWindow(). For example, if you want to share a video feed in window1 and make sure it appear in window2, you can do the following:

What can you achieve with this?

You can architect an entire API of your page objects and test suite which does context switching between windows based on the received window name.

Hence, whenever you call those API you need to pass the context of that window. So, you do not need record similar actions for individual windows. Are you ready to create more flexible API which re-architect your test suite?

You may also like...

2 Responses

  1. Edon Sopjani says:

    Hi, i try to make call between to users, but when i open my first window and login to it, then i open the second window and go to login page it logs me as the first user, how can i open new window as new Session?

    • tutorialhorizon says:

      That is true. You can use the following approach to mitigate this issue:

      After navigating to the second user and before login – clear the localStorage, cookies, sessionStorage, serviceWorkers and any other storage which your application uses. Then you will be able to login as user 2 in the second window. I hope it helps.

Leave a Reply

Your email address will not be published.