Detecting OS & IE Version in (C#) Coded UI Tests

Using ProcessStartInfo and ApplicationUnderTest.Launch(ProcessStartInfo startInfo) you can launch a process under another user, but this will not work for Coded UI Tests in IE because you cannot access the DOM inside IE. Instead you can use the approach described there: https://blogs.msdn.com/b/siddharthapandey/archive/2009/12/13/testing-webpages-that-uses-windows-authentication-for-different-credentials.aspx

As mentioned the login dialog is different depending on Windows version. There might also be other situation where you want know the OS and/or IE version.

You can detect OS the Windows version in C# like this using Environment.OSVersion:

    1:  string ver = "0.0.0.0";
    2:  ver = Environment.OSVersion.ToString();
    3:              
    4:  switch (ver)
    5:  {
    6:     default:
    7:       //Do clever stuff based on the version number
    8:       break;
    9:  }
   10:   
   11:  TestContext.WriteLine("OS Version Detected was: " + ver);

Test output:

image

The IE version can be found using the WebBrowser class:

    1:  string ver = "0.0.0.0";
    2:  using (WebBrowser wb = new WebBrowser())
    3:  {
    4:     ver = wb.Version.ToString();
    5:  }
    6:   
    7:  switch (ver)
    8:  {
    9:     default:
   10:      //Do clever stuff based on the version number
   11:      break;
   12:  }
   13:   
   14:  TestContext.WriteLine("IE Version Detected was: " + ver);

Test output:

image