Be the first user to complete this post

  • 0
Add to List

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].
  • window.open opens the url in a new window with specified properties and sets the window name to window1.
[wpgist id="a1e823ad7b83044bf0f2" file="open-1.js"] To open another window, you can use the same code and pass different arguments. It’s that simple! [wpgist id="a1e823ad7b83044bf0f2" file="open-2.js"] 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: [wpgist id="a1e823ad7b83044bf0f2" file="video.js"]

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?



Also Read:

  1. box-sizing
  2. Using es6 modules with simple examples
  3. Why use javascript strict mode
  4. css - align text to an image vertically
  5. JavaScript Promises - Visualized