Like everything else you can do with WebRTC, screen sharing is natively supported by testRTC. There are though a few things you should be aware of and prepare in advance with if you want to test and validate your screen sharing feature with testRTC.
1. Understanding browser tabs in testRTC
When using screen sharing, you are going to move between tabs.
testRTC may or may not open chrome://webrtc-internals tab for its own use, which can confuse certain scripts.
This is why we make use of process.env.RTC_EXTRA_TABS environment variable. You can learn more about switching windows and tabs in testRTC.
2. Use run options to grab the whole screen
You can’t automate the screen picker modal of Chrome. What you can do instead is let Chrome know you wish to override that modal and always capture the whole screen.
#chrome-cli:auto-select-desktop-capture-source=Entire screen,enable-usermedia-screen-capturing
4. Tab switching
Once you click the share button on your UI, it is time to open a new and open that YouTube video URL.
function startedSharing() {
client
.rtcEvent('Screen Share ', 'global')
.rtcScreenshot('screen share')
.execute("window.open('" + videoURL + "', '_blank')")
.pause(5 * sec)
// Switch to the YouTube tab
.windowHandles(function(result) {
var newWindow;
newWindow = result.value[1+Number(process.env.RTC_EXTRA_TABS)];
this.switchWindow(newWindow);
});
}
A few observations here:
- You can place this function as one of your assets
- Adding an event using rtcEvent() at the beginning comes in handy when you’ll view the resulting graphs in the end
- The videoURL is that YouTube URL we’ve shared earlier. Use a variable for that so it will be easier to search and modify based on your needs
- Actual window switching is done using pure Nightwatch commands
function stoppedScreensharing() {
client.windowHandles(function (result) {
var newWindow;
newWindow = result.value[Number(process.env.RTC_EXTRA_TABS)];
this.switchWindow(newWindow);
});
}
Just don’t forget to click the stop screen sharing button in your UI afterwards.
6. Take a screenshot on the viewers’ side
For debugging purposes, you can use rtcScreenshot() to take a screenshot of what gets shared for those who aren’t screen sharing.