2
votes

Trying to Launch the browser using BrowserWindow browser = BrowserWindow.Launch(); getting exception in Visual Studio 2012 Ultimate

I have included following dll :

TechTalk.SpecFlow, nunit.util , nunit.core , Microsoft.VisualStudio.QualityTools.UnitTestFramework , NUnit.VisualStudio.TestAdapter , nunit.core.interfaces , nunit.framework , Microsoft.VisualStudio.TestTools.UITesting

and Created test method using Spec flow with coded UI getting runtime exception:

Test method specflow_CodedUI.SpecFlowFeature1Feature.AddTwoNumbers threw exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.TestTools.UITest.Playback, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.

3
clean and then rebuild, but this time click EXTRA hard! - Ewan

3 Answers

0
votes

You may want to try cleaning your solution, and deleting your packages folder and then rebuilding - I had a similar issue some time ago, doing this fixed it.

Obviously, if you require an assembly binding redirect for your Microsoft.VisualStudio.TestTools.UITesting reference, make sure it is correct.

0
votes

It does not work directly as specflow does not generate [CodedUITest] attribute on the unit tests. Follow this: https://github.com/techtalk/SpecFlow/wiki/Using-SpecFlow-with-CodedUI-API

0
votes

I have been using Process.Start to start the browser:

public class Browser : IDisposable
{
    private System.Diagnostics.Process currentBrowserProcess;

    private BrowserWindow window;

    public BrowserWindow Window
    {
        get
        {
            if (window == null)
            {
                window = BrowserWindow.FromProcess(currentBrowserProcess);
                window.CloseOnPlaybackCleanup = false;
            }

            return window;
        }
    }

    public Browser(string url)
    {
        Open(url);
    }

    public void Dispose()
    {
        Window.Close();
        window = null;
        currentBrowserProcess = null;
    }

    public void Open(string url)
    {
        if (currentBrowserProcess == null)
        {
            currentBrowserProcess = System.Diagnostics.Process.Start("iexplore.exe", string.Format("\"{0}\"", url));
        }
        else
        {
            Window.NavigateToUrl(new Uri(url));
        }
    }
}

And to use it:

Browser browser = new Browser("http://localhost/foo");

You can put that in the ScenarioContext for safe keeping. You can access the "window" object of the browser using browser.Window. Add your own helper methods to this class to make finding elements easy.

public HtmlButton Button(string buttonText, UITestControl container = null)
{
    HtmlButton element = new HtmlButton(container ?? Body);
    element.FilterProperties[HtmlButton.PropertyNames.InnerText] = buttonText;
    return element;
}

And to use:

HtmlButton button = browser.Button("Click Me!");

Mouse.Click(button);