Continuous Testing with Selenium and Azure DevOps
Published Feb 09 2022 07:36 AM 16K Views
Iron Contributor

By Travis Ray

 

There are many articles and blogs on how to use the open-source tool, Selenium, to automate testing at the UI layer. This article assumes the reader has found a plethora of materials detailing the creation of Selenium tests and may be wondering what the use of automation is if someone must manually execute it. Creating stable automated tests is most of the battle. However, the real value of automation is realized when the execution and reporting is automatic as well.

 

If you are using Azure DevOps pipelines, the task is relatively simple to implement. The first step is to include the test project in the Git repo of the Azure DevOps project of the application being tested. In this example, I have created a separate project in the application solution:

Microsoft_Testing_Team_0-1644418498168.png

Configure the build pipeline with a Copy Files task to push all the artifacts of the build to the build.artifactstagingdirectory.

Microsoft_Testing_Team_1-1644418621465.png

The next build task will be to publish the contents of the build.artifactstagingdirectory. This will make the dll’s and dependencies of the Selenium tests available to the build agent.

Microsoft_Testing_Team_2-1644418684877.png

The next step will be to configure the Release pipeline. The UI tests will be executed only after a successful deployment of the application code. Add a new Visual Studio Test task.

Microsoft_Testing_Team_3-1644418891181.png

For the Test Files property of the VsTest task, specify the path to the dll of the Selenium test project.

Microsoft_Testing_Team_6-1644419351170.png

 

If you are unsure about the path to the test binaries, you can check the log from Copy Files task of the of the latest successful Build Pipeline. “D:\a\1\a” will be replaced by “**” in the Test files property of the VsTest Task. This specifies the root directory of the drop.

Microsoft_Testing_Team_5-1644419267616.png

Check the boxes titled: “Test mix contains UI tests” and “Upload test attachments”

Microsoft_Testing_Team_7-1644419467625.png

Save the pipeline and create a release run. The tests will now be automatically executed at the end of a successful deployment (Continuous Testing).

Microsoft_Testing_Team_9-1644419863705.png

 

 

Microsoft_Testing_Team_8-1644419774540.png

The test results can be further explored by clicking on the flask icon of the Release stage.

Microsoft_Testing_Team_11-1644420025064.png

By default, only the aborted and failed tests are shown. Explore the passed test results by including them in the filter.

Microsoft_Testing_Team_12-1644420070977.png

No Filters:

Microsoft_Testing_Team_13-1644420114245.png

 

If you have implemented the GetScreenshot() method of the Selenium webdriver and AddResultFile() method of the TestContext object into your tests, attachments will be included in the results:

        [TestMethod]
        public void PUL_Categories()
        {
           
            Helper.InitializeChromeDriver(out _driver, "http://<partsunlimited>.azurewebsites.net");


            PULPages pulPages = new PULPages(_driver);

            try
            {
                Assert.IsTrue(pulPages.SelectMore());
                _driver.GetScreenshot().SaveAsFile(Directory.GetCurrentDirectory() + "/SelectMore.png");
                TestContext.AddResultFile(Directory.GetCurrentDirectory() + "/SelectMore.png");
            }
            catch
            {
                _driver.GetScreenshot().SaveAsFile(Directory.GetCurrentDirectory() + "/SelectMore.png");
                TestContext.AddResultFile(Directory.GetCurrentDirectory() + "/SelectMore.png");
                Assert.Fail();
                _driver.Quit();
            }
        }

 

Attachments* tab:

Microsoft_Testing_Team_14-1644420192963.png

 

 

Thank you for reading! If you are interested in more information on this subject, we encourage you to check out or previous posts below:

 

 

References:

Monitoring Application Performance with Application Insights | Azure DevOps Hands-on-Labs (azuredevo...

 

 

2 Comments
Version history
Last update:
‎Feb 09 2022 07:35 AM