Automating SignalR applications with Selenium WebDriver

Last Updated on by

Post summary: This post is about a “No response from server for url” issue during automation of web application using SignalR with Selenium WebDriver. The issue was resolved by configuring the application to connect to the server through WebSocket protocol.

I had to automate with Selenium WebDriver (version 2.43) a single page web application which was built with SignalR. The first thing to do when you start an automation is to automate a smoke test scenario. So did I. It run fine on Internet Explorer (version 11) and Chrome (version 37). I was happy and confident I’m going to finish this project on time. The happy face was dramatically changed when I run the suite on Firefox (version 33). The driver timed out with “No response from server for url” issue. I searched the net for similar problems with no luck. I couldn’t find an end-to-end solution to issues with SignalR automation so I prepared this post.

About SignalR

ASP.NET SignalR is a library for building “real-time” applications that enable the server to push events to the client instead of relying client to request data from the server. Once the application is started SignalR client tries to connect to the server with the transport protocols in the order shown in the list: WebSocket, Server-sent events, Forever Frame (IE only) and finally Ajax long polling.

My application was forced to connect to the server with Long Polling transport (later on I discovered this was caused by a bug in application’s connection logic). Client (browser) opens a connection to the server. The server keeps this connection open for a relatively long time (2 minutes in my case). Seems like this open connection is confusing Selenium and it doesn’t actually know when the browser is ready. “Unstable” page loading strategy did not work out:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("webdriver.load.strategy", "unstable");
WebDriver driver = new FirefoxDriver(profile);

The only solution to make Selenium working with SignalR in all three browsers was to make the application under test working with WebSocket transport protocol.

It is also beneficial for the application itself to work with WebSockets. There are several SignalR prerequisites in order to use it with WebSockets: IIS 8 or IIS 8 Express with enabled WebSockets. In order to get enabled Web Sockets are installed additionally to IIS as a Windows feature.