{"id":333,"date":"2014-11-16T22:40:00","date_gmt":"2014-11-16T22:40:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2014\/11\/16\/using-selenium-with-cloud-based-load-testing\/"},"modified":"2022-05-26T02:12:09","modified_gmt":"2022-05-26T10:12:09","slug":"using-selenium-with-cloud-based-load-testing","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/using-selenium-with-cloud-based-load-testing\/","title":{"rendered":"Using Selenium with Cloud-based Load Testing"},"content":{"rendered":"<p>This blog is an introduction to how users can execute Selenium tests using <a title=\"Cloud-based Load Test\" href=\"https:\/\/www.visualstudio.com\/features\/vso-cloud-load-testing-vs\" target=\"_blank\" rel=\"noopener\">Cloud-based Load Testing<\/a> from Visual Studio Online.\u00a0<\/p>\n<p><strong>Introduction<\/strong><\/p>\n<p>Let&#8217;s get familiar with Cloud-based Load Testing (CLT) from Visual Studio Online (VSO) and Selenium.<\/p>\n<ul type=\"disc\">\n<li>\n    <span>Cloud-base Load Testing:<\/span>\n  <\/li>\n<\/ul>\n<ul type=\"disc\">\n<li>\n    <span>A good introduction to CLT with VSO and key feature can be found here &#8211; <\/span><a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2013\/06\/03\/introducing-cloud-based-load-testing-with-team-foundation-service.aspx\"><span>Introducing Cloud-based Load Testing<\/span><\/a>\n  <\/li>\n<li>\n    <span>To get started quickly follow the instructions at this link &#8211; <\/span><a href=\"http:\/\/www.visualstudio.com\/get-started\/load-test-your-app-vs\"><span>Load Testing in cloud<\/span><\/a>\n  <\/li>\n<\/ul>\n<ul>\n<li><span>Selenium<\/span><\/li>\n<\/ul>\n<ul type=\"disc\">\n<li>\n    <em>Selenium automates browsers <\/em><span>Quote: <\/span><a href=\"http:\/\/www.seleniumhq.org\/\"><span>Selenium Official Website<\/span><\/a>\n  <\/li>\n<li>\n    <span>Please visit the official web site to get an overall idea of Selenium<\/span>\n  <\/li>\n<li>\n    <span>For this tutorial we will be specifically using a <\/span><a href=\"http:\/\/www.nuget.org\/packages\/selenium.webdriver\"><span>Selenium Nuget Package<\/span><\/a><span> and <\/span><a href=\"http:\/\/www.nuget.org\/packages\/PhantomJS\/\"><span>Phantomjs Nuget Package<\/span><\/a><span> in Visual Studio<\/span>\n  <\/li>\n<\/ul>\n<p>Let&#8217;s get started.<\/p>\n<p><strong>Authoring Selenium unit tests in Visual Studio<\/strong><\/p>\n<ol type=\"1\">\n<li value=\"1\">\n    <span>Let&#8217;s start by creating a Unit Test Project in Visual Studio. File -> New Project -> Templates -> Visual C# -> Test -> Unit Test Project<\/span>\n  <\/li>\n<li>\n    <span>Once the library is created, install Selenium Nuget Package. Right Click on the project -> Manage Nuget Packages\u2026 -> &#8220;Search for Selenium&#8221; -> Install<\/span>\n  <\/li>\n<\/ol>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2014\/11\/3426.SeleniumNuget.png\" alt=\"\" border=\"0\" \/>\u00a0<\/p>\n<ol type=\"1\">\n<li value=\"3\">\n    <span>After installing the Nuget package, the references would include WebDriver reference.<\/span>\n  <\/li>\n<li>\n    <span>Download required Web drivers. For the sake of this example let&#8217;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 &#8220;Copy to Output Directory&#8221; as &#8220;Copy if Newer&#8221;<\/span>\n  <\/li>\n<\/ol>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2014\/11\/1663.SeleniumProject.png\" alt=\"SeleniumProject\" width=\"388\" height=\"223\" \/><\/p>\n<ol type=\"1\">\n<li value=\"5\">\n    <span>You can create a CS file to get started with writing Unit Tests. Let&#8217;s add a small unit test using Selenium<\/span>\n  <\/li>\n<\/ol>\n<pre class=\"scroll\"><code class=\"csharp\">using Microsoft.VisualStudio.TestTools.UnitTesting;&lt;br \/> using OpenQA.Selenium;&lt;br \/> using OpenQA.Selenium.PhantomJS;&lt;br \/> using System;&lt;br \/> using System.Text;&lt;br \/> &lt;br \/> namespace SeleniumSample&lt;br \/> {&lt;br \/> [TestClass]&lt;br \/> public class SeleniumTests&lt;br \/> {&lt;br \/> [TestMethod]&lt;br \/> public void TheBingSearchTest()&lt;br \/> {&lt;br \/> TestContext.BeginTimer(\"BingSearchTest_Navigate\");&lt;br \/> _driver.Navigate().GoToUrl(\"http:\/\/www.bing.com\/\");&lt;br \/> TestContext.EndTimer(\"BingSearchTest_Navigate\");&lt;br \/> &lt;br \/> TestContext.BeginTimer(\"BingSearchTest_SearchBHarry\");&lt;br \/> _driver.FindElement(By.Id(\"sb_form_q\")).SendKeys(\"Brian harry blog\");&lt;br \/> _driver.FindElement(By.Id(\"sb_form_go\")).Click();&lt;br \/> TestContext.EndTimer(\"BingSearchTest_SearchBHarry\");&lt;br \/> &lt;br \/> var elementText = _driver.FindElement(By.XPath(\"\/\/ol[@id='b_results']\/li\/h2\/a\"));&lt;br \/> Assert.IsTrue(elementText.Text.Equals(\"Brian Harry's blog - Site Home - MSDN Blogs\"), \"Verified title of the blog page\");&lt;br \/> }&lt;br \/> &lt;br \/> public TestContext TestContext { get; set; }&lt;br \/> &lt;br \/> #region Additional test attributes&lt;br \/> &lt;br \/> [TestInitialize]&lt;br \/> public void SetupTestSuite()&lt;br \/> {&lt;br \/> Console.WriteLine(\"Test init called: {0}\");&lt;br \/> _driver = new PhantomJSDriver();&lt;br \/> }&lt;br \/> &lt;br \/> [TestCleanup]&lt;br \/> public void CleanupTestSuite()&lt;br \/> {&lt;br \/> _driver.Quit();&lt;br \/> }&lt;br \/> #endregion&lt;br \/> private IWebDriver _driver;&lt;br \/> }&lt;br \/> }<\/code><\/pre>\n<ol type=\"1\">\n<li value=\"6\">\n    <span>Right click on the solution and add a &#8220;Test Settings&#8221; File. This is important* in order to run the above code using Test Explorer (Test -> Windows -> Test Explorer)<\/span>\n  <\/li>\n<\/ol>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2014\/11\/5707.TestSettings.png\" alt=\"\" border=\"0\" \/><\/p>\n<ol type=\"1\">\n<li value=\"7\">\n    <span>Configure TestSettings to include phantomjs.exe as a deployment item<\/span>\n  <\/li>\n<\/ol>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2014\/11\/8877.DeploymentSettings.png\" alt=\"\" border=\"0\" \/><\/p>\n<ol type=\"1\">\n<li value=\"8\">\n    <span>Build the solution. <\/span>\n  <\/li>\n<li>\n    <span>From Test -> Test Settings -> Select Test Settings File, choose the testsettings file that is created in the previous step.<\/span>\n  <\/li>\n<li>\n    <span>Verify this runs on your local machine using Test Explorer (Test> Windows> Test Explorer) to check if things are working fine.<\/span>\n  <\/li>\n<\/ol>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2014\/11\/8233.TestExplorer.png\" alt=\"TestExplorer\" width=\"315\" height=\"344\" \/><\/p>\n<p><strong>Adding Load Test for the unit tests<\/strong><\/p>\n<ol type=\"1\">\n<li value=\"1\">\n    <span>Add a loadtest to the project (Right click -> Add ->\u00a0 Load Test \u2026). In the load test configuration wizard, in the &#8220;Text Mix&#8221;, click add and choose unit test of your interest, for example: <\/span><span>TheBingSearchTest<\/span>\n  <\/li>\n<li>\n    <span>Verify the load runs on your local machine. <\/span>\n  <\/li>\n<\/ol>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2014\/11\/3113.LoadTestEditor.png\" alt=\"LoadTestEditor\" width=\"405\" height=\"235\" \/><\/p>\n<p><strong>Running Selenium Tests on CLT On VSO<\/strong><\/p>\n<ol type=\"1\">\n<li value=\"1\">\n    <span>Congratulations you are just one click to run your tests on Microsoft Azure cloud!<\/span>\n  <\/li>\n<li>\n    <span>From Test -> Test Settings -> Select Test Settings File, choose the Local.testsettings file that is created when the load test project is added.<\/span>\n  <\/li>\n<li>\n    <span>Open this file change the option to &#8220;Run Tests using Visual Studio Online&#8221;<\/span>\n  <\/li>\n<\/ol>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2014\/11\/8228.VSOSettings.png\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 For more information please visit this blog to get a good understanding of how you can run your tests on Cloud &#8211; <a href=\"http:\/\/www.visualstudio.com\/get-started\/load-test-your-app-vs\">http:\/\/www.visualstudio.com\/get-started\/load-test-your-app-vs<\/a><\/p>\n<ol type=\"1\">\n<li value=\"4\">\n    <span>Once the run is completed and you have downloaded the report. Click on View report as mentioned in the above link.<\/span>\n  <\/li>\n<li>\n    <span>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<\/span>\n  <\/li>\n<\/ol>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2014\/11\/7563.Graphs.png\" alt=\"\" border=\"0\" \/><\/p>\n<p>Please give this a try and do let us know your feedback :). Feel free to reach us at <a href=\"&#109;&#x61;&#105;&#x6c;&#116;&#x6f;:&#118;&#x73;&#111;&#x6c;&#111;&#x61;d&#116;&#x65;&#115;&#x74;&#64;&#x6d;i&#99;&#x72;&#111;&#x73;&#111;&#x66;t&#46;&#x63;&#111;&#x6d;\">&#118;&#x73;&#111;&#x6c;&#111;&#x61;d&#116;&#x65;&#115;&#x74;&#64;&#x6d;i&#99;&#x72;&#111;&#x73;&#111;&#x66;t&#46;&#x63;&#111;&#x6d;<\/a>\u00a0<\/p>\n<p><strong>Issues<\/strong><\/p>\n<ol type=\"1\">\n<li value=\"1\">\n    <span>If you try running the unit test without adding the Load Test Project you would run into System.NotSupported Exception at TestContext.BeginTimer(). It\u2019s a known issue<\/span>\n  <\/li>\n<ul type=\"disc\">\n<li>\n      <span>A connect bug tracking it &#8211; <\/span><a href=\"https:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/774712\/unit-test-testcontext-begintimer-throws-notsupportedexception\"><span>https:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/774712\/unit-test-testcontext-begintimer-throws-notsupportedexception<\/span><\/a>\n    <\/li>\n<li>\n      <span>An alternative that is blogged &#8211; <\/span><a href=\"http:\/\/karlz.net\/blog\/index.php\/2012\/11\/17\/where-is-testcontext-begintimer\/\"><span>http:\/\/karlz.net\/blog\/index.php\/2012\/11\/17\/where-is-testcontext-begintimer\/<\/span><\/a>\n    <\/li>\n<\/ul>\n<\/ol>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0By adding a testsettings file the above issue could be avoided \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This blog is an introduction to how users can execute Selenium tests using Cloud-based Load Testing from Visual Studio Online.\u00a0 Introduction Let&#8217;s get familiar with Cloud-based Load Testing (CLT) from Visual Studio Online (VSO) and Selenium. Cloud-base Load Testing: A good introduction to CLT with VSO and key feature can be found here &#8211; Introducing [&hellip;]<\/p>\n","protected":false},"author":129,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,252],"tags":[],"class_list":["post-333","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-testing"],"acf":[],"blog_post_summary":"<p>This blog is an introduction to how users can execute Selenium tests using Cloud-based Load Testing from Visual Studio Online.\u00a0 Introduction Let&#8217;s get familiar with Cloud-based Load Testing (CLT) from Visual Studio Online (VSO) and Selenium. Cloud-base Load Testing: A good introduction to CLT with VSO and key feature can be found here &#8211; Introducing [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/129"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=333"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/333\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/45953"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}