Managing Browser Profiles when using Cross Browser testing in Coded UI Test

Managing Browser Profiles when using Cross Browser testing in Coded UI Test

  • Comments 5

We introduced extended support in Coded UI Test for Cross Browser Testing with VS 2012 Update 2 February CTP (see this, this and this post for details). This post addresses details specific to managing browser profiles when using cross-browser testing feature.

Browser launches are often customized and you might want to test with specific user profiles. Sometimes, you don't care about using specific profiles, but are forced to use a default profile. For instance,
if a profile is not specified, Chrome may think that it’s setting up the browser for first use and it displays some initial browser settings and you see the message "Chrome is almost ready". This does not let you proceed with the tests.

Two commonly seen issues and their solutions are detailed below:

You don’t see your profile getting picked up.

Coded UI Test Picks up the profile the following way:

(i)   If you have specified an argument of “--user-data-dir=<profile directory>” this is respected. Chrome will use this profile directory to launch your browser. (On details on what parameter to give for this command line see http://www.chromium.org/user-experience/user-data-directory)

Coded UI Code for this would look like:

BrowserWindow.CurrentBrowser = "Chrome";

BrowserWindow.Launch(new string[] { "http://www.bing.com/", @"--user-data-dir=C:\Users\<username>\AppData\Local\Google\Chrome\User Data" });

(ii)   If you have set Environment Variables for the folder path for the profile directories of Chrome/Firefox, these will be used. The Environment variable keys are:

"FireFoxProfileDirectory" – For Firefox

"ChromeProfileDirectory" – For Chrome

Set the above keys to the profile folder you want to get picked every time.

(iii)    If neither of the above exists, a default temporary profile gets picked.

Your profile got picked fine, but you notice that multiple browser launches on Chrome do not proceed:

[You have used either  (i) or (ii) of option 1 above], it’s due to a restriction that we cannot launch a second browser using the same profile directory. This is because the profile content gets locked and we cannot access it for another browser launch. This works just fine for FireFox, because the Selenium API internally will create copies of the profile directory specified. There are both pros and cons to the same – cached folders for a profile can become a pain, plus IO operation in folder copying consumes more time. If you need multiple launches of chrome in your test code, you can create your own temporary copies of the profile folder and use them as command lines. If you really do not care about what profile gets picked up, all is good – you need not set any environment variable or specify any command line argument, a temporary profile will get created for each browser launch.

 

Leave a Comment
  • Please add 8 and 1 and type the answer here:
  • Post
  • Hi everyone,

    I recorded codedUI tests on IE and trying to play back on chrome but I am facing some issues because chrome is not able to identify a control if it dont have a unique id. In case of the webpages which I am testing some controld dont have id's and some controls have ids which keep on changes. Please let me know if there is any work around for this issue.

    Thanks in advance,

    Raji

  • Hi Rajeswari,

    What is the Visual Studio version you are using?

    With Visual Studio Update 2, we have included a smart match logic, which will skip searching by id and use other properties if id has changed.

    Do the controls have other good search properties?

    To modify the properties you want to record, you can take a look at this blog blogs.msdn.com/.../coded-ui-test-configuring-search-properties-while-recording-on-internet-explorer.aspx

  • Hi Saima,

    Thanks for your response. I am using Visual STudio 2012 and installed update 2 as well. The test is failing even if the control has unique nam. It is looking only for the id.

    Thanks,

    Raji

  • Hey, Is cross browsing valid for safari web browser? I am using VS 2012 Update 3

  • Hi there,

    I've tried several things , and Coded UI is not selecting the profile I need. Basically my problem is that I need new to open on a new tab,. but i keep seeing that option unchecked no matter what i Do . I've tried to set the environment variables, I've sent parameters while launcing Firefox ( browser = BrowserWindow.Launch(new string[] {"http://URL"," -profile C:\\FirefoxProfile"}); ) and also with the -P and profile name.

    Nothing seems to work, :( any ideas?

Page 1 of 1 (5 items)