Search code examples
c#visual-studiocoded-ui-tests

c# coded UI project. Coded UI Test Builder doesn't record WinForm start


I have a Solution with a WinForm and a coded UI Test Project. I would like to test my WinForm application with a coded UI Test.

When I record my actions with the UI Test builder it doesn't record the start of my WinForm application! Everything else like clicking buttons gets recorded.

So when I then run my test it fails cause the test can't find the WinForm (obviously)...

But why is that? Can I add some code in the test method to start the Winform application?

Thanks for help


Solution

  • If you want Coded UI to launch your forms application on start of a test, use the method

    ApplicationUnderTest.Launch("FORMS_APP_PATH");
    

    You can check the precise method details on MSDN.

    Update:

    To handle changing paths I created a new Forms solution and called it LabPlus. I then added a CodedUI test project to it. Inside the test project I added the reference of the LabPlus assembly. After that, I wrote following line in my CUI test method:

    ApplicationUnderTest.Launch(System.Reflection.Assembly.GetAssembly(typeof(LabPlus.Form1)).Location);
    

    I hope this answers your question :)