Using Selenium with Cloud-based Load Testing

RanganathG [MSFT]

This blog is an introduction to how users can execute Selenium tests using Cloud-based Load Testing from Visual Studio Online. 


Let’s get familiar with Cloud-based Load Testing (CLT) from Visual Studio Online (VSO) and Selenium.

  • Cloud-base Load Testing:
  • Selenium

Let’s get started.

Authoring Selenium unit tests in Visual Studio

  1. Let’s start by creating a Unit Test Project in Visual Studio. File -> New Project -> Templates -> Visual C# -> Test -> Unit Test Project
  2. Once the library is created, install Selenium Nuget Package. Right Click on the project -> Manage Nuget Packages… -> “Search for Selenium” -> Install


  1. After installing the Nuget package, the references would include WebDriver reference.
  2. Download required Web drivers. For the sake of this example let’s use PhantomJs. You can search for Phantomjs in the Nuget Package Manager and install it just as you did for Selenium. Change the property of phantomjs.exe “Copy to Output Directory” as “Copy if Newer”


  1. You can create a CS file to get started with writing Unit Tests. Let’s add a small unit test using Selenium
using Microsoft.VisualStudio.TestTools.UnitTesting;<br /> using OpenQA.Selenium;<br /> using OpenQA.Selenium.PhantomJS;<br /> using System;<br /> using System.Text;<br /> <br /> namespace SeleniumSample<br /> {<br /> [TestClass]<br /> public class SeleniumTests<br /> {<br /> [TestMethod]<br /> public void TheBingSearchTest()<br /> {<br /> TestContext.BeginTimer("BingSearchTest_Navigate");<br /> _driver.Navigate().GoToUrl("");<br /> TestContext.EndTimer("BingSearchTest_Navigate");<br /> <br /> TestContext.BeginTimer("BingSearchTest_SearchBHarry");<br /> _driver.FindElement(By.Id("sb_form_q")).SendKeys("Brian harry blog");<br /> _driver.FindElement(By.Id("sb_form_go")).Click();<br /> TestContext.EndTimer("BingSearchTest_SearchBHarry");<br /> <br /> var elementText = _driver.FindElement(By.XPath("//ol[@id='b_results']/li/h2/a"));<br /> Assert.IsTrue(elementText.Text.Equals("Brian Harry's blog - Site Home - MSDN Blogs"), "Verified title of the blog page");<br /> }<br /> <br /> public TestContext TestContext { get; set; }<br /> <br /> #region Additional test attributes<br /> <br /> [TestInitialize]<br /> public void SetupTestSuite()<br /> {<br /> Console.WriteLine("Test init called: {0}");<br /> _driver = new PhantomJSDriver();<br /> }<br /> <br /> [TestCleanup]<br /> public void CleanupTestSuite()<br /> {<br /> _driver.Quit();<br /> }<br /> #endregion<br /> private IWebDriver _driver;<br /> }<br /> }
  1. Right click on the solution and add a “Test Settings” File. This is important* in order to run the above code using Test Explorer (Test -> Windows -> Test Explorer)


  1. Configure TestSettings to include phantomjs.exe as a deployment item


  1. Build the solution.
  2. From Test -> Test Settings -> Select Test Settings File, choose the testsettings file that is created in the previous step.
  3. Verify this runs on your local machine using Test Explorer (Test> Windows> Test Explorer) to check if things are working fine.


Adding Load Test for the unit tests

  1. Add a loadtest to the project (Right click -> Add ->  Load Test …). In the load test configuration wizard, in the “Text Mix”, click add and choose unit test of your interest, for example: TheBingSearchTest
  2. Verify the load runs on your local machine.


Running Selenium Tests on CLT On VSO

  1. Congratulations you are just one click to run your tests on Microsoft Azure cloud!
  2. From Test -> Test Settings -> Select Test Settings File, choose the Local.testsettings file that is created when the load test project is added.
  3. Open this file change the option to “Run Tests using Visual Studio Online”


              For more information please visit this blog to get a good understanding of how you can run your tests on Cloud –

  1. Once the run is completed and you have downloaded the report. Click on View report as mentioned in the above link.
  2. You would be able get a lot of insights into how the test execution happened. You can get a view of the transactions that happened in your tests (BingSearchTest_Navigate is a transaction in your test). It would appear like


Please give this a try and do let us know your feedback :). Feel free to reach us at 


  1. If you try running the unit test without adding the Load Test Project you would run into System.NotSupported Exception at TestContext.BeginTimer(). It’s a known issue

               By adding a testsettings file the above issue could be avoided 🙂


Discussion is closed.

Feedback usabilla icon