• Blog
  • Info Support
  • Career
  • Training
  • International Group
  • Info Support
  • Blog
  • Career
  • Training
  • International Group
  • Search
logo InfoSupport
  • Latest blogs
  • Popular blogs
  • Experts
      • Alles
      • Bloggers
      • Speakers
  • Meet us
  • About us
    • nl
    • en
    • .NET
    • Advanced Analytics
    • Agile
    • Akka
    • Alexa
    • Algorithms
    • Api's
    • Architectuur
    • Artificial Intelligence
    • ATDD
    • Augmented Reality
    • AWS
    • Azure
    • Big Data
    • Blockchain
    • Business Intelligence
    • Cloud
    • Code Combat
    • Cognitive Services
    • Communicatie
    • Containers
    • Continuous Delivery
    • CQRS
    • Cyber Security
    • Dapr
    • Data
    • Data & Analystics
    • Data Science
    • Data Warehousing
    • Databricks
    • DevOps
    • Digital Days
    • Docker
    • eHealth
    • Enterprise Architecture
    • Hacking
    • Infrastructure & Hosting
    • Innovatie
    • Integration
    • Internet of Things
    • Java
    • Machine Learning
    • Microservices
    • Microsoft
    • Microsoft Bot Framework
    • Microsoft Data Platform
    • Mobile Development
    • Mutation Testing
    • Open source
    • Pepper
    • Power BI
    • Privacy & Ethiek
    • Python
    • Quality Assistance & Test
    • Quality Assurance & Test
    • Requirements Management
    • Scala
    • Scratch
    • Security
    • SharePoint
    • Software Architecture
    • Software development
    • Software Factory
    • SQL Server
    • SSL
    • Start-up
    • Startup thinking
    • Stryker
    • Test Quality
    • Testing
    • TLS
    • TypeScript
    • Various
    • Web Development
    • Web-scale IT
    • Xamarin
    • Alles
    • Bloggers
    • Speakers
Home » Switching browser in CodedUI or Selenium tests based on MTM configuration
  • Switching browser in CodedUI or Selenium tests based on MTM configuration

    • By Marcel de Vries
    • .NET 9 years ago
    • .NET 0 comments
    • .NET .NET
    Switching browser in CodedUI or Selenium tests based on MTM configuration

    *Moved to: http://fluentbytes.com/switching-browser-in-codedui-or-selenium-tests-based-on-mtm-configuration/

    In my previous post I have shown how you can integrate Microsoft Test Manager(MTM) with Selenium for cross browser testing of your web applications. One of the issues I did not touch what how can you switch to the correct browser based on the configuration selected to run in the Test Suite.

    So in MTM  you can configure the configurations you want to test. For a typical web scenario the following test settings would be a good example:

    image

    Now when I run a Test Case from the MTM environment, the test case will be put to the ready state for each configuration. Next I can run those test cases and from the Test Tab and the associated test automation will be started.

    Now in order to adjust my test to pick the correct browser, I want to know what configuration this test is running under. With Update 1 of visual studio 2012, the test controller and test agents, you can now get this information from the test context. Below you can see a list of properties that are available when you run a Test that is triggered from Microsoft Test Manager.  (this is the TestContext.Properties[] dictionary)

    Variable Name Example Value
    TestRunResultsDirectory C:UsersAdministratorAppDataLocalVSEQTQTAgent22TestClientResultsTestClient
    AgentId 1
    AgentName TestClient
    TestRunDirectory C:UsersAdministratorAppDataLocalVSEQTQTAgent22TestClient
    BuildDirectory \vsalmffdropsNew Build Definition 1New Build Definition 1_20130222.7
    DataCollectionEnvironmentContext Microsoft.VisualStudio.TestTools.Execution.DataCollectionEnvironmentContext
    TestResultsDirectory C:UsersAdministratorAppDataLocalVSEQTQTAgent22TestClientResultsb23878fe-9ce5-4444-83c1-563801f07762TestClient
    TestLogsDir C:UsersAdministratorAppDataLocalVSEQTQTAgent22TestClientResultsTestClient
    TestDeploymentDir C:UsersAdministratorAppDataLocalVSEQTQTAgent22TestClientDeployment
    ResultsDirectory C:UsersAdministratorAppDataLocalVSEQTQTAgent22TestClientResults
    ControllerName vsalm:6901
    TestDir C:UsersAdministratorAppDataLocalVSEQTQTAgent22TestClient
    AgentLoadDistributor Microsoft.VisualStudio.TestTools.Execution.AgentLoadDistributor
    DeploymentDirectory C:UsersAdministratorAppDataLocalVSEQTQTAgent22TestClientDeployment
    TotalAgents 1
    AgentWeighting 100
    FullyQualifiedTestClassName UnitTestProject1.CodedUITest1
    TestName CodedUITestMethod1
    __Tfs_BuildUri__ vstfs:///Build/Build/18
    __Tfs_IsInLabEnvironment__ True
    __Tfs_TestRunId__ 22
    __Tfs_TestCaseId__ 117
    __Tfs_TeamProject__ MyTeamProjectName
    __Tfs_BuildDirectory__ \vsalmffdropsNew Build Definition 1New Build Definition 1_20130222.7
    __Tfs_LabEnvironment__ <?xml version=”1.0″ encoding=”utf-16″?><LabEnvironment Id=”5f37b167-ad24-4f7e-bb1e-2e65a3e71a1f” Name=”Windows 7 Client” Uri=”vstfs:///LabManagement/LabEnvironment/2″><LabSystems><LabSystem Name=”TestClient” ComputerName=”TestClient” Roles=”Desktop Client”><CustomProperties /></LabSystem></LabSystems></LabEnvironment>
    __Tfs_TestConfigurationId__ 2
    __Tfs_TestPlanId__ 4
    __Tfs_TestConfigurationName__ Chrome
    __Tfs_TestPointId__ 12
    __Tfs_TfsServerCollectionUrl__ http://vsalm:8080/tfs/fabrikamfibercollection
    __Tfs_BuildPlatform__ Any CPU
    __Tfs_BuildNumber__ New Build Definition 1_20130222.7
    __Tfs_BuildFlavor__ Debug
    __Tfs_BuildConfigurationId__ 22

    In this list you now see the __Tfs__xxxx properties that are available. Here you can now find properties on e.g. the Environment you are running in and the information from MTM which test plan and configuration this test is part of.

    Now for running cross browser tests this is a huge benefit, since we can now leverage the configuration names of the tests that we run. In my particular case I can access the __Tfs_TestConfigurationName (highlighted in bold in the table)&nbsp;and this will return one of the three strings I have, “IE”, ‘Firefox” or “chrome”.

    So what I do is set up the browser I want to run my test on in the [TestInitialize]. If you are using Selenium you can use the info to switch the driver, in CodedUI this is done by setting the static property on the BrowserWindow. the following snippet of code shows how this is done:

    Selenium:

    [TestInitialize]
    public void Setup()
    {
        if (TestContext.Properties["__Tfs_TestConfigurationName__"] != null)
        {
            string selectedBrowser = TestContext.Properties["__Tfs_TestConfigurationName__"].ToString();
    
            Debug.WriteLine(string.Format("Selected browser configuration '__Tfs_TEstConfigurationName__' == {0}", selectedBrowser));
    
            if (!string.IsNullOrEmpty(selectedBrowser))
            {
                // check if we selected IE, Firefox or chrome
                switch (selectedBrowser)
                {
                    case "IE":
                        driver = new InternetExplorerDriver();
                        break;
                    case "Firefox":
                        driver = new FirefoxDriver();
                        break;
                    case "Chrome":
                        driver = new ChromeDriver();
                        break;
                    default:
                        driver = new FirefoxDriver();
                        break;
                }                        
            }
        }
    }
    

    CodedUI:

    [TestInitialize]
    public void TestInitialize()
    {
        if (TestContext.Properties["__Tfs_TestConfigurationName__"] != null)
        {
            string selectedBrowser = TestContext.Properties["__Tfs_TestConfigurationName__"].ToString();
            
            Debug.WriteLine(string.Format("Selected browser configuration '__Tfs_TEstConfigurationName__' == {0}",selectedBrowser));
    
            if (!string.IsNullOrEmpty(selectedBrowser))
            {
                // check if we selected IE, Firefox or chrome
                if (selectedBrowser == "IE")
                    return;
                BrowserWindow.CurrentBrowser = selectedBrowser;
            }
        }
    }

    So now you see that you can switch the browser based on the configuration you set in MTM.

    Next is to set up a new Lab Management build, where you select the Build, Test Environment and the Test plan you want to run. Now you create a new Build definition for each configuration (you can only select one per build definition) and you can schedule them all in parallel since they will be queued to the test agent running in the environment.

    This results in a set of test runs each morning that you can now check on any faults that night in any particular browser. You can see in the screenshot below taken from MTM, details of the run like: the build it ran on, if it was passed or failed and the time the run was made. Clicking on one of the rows, will take you to the results of that run, so you can further analyze what perhaps went wrong. Based on the Test settings you choose for the run, you will have more or less diagnostics to follow up in case of a failure.

    image

    Hope this helps you getting started!

    Follow my new blog on http://fluentbytes.com

    Share this

Marcel de Vries

View profile

Related IT training

Go to training website

Related Consultancy solutions

Go to infosupport.com

Related blogs

  • Innovative patterns in software quality management

    Innovative patterns in software quality management Tom van den Berg - 1 month ago

  • Developing a Service Fabric service using another host

    Developing a Service Fabric service using another host Tim van de Lockand - 5 months ago

  • Adding a package to your private WinGet.RestSource feed…

    Adding a package to your private WinGet.RestSource feed… Léon Bouquiet - 10 months ago

Related downloads

  • Beslisboom voor een rechtmatig ‘kopietje productie’

  • Klantreferentie: Remmicom zet wetgeving om in intellige…

  • Klantreferentie RDW: Samenwerken voor veilig en vertrou…

  • Klantreferentie BeFrank: Strategische IT voor een innov…

  • Wie durft te experimenteren met data in de zorg?

Related videos

  • mijnverzekeringenopeenrij.nl

    mijnverzekeringenopeenrij.nl

  • Winnaar | Innovation Projects 2017

    Winnaar | Innovation Projects 2017

  • Explore | Info Support & HAN & Poliskluis

    Explore | Info Support & HAN & Poliskluis

  • LifeApps bij HagaZiekenhuis

    LifeApps bij HagaZiekenhuis

  • Info Support | Bedrijfsfilm

    Info Support | Bedrijfsfilm

Nieuwsbrief

* verplichte velden

Contact

  • Head office NL
  • Kruisboog 42
  • 3905 TG Veenendaal
  • T +31 318 552020
  • Call
  • Mail
  • Directions
  • Head office BE
  • Generaal De Wittelaan 17
  • bus 30 2800 Mechelen
  • T +32 15 286370
  • Call
  • Mail
  • Directions

Follow us

  • Twitter
  • Facebook
  • Linkedin
  • Youtube

Newsletter

Sign in

Extra

  • Media Library
  • Disclaimer
  • Algemene voorwaarden
  • ISHBS Webmail
  • Extranet
Beheer cookie toestemming
Deze website maakt gebruik van Functionele en Analytische cookies voor website optimalisatie en statistieken.
Functioneel
Altijd actief
De technische opslag of toegang is strikt noodzakelijk voor het legitieme doel het gebruik mogelijk te maken van een specifieke dienst waarom de abonnee of gebruiker uitdrukkelijk heeft gevraagd, of met als enig doel de uitvoering van de transmissie van een communicatie over een elektronisch communicatienetwerk.
Voorkeuren
De technische opslag of toegang is noodzakelijk voor het legitieme doel voorkeuren op te slaan die niet door de abonnee of gebruiker zijn aangevraagd.
Statistieken
De technische opslag of toegang die uitsluitend voor statistische doeleinden wordt gebruikt. De technische opslag of toegang die uitsluitend wordt gebruikt voor anonieme statistische doeleinden. Zonder dagvaarding, vrijwillige naleving door uw Internet Service Provider, of aanvullende gegevens van een derde partij, kan informatie die alleen voor dit doel wordt opgeslagen of opgehaald gewoonlijk niet worden gebruikt om je te identificeren.
Marketing
De technische opslag of toegang is nodig om gebruikersprofielen op te stellen voor het verzenden van reclame, of om de gebruiker op een website of over verschillende websites te volgen voor soortgelijke marketingdoeleinden.
Beheer opties Beheer diensten Beheer leveranciers Lees meer over deze doeleinden
Voorkeuren
{title} {title} {title}