Tuesday, October 29, 2019

Automated Cross Browser Testing with LambdaTest and Azure DevOps

Testing is very important process of the software development life-cycle which improve the quality of the software product by identifying issues of the software in various pre-release stages. Cross browser, device testing is important to verify application performance in different browsers and devices.  Hence, test teams use both manual and automated test mechanisms to perform test activities. This post explains how to perform automated cross browser, device testing with LambdaTest and Azure DevOps.

Pre-requisites: Selenium script which use LambdaTest selenium grid
                            Azure DevOps project


Let's get started


  • Write a Selenium script similar to following. It uses remote web driver instead of selenium client browser driver. It navigates to google page and search for the given text. You would be able to see few methods in the script.

1. Test method - This method explains, initiate remote web driver, navigate to google page and perform action on page

2. Desired capabilities - Read values from the configuration file and set to the capability values.



using System;
using System.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;
using SeleniumExtras.WaitHelpers;

namespace UnitTestProject2
{
    [TestClass]
    public class UnitTest1
    {
        private static IWebDriver driver;
        private static String ltUserName;
        private static String ltAppKey;
        private static String platform;
        private static String browser;
        private static String browserVersion;
        [TestMethod]
        public void TestMethod1()
        {            
            var option = new ChromeOptions();
            option.AddArgument("--start-maximized");
            IWebDriver driver = new RemoteWebDriver(new Uri(ConfigurationSettings.AppSettings["LTUrl"]), InitializeData(), TimeSpan.FromSeconds(600));
            OpenQA.Selenium.Support.UI.WebDriverWait wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromMinutes(1));
            driver.Navigate().GoToUrl("https://www.google.com/");
            wait.Until(ExpectedConditions.ElementToBeClickable(By.Name("q"))).SendKeys("LambdaTest");
            driver.Quit();
        }

        public static DesiredCapabilities InitializeData()
        {
            InitCaps();
            DesiredCapabilities caps1 = new DesiredCapabilities();
            caps1.SetCapability("platform", platform);
            caps1.SetCapability("browserName", browser); // name of your browser
            caps1.SetCapability("version", browserVersion); // version of your selected browser
            caps1.SetCapability("name", "CSharpTestSample");
            caps1.SetCapability("build", "LambdaTestSampleApp");
            caps1.SetCapability("user", ltUserName);
            caps1.SetCapability("accessKey", ltAppKey);
            caps1.SetCapability("network", true); // To enable network logs
            caps1.SetCapability("visual", true); // To enable step by step screenshot
            caps1.SetCapability("video", true); // To enable video recording
            caps1.SetCapability("console", true); // To capture console logs
            return caps1;
        }
        public static void InitCaps()

        {
            if (String.IsNullOrEmpty(Environment.GetEnvironmentVariable("LT_USERNAME")))
            {
                ltUserName = ConfigurationSettings.AppSettings["LTUser"];
            }
            if (String.IsNullOrEmpty(Environment.GetEnvironmentVariable("LT_APPKEY")))

                ltAppKey = ConfigurationSettings.AppSettings["LTAccessKey"];

            if (String.IsNullOrEmpty(Environment.GetEnvironmentVariable("LT_OPERATING_SYSTEM")))

                platform = ConfigurationSettings.AppSettings["OS"];

            if (String.IsNullOrEmpty(Environment.GetEnvironmentVariable("LT_BROWSER")))

                browser = ConfigurationSettings.AppSettings["Browser"];

            if (String.IsNullOrEmpty(Environment.GetEnvironmentVariable("LT_BROWSER_VERSION")))

                browserVersion = ConfigurationSettings.AppSettings["BrowserVersion"];
        }
    }
}
  • Lambda test allows you to select browser and platform combination. After you select the platforms and browsers, it generates the desired capability scripts that you need to include in your test script. You can move to capability generator from here  https://www.lambdatest.com/capabilities-generator/

  • You can maintain the configuration values using Application configuration file as follows. You need to provide  LTUser value and LTAccessKey values to connect with LambdaTest.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <appSettings>
    <add key="URL" value="https://www.google.com/" />
    <add key="LTUser" value= "myUserName"/>
      <add key="LTAccessKey" value="myAccessKey" />
      <add key="LTUrl" value="https://hub.lambdatest.com/wd/hub" />

      <add key="Browser" value="Safari" />
      <add key="BrowserVersion" value="11.0" />
      <add key="OS" value="macOS High Sierra" />
    </appSettings>
</configuration>
  • To find the LTUser and LTAccessKey values, Login and go to LambdaTest Automation section. You would be able to find the key icon. Click on the key icon to find the LTUser and LTAccessKey value.

  • Now we have the selenium automation script which use remote web driver. Add the source code to Azure DevOps source control. Let's discuss how to integrate this test automation script with Azure DevOps pipelines.
  • Go to Azure DevOps pipelines. Create a build pipeline to gather artifacts. You can create a build with following tasks.
  • Now we have all the necessary artifacts published in the build pipeline. Hence, we can create a release pipeline to trigger a lambda test run. You can create a release pipeline with tasks as shown in the following image.

  • After test run completed, go to Automation section of  LambdaTest, You would be able to see the  test run results with the test run video.


We have discussed how to write a sample test script with remote web driver. Further, we learned how to run the test script using Azure DevOps. Finally, we were able to see the test result in LambdaTest.

No comments:

Post a Comment