Site Loader
Auckland, New Zealand
In this post we will discuss working with different browser in Coded UI Testing such as Chrome, firefox and IE using the same code which we worked in previous post. Cross-browser testing libraries does NOT ships with Visual Studio 2013 out of the box, rather, it should be downloaded as an extension from Visual Studio Extensions and Updates as shown below

You can also download from the following link https://visualstudiogallery.msdn.microsoft.com/11cfc881-f8c9-4f96-b303-a2780156628d The extension will be installed in the common file directory of your local machine C:\Program Files (x86)\Common Files\Microsoft Shared\VSTT

What’s the coding change?

Code change for Cross-browser testing is as simple as changing the CurrentBrowser property of BrowserWindow class
//For Chrome Browser
BrowserWindow.CurrentBrowser = "chrome"

//For Firefox Browser
BrowserWindow.CurrentBrowser = "firefox"

//The default Value for BrowserWindow is IE, hence no need to mention in property
Here is the complete Video for the above discussion. Thanks for reading the post and watching the video!!! Please leave your comments and let me know if there is anything need to be improved in the post. Thanks, Karthik KK

Post Author: Karthik kk

42 Replies to “Cross Browser Testing with Coded UI”

  1. Hi Karthik,

    There is severe issue while running the tests with chrome or firefox. Its too slow and unable to execute test cases/run which works perfectly fine with IE.

    To troubleshoot the same i searched few other things and applied the same as mentioned in the below article but still its not working for me.

    http://blogs.msdn.com/b/visualstudioalm/archive/2013/02/21/handling-browser-profile-issues-while-doing-cross-browser-testing-with-coded-ui-test.aspx

    Is there any way we can make it smoothly working.
    My code is totally hand coded no record and playback.

      1. I am facing issue at very starting of the test run i.e the browser is being launched with URL but its taking more than usual time to be redirected to login page and hence test fails as the control not found due to the page never being reached out.

        Its working fine while working with IE but not sure what issues with Chrome.

        Below is the error log of the same…

        Result Message:
        Test method RTest.TestScripting.TestScenario threw exception:
        Microsoft.VisualStudio.TestTools.UITest.Extension.FailedToLaunchApplicationException: “The application cannot be started. This could be due to one of the following reasons:
        1) Another instance of the application is already running and only one instance can be running at a time.
        2) The application started another process and has now stopped. You may need to launch the process directly.
        3) You do not have sufficient privileges for this application.” File: .
        Result StackTrace:
        at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.ThrowIfProcessNotValid(Process process)
        at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.SetCurrentProcessPrivate(Process value)
        at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.c__DisplayClassb.b__a()
        at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
        at Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.set_Process(Process value)
        at Microsoft.VisualStudio.TestTools.UITesting.BrowserWindow.FromProcessPrivate(Process processToWrap)
        at Microsoft.VisualStudio.TestTools.UITesting.BrowserWindow.c__DisplayClass1b.b__1a()
        at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
        at Microsoft.VisualStudio.TestTools.UITesting.BrowserWindow.FromProcess(Process processToWrap)
        at RTest.TestScripting.TestScenario() in d:\Automation Exp\RTest\RTest\TestScripting.cs:line 48

        1. Well, this issue clearly states that your ChromeDriver.exe is already running, meaning previous instance of ChromeDriver.exe is not closed properly.

          Just go to task manager and kill the ChromeDriver.exe, which should work fine.

          Also, add code in TestCleanup to to close the driver every time while you are done with your test

          driver.close()
          

          Thanks,
          Karthik KK

  2. Great video but I have a couple questions. Why are you getting the error message at the top of the chrome browser? I have done a bunch of searches and get varied explanations. Were you able to resolve this issue?

    Also when I launch Firefox in the manner you suggest, it does not open the url. Any ideas?

  3. I am referring to the error in your video that pops up in yellow that states you are using an unsupported command-line flag (8:21) into the video. I am getting the same error but it looks like that is resolved in ChromeDriver 2.11 (http://chromedriver.storage.googleapis.com/2.15/notes.txt)

    Firefox was not working for me because I was using FireFox 37 (the latest) and the Selenium Web Driver does not work with that yet, so I am now using FireFox (34).

    Just thought I would pass along the info

  4. HI Karthik,
    I have been watching some more of your videos and reading more of the blog and I have a follow up question. Hopefully you have time to look at it.

    In your example you launch the driver by setting the WindowBrowser like this:

    BrowserWindow.CurrentBrowser = “firefox”;
    BrowserWindow.Launch(“http://www.google.com”);

    How do you close the driver once it starts?

    Also, in a lot of other documentation I have read that people start the driver using the code below. I am curious why you don’t start it this way, or what the benefits are of starting it this way? What is the difference between the two ways the driver are launched/referenced?

    IWebDriver driver = new FirefoxDriver();
    driver.Navigate().GoToUrl(“http://www.google.com”);

    Thanks for taking a look! Keep up the good work!
    Dave

    1. oops !!!

      The topic we are covering is Coded UI Cross browser testing, but the one you have mentioned is Selenium.

      Selenium has IWebDriver interface, whereas CUIT has BrowserWindow static class.

      Hope this will clear out your question !!!

      Thanks,
      Karthik KK

  5. Hello Karthik,
    I am having an issue with my CustomCaller.cs when trying to do cross browser testing. The chrome browser window opens and navigates to the correct page but the CustomCaller is unable to locate the browser window. The tests work if I record them in the action recorder but not when I’m passing control references to the CustomCaller methods. Hopefully you can shed some light on this issue.

    Thanks for all the great videos!
    Kyle

    1. Hi Kyle,

      Seems like you need to set some additional search properties for your BrowserWindow Class,

      Try to set the additional search properties like Title or Name and see if it works.

      This sometimes happens in Chrome and firefox.

      Thanks,
      Karthik KK

  6. Hi karthik ,

    i am facing problem in cross browser testing, my code need to pass object of browser window in each functions written in saperate .cs files. please help

  7. HI Karthik,
    My Coded UI test is running perfectly in IE browsers, while I am unable to execute it in Chrome. I have installed all necessary drivers & Selenium Web Driver also.
    But the code is unable to identify the windows security popup in chrome.
    I am using VSTS 2013 Premium Edition Version 4.5.

    Please let me know the solution for the same. Thanks.

  8. Hi Karthik,
    I’m having a problem with running my tests in Chrome browser. The error message I’m getting is:

    Test method CodedUITestProject7.CodedUITest1.CodedUITestMethod1 threw exception:
    Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException: Could not locate the browser window, window name not specified.

    My tests are hard coded, and work perfectly on IE10. All of my test are done step-by-step according to your video instructions, including the Cross Browser Testing with Coded UI Testing — Part 26 video .

    P.S. Also I would like to add that I’m quite new to the testing and your video series on testing automation mean world to me.

    Thanks, and have a nice day

    Nenad

    1. …and for the error I would like to add that Chrome browser opens, and it lunches the Initial page. After the page opens chrome crushes and I’m getting windows message
      chromedriver.exe has stopped working
      A problem caused the program to stop working correctly.
      Windows will close the program and notify you i fa solution is available.”

    2. Thanks for reading the post.

      The problem with chrome browser and IE browser is, the window name sometimes changes with both the browsers.

      Hence try to use the Name property alone in the browser search property.

      Also use the propertyexpressionfilter.contains to set your Name property as well.

      Thanks,
      Karthik KK

      1. Thank you for the answer, but since I’m very new in automated testing (coding as well) I’m having a hard time implementing (understanding) your advice. As for your answer, could you please explain to me in more detail if you can:

        1. “…the window name sometimes changes with both the browsers.” – is this that same property (‘Name’) has different values for Chrome and IE

        2. “…use the Name property alone in the browser search property.” – is this for identifying Window as in (but instead of using ‘ClassName’ I should use ‘Name): window.SearchProperties[HtmlImage.PropertyNames.ClassName] = BrowserWindow.CurrentBrowser.ToString();

        3. “…use the propertyexpressionfilter.contains to set your Name property…” – I’ve couldn’t find any material on-line on this topic.

        Have a nice day good sir,

        Nenad

        1. Hi Nenad,

          Have you ever figured out how to solve your problem? Because I am having te exact same problem. Chrome launches the login page but then crashes with the same error message you mentioned above.

          Would love to here if and how you fixed it!

          Many thanks,
          merel

  9. i am facing issue using cross browser selenium components.
    error yograj002@gmail.com
    An exception of type ‘OpenQA.Selenium.WebDriverException’ occurred in WebDriver.dll but was not handled in user code is shown when the chrome browser launched and i am not able to find any control on Browser Window. Also not able to capture browser window of chrome browser

  10. Dear Karthik,

    After reading this post and especially your replies I believe you know what problem I am facing.

    I have a set of coded ui tests that are successfully running in IE.
    After installing cross browser components for selenium tests also run in Chrome.
    When switching browser to firefox browser is not being started.

    Launching browser code is the most standard it can get:

    BrowserWindow.CurrentBrowser = BaseTest.browser; // “chrome” / “firefox” / “iexplore” BrowserWindow.Launch(BaseTest.url);

    Visual Studio 2013 with Uprade 4
    Firefox: latest version 43, downgraded to older versions (33, 37).
    Firefox install folder: C:\Program Files (x86)\Mozilla Firefox

    In your video you mention that there is no need to install a firefox driver, since the execution engine will start firefox process from %ProgramFiles% folder. Unfortunately it does not happen here. What would be your idea why firefox is not started?

    Thanks a lot for looking into this! I have surfed a lot through internet and still do not have the answer…

    Kind regards,
    Olena

      1. Hi Karthik,

        Thanks for the fast feedback! Here is an exception + stacktrace:

        System.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object..
        Result StackTrace:
        at Microsoft.VisualStudio.TestTools.UITest.Extension.CrossBrowserProxy.ProxyFirefoxDriver.c__DisplayClass54.b__52()
        at Microsoft.VisualStudio.TestTools.UITest.Extension.CrossBrowserProxy.FuncInvoker.InvokeMethod[T](Func`1 function)
        at Microsoft.VisualStudio.TestTools.UITest.Extension.CrossBrowserProxy.ProxyFirefoxDriver..ctor(ProxyFirefoxProfile profile)
        at Microsoft.VisualStudio.TestTools.UITest.Extension.CrossBrowser.BrowserServices.FirefoxBrowserService.InitializeWebDriver(String[] args)
        at Microsoft.VisualStudio.TestTools.UITest.Extension.CrossBrowser.CrossBrowserService.b__1(String[] args)
        at Microsoft.VisualStudio.TestTools.UITest.Extension.CrossBrowser.CrossBrowserService.Launch(String[] args)
        at Microsoft.VisualStudio.TestTools.UITest.Extension.CrossBrowser.CrossBrowserFactory.Launch(String[] arguments)
        at Microsoft.VisualStudio.TestTools.UITesting.BrowserWindow.LaunchPrivate(String[] arguments)
        at Microsoft.VisualStudio.TestTools.UITesting.BrowserWindow.c__DisplayClass18.b__17()
        at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
        at Microsoft.VisualStudio.TestTools.UITesting.BrowserWindow.Launch(String[] arguments)
        at Tests.UIMaps.BaseUIMapClasses.BaseUIMap.StartBrowser() in c:\tfs\ef72\0\work\other\internal\qa\Autotests\Tests\UIMaps\BaseUIMap.cs:line 49

  11. Hi Kartik

    Great videos and knowledge sharing. Thank a lot.
    My query is :
    Assume user1 is logged in using Chrome browser. Then control is moved to IE and user2 is logged in using IE browser and does some operations (click, save, enter some data in text boxes etc…………….). Now I am unable to switch to Chrome browser and do some operations. If anybody have any idea, please share.

    Thanks in advance.
    Naveen

    1. Hi Naveen,

      I would say, if you could switch browser once you should be able to do it second time. Does it work when switching to / from Firefox?

      Kind regards, Olena

  12. Hi,

    Not able to locate chrome browser using Coded UI – C#.

    When I wrote the code for IE, it works:

    BrowserWindow browserWindow = new BrowserWindow();
    BrowserWindow.CurrentBrowser = “ie”;
    browserWindow = BrowserWindow.Locate(“Google”);

    browserWindow.DrawHighlight();
    browserWindow.ResizeWindow(500, 500);
    browserWindow.CloseOnPlaybackCleanup = false;

    But when i want the same code to run on chrome , it doesnt !

    BrowserWindow browserWindow = new BrowserWindow();
    BrowserWindow.CurrentBrowser = “chrome”;
    browserWindow = BrowserWindow.Locate(“Google”);

    browserWindow.DrawHighlight();
    browserWindow.ResizeWindow(500, 500);
    browserWindow.CloseOnPlaybackCleanup = false;

    Note – software used:

    Microsoft Visual Studio Enterprise 2015
    Version 14.0.24720.00 Update 1
    Microsoft .NET Framework
    Version 4.6.01055

    Chrome: Version 49.0.2623.87 m

    Need urgent help, please.

    Thanks a lot, in advance.

  13. Hi Karthik,
    I am working in codedui automation testing. I have written test script for automating datadriven. When script open application, it is lot of time to enter data. Could you please me in reducing delay.

  14. Hi Karthick,
    I am working in chrome browser. Everytime i run the code m getting this error.
    “Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException: Could not locate the browser window, window name not specified.”

  15. Hi I am facing problem while launching Firefox version 48 from Coded UI. The same test script is working fine in chrome but not for Firefox.
    Any idea what can be the problem?

  16. hi karthick

    i am install all the setup based on the video but i am getting error for an error occured while connecting to firefox.

    Pleae help me

  17. Hi karthick,
    really nice videos, helped lot understanding Coded ui cross browser testing. I have few queries, pls help me solve these.

    I am using Chrome v 55 for cross browser testing, and getting errors:
    1. chromedriver.exe has stopped working
    2. Microsoft.VisualStudio.TestTools.UITesting.UITest.Extension.UITestException: The HTTP request to the remote WebDriver server for URL http://localhost:42497/session timed out after 60 seconds.

    I downloaded and copied the recent chrome webdriver (2.27) in VSTT, but still facing the same issues.

  18. Hi,
    Can anybody help me with these? Thanks in advance.

    I am using Chrome v 55 for cross browser testing, and getting errors:
    1. chromedriver.exe has stopped working
    2. Microsoft.VisualStudio.TestTools.UITesting.UITest.Extension.UITestException: The HTTP request to the remote WebDriver server for URL http://localhost:42497/session timed out after 60 seconds.

    I downloaded and copied the recent chrome webdriver (2.27) in VSTT, but still facing the same issues.

  19. I have got this error. Who can help?
    An exception of type ‘System.ArgumentNullException’ occurred in Microsoft.VisualStudio.TestTools.UITesting.dll but was not handled in user code

    Additional information: Value cannot be null.
    If I don’t use BrowserWindow window = BrowserWindow.Launch(urlPage); launching IE 11 works well.

Leave a Reply

Your email address will not be published. Required fields are marked *