VS 2010 Coded UI Test - Launch Referenced Application
Asked Answered
G

3

22

I'm using Visuial Studio's Coded UI Tests to run Automated UI tests on a WPF Application everytime a build runs on my TFS server. The problem I am running into is dynamically launching the executable based on the path where it was just built to, including the configuration(x86, x64).

Is there any way to get the path to an executable in a referenced project so that I can launch the application dynamically from my test project?

Geochemistry answered 5/5, 2010 at 21:5 Comment(0)
G
24

MSTest:

  1. Open your .testsettings file and check the "Enable Deployment" under the deployment section.
  2. In your test project right-click and select Add Existing Item.
  3. Browse to the build location of your application to test.
  4. Find your executable and select "Add as link" (make sure you either include all of your apps dependent DLL's if they are not already referenced by your test project.)
  5. Right click the link to the executable and select "Copy Always" (this will copy a new version of the .exe to your tests bin directory when it is built)
  6. In your [TestInitialize] add the following to launch your app:

    _yourApp = ApplicationUnderTest.Launch(Path.Combine(Directory.GetCurrentDirectory(), "yourexecutablename.exe"));
  7. In your [TestCleanup] you add the following:

    _yourApp.Close();

NUnit: (you will need to reference and use Microsoft.VisualStudio.TestTools.UITesting)

  1. In your test project right-click and select Add Existing Item.
  2. Browse to the build location of your application to test.
  3. Find your executable and select "Add as link" (make sure you either include all of your apps dependent DLL's if they are not already referenced by your test project.)
  4. Right click the link to the executable and select "Copy Always" (this will copy a new version of the .exe to your tests bin directory when it is built)
  5. In your [Setup] add the following to launch your app:

    _yourApp = ApplicationUnderTest.Launch("yourexecutablename.exe"));
  6. In your [Teardown] you add the following:

    _yourApp.Close();

note: I have not verified the NUnit implementation

Gnomon answered 7/5, 2010 at 17:47 Comment(4)
Just a note for VB .Net users: Added an internal variable inside the testing class (such as "Private myApp"), instead of brackets, use <> (such as "<TestCleanup()>" instead of "[TestCleanup]", and steps 4 and 5 are impossible to do.Neighborly
@Zian Choy - Build your executable project as you would normally, then when you go to add a link to the .exe you need to find it in it's build configuration's build path. For example, c:\myapp\bin\debug\myapp.exe.Gnomon
Ah, I made a mistake with how I was adding the EXE.Neighborly
This doesn't work. The EXE file does not get copied to the [VS gibberish]/Out folder even when the EXE is added as a link and the copy setting is set to "Copy Always".Neighborly
M
4

As Zian Choy wrote, using the steps provided by Adam, the application under test is not being copied to the .../Out directory. The following additional steps worked for me:

  1. Open your .testsettings file and check the "Enable Deployment" under the "Deployment" section.
  2. Add your binaries under test via "Add Directory...", e.g. "\AppUnderTest\bin\debug"
Mignon answered 15/2, 2013 at 10:30 Comment(0)
G
1

I've been struggling for some time with trying to figure out how to tell my CodedUI project where to launch the executable from and how to do it "right", so it works automatically when different users run the code in different workspaces, on different hosts etc. I did come up with copying the executable into a shared directory (step in the right direction) and then recording an action to start it from there (band aid, so it at least works for different users on the same host).

Here are the steps from your MSTest instructions, adapted for MS Visual Studio 2015 Enterprise IDE. Sadly, I do not have enough "reputation points" to be able to embed screen shots --

  1. From inside MS Visual Studio IDE, in Solution Explorer, click on your CodedUI project to highlight it, right click, select "Add", select "Existing item"
  2. In Add Existing Item dialog, navigate to the executable that you want to test within your CodedUI project. Click on the file to highlight it, then locate "Add" drop-down list on the dialog window and select "Add as Link", click OK
  3. Go back to Solution Explorer, click on CodedUI project again and expand it. Now you should see an icon .exe listed inside CodedUI project
  4. Right-click on .exe icon and select "Properties"
  5. In Properties window, set BuildAction to Content and Copy to Output Directory Copy Always

Voila!!!

Gymnosperm answered 20/10, 2016 at 20:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.