Site Loader
Auckland, New Zealand
In this post, we will discuss working with different advanced features of browserwindow class in Coded UI Testing.Using BrowserWindow class of Coded UI testing we can perform some of the most common and useful operations such as
  • Clearing Cache
  • Clearing Cookies
  • Executing scripts
  • Capturing screenshots
  • Working with existing browser session etc

Working with Existing browser session

There are many situations were, we might need to work with existing opened browsers, this can be done very easily using Locate() method available with BrowserWindow class of coded UI Testing.
NoteIn Selenium WebDriver, working with existing session is not possible till now, which is still a feature request by many but still in vein, which you can read from here. But the same is possible with RemoteWebDriver and that too supports only FireFox browser !!!
Here is the code snippet
BrowserWindow window = BrowserWindow.Locate("Execute Automation");

Clearing Cache and Cookies of browser

We can clear cache and cookies of browser before launching the browser using the following code snippet
BrowserWindow.ClearCookies();
BrowserWindow.ClearCache();

Capturing Screenshot of the browser

We can capture the screenshot of the browser as well using the code snippet below
  Image image = window.CaptureImage();
  image.Save(@"D:\captured.jpeg", ImageFormat.Jpeg);
  image.Dispose();

Other useful properties of BrowserWindow class

We can also user CurrentBrowser property of BrowserWindow class to set the browser we are working, this can be helpful while working with cross browser testing to enable working with different browsers like Firefox and Chrome. You can watch the complete video from the video below Thanks for watching the video and reading the article !!! Please leave your comments and let me know if there is anything need to be improved in the article. Thanks, Karthik KK

Post Author: Karthik kk

4 Replies to “Exploring features of Browser in CUIT”

    1. True, this is possible only with RemoteWebDriver class, but not with WebDriver of Selenium, you brought the right point !!!

      I will update my post.

      Thanks,
      Karthik KK

  1. Hi Karthik,

    Here small doubt Capturing the image at what time its exactly capturing? I mean that after completing the tests? but here I observed in middle of the test its capturing if its capturing after completion of the test Initial text box we are passing KK string right that is not captured in the image why?

    1. I think in video I mentioned that the screenshot will be captured if there is any exception in your code.

      Thanks,
      Karthik KK

Leave a Reply to Mohammad Saad Cancel reply

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