SpecBind / specbind

Bridges the SpecFlow and popular UI automation frameworks to simplify acceptance tests.
MIT License
41 stars 25 forks source link

Feature Request: Ability to get BrowserWindow from CodedUIBrowser #118

Open icnocop opened 8 years ago

icnocop commented 8 years ago

I would like to get the BrowserWindow from the CodedUIBrowser.

    [Binding]
    public sealed class MySteps
    {
        private readonly IObjectContainer objectContainer;

        public MySteps(IObjectContainer objectContainer)
        {
            this.objectContainer = objectContainer;
        }

        [Given(@"I want to do something with the browser")]
        public void GivenIWantToDoSomethingWithTheBrowser()
        {
            CodedUIBrowser browser = (CodedUIBrowser)this.objectContainer.Resolve<IBrowser>();
            // I can get CodedUIBrowser, but how can I get the Microsoft.VisualStudio.TestTools.UITesting.BrowserWindow?
        }

Thank you.

dpiessens commented 8 years ago

Hi, why do you want to access the browser window directly?

icnocop commented 8 years ago

The web application I am testing prompts the user to open/save a file, and in order to validate the downloaded file, I have to interact with the BrowserWindow using CodedUI WinControls in order to click on the Save > "Save as" button in the Notification window that appears:

savedialog 1

I'm able to automate the saving of the file without an issue, it's just that I have what seems to be a "code smell" when it comes to retrieving the BrowserWindow.

If the ability to save the file is built-in to SpecBind that would be more ideal, but it seems that making the BrowserWindow publicly accessible is more flexible for extending the capabilities of SpecBind for other requirements that may be required in the future.

For example, my step reads as follows: Given I was prompted to download "11.msr"

That step does the following:

  1. Verify that the file name in the step is the same as what the browser window prompts me to save.
  2. Saves the file to a temporary location.
  3. Saves the temporary file path so it can be used in another step.

Lastly, I have an "AfterScenario" SpecFlow binding hook to delete the temporary file if it exists.

pj-jacobs commented 6 years ago

This help a lot when testing responsive pages and you need to resize the BrowserWindow.