Identify browser window by absolutepath

Apr 18, 2013 at 10:48 AM
Edited Apr 18, 2013 at 11:12 AM
Hi All,


browser windows are identified by the following
ReviewPage reviewPage = CUITe_DynamicBrowserWindow.GetBrowserWindow<ReviewPage>("[project title] PleaseReview™");
is there a way to identify the browser window by part of the title or absolute path or any property other than title?

for example if the title is "public new string sWindowTitle = "coded ui test framework - Google Search" i only want to give part of it "Google Search" or part of its absolute path "google.com/Search?"

is this possible?
Coordinator
Apr 22, 2013 at 12:47 AM
Hi deepakguna,

Browser window titles seem to support partial matches.

Here is an example:
            //Arrange
            using (TempFile tempFile = new TempFile(
@"<html>
    <head>
        <title>test 1 2 3</title>
    </head>
    <body>
        <button id=""buttonId"" >Button</button>
    </body>
</html>"))
            {
                CUITe_BrowserWindow.Launch(tempFile.FilePath);
                CUITe_BrowserWindow window = new CUITe_BrowserWindow("test");

                //Act
                CUITe_HtmlButton button = window.Get<CUITe_HtmlButton>("id=buttonId");

                //Assert
                Assert.AreEqual(button.InnerText, "Button");

                Trace.WriteLine(window.Uri.ToString());

                window.Close();
            }
The sample code also illustrates how to get the Uri of the browser window.

Does this satisfy your requirements?
If not, in what scenario is finding a specific browser instance that has navigated to a specific Uri required?
Apr 23, 2013 at 4:02 AM
Thank you icnocop!

there are some scenarios where we need to use absolute path or part of it to uniquely identify a window, (title will be same )
Coordinator
Apr 23, 2013 at 5:45 AM
I don't believe Coded UI supports this kind of functionality out-of-the-box, so you will have to implement it yourself.

Here is some sample code that enumerates all Internet Explorer browser windows and outputs the uri and title:
            Process[] processes = Process.GetProcessesByName("iexplore");
            foreach (Process process in processes)
            {
                if (string.IsNullOrEmpty(process.MainWindowTitle))
                {
                    continue;
                }

                BrowserWindow bWin = CUITe_BrowserWindow.FromProcess(process);
                Trace.WriteLine(string.Format("Found browser window: {0} {1}", bWin.Uri, bWin.Title));
            }
Apr 23, 2013 at 10:31 AM
Thank you again,

I think coded ui supports this absolutepath property out of the box. which you can use to identify the browsers/page document. I was looking for something like this in CUite, but on seeing browser window we just have title
Coordinator
Apr 24, 2013 at 7:35 AM
Related to my last post, you can use bWin.Uri.AbsolutePath for example.

The BrowserWindow class is part of Microsoft's Coded UI namespace (Microsoft.VisualStudio.TestTools.UITesting).