Running UI Tests from Bamboo
Asked by Troels Larsen:

Hi,

We are having some problems running .Net unit tests from Bamboo. It seems that the results when we run them from bamboo aren't the same as when we run them manually using VS2010 or mstest.

Our theory is that the UI itself isn't being loaded, and we have tested it by adding the following test to our build:

```
[TestMethod]        public void TestBamboo()        {            var window = new Window();            window.Loaded += new RoutedEventHandler(window_Loaded);            window.Show();            Thread.Sleep(2000);            window.Close();        }        void window_Loaded(object sender, RoutedEventArgs e)        {            throw new NotImplementedException();        }
```

So the test should fail when the window loads, and it does so from my machine. However, this test succeeds from bamboo.

We have tried running bamboo from the console instead of the service, but to no avail.

How can we run these tests in interactive mode even when we aren't logged into the machine running bamboo?

The build server is a Windows Server 2008 R2, and bamboo is running locally.


Answers:
author: Scott Goodwin
body: Ran in to this same issue, and it is related to Session 0 Isolation, a security feature of Vista and 7.

I was able to install Bamboo agent as a service, yet kick off GUI tests by using the following advice:

<http://www.codeproject.com/Articles/35773/Subverting-Vista-UAC-in-Both-32-and-64-bit-Archite>


author: Ashwani
body: Hello Troels,

I am also facing the same issue. GUI is not getting invoked when running test using Mstest through Bamboo build.

Could you please help on this issue.

Many Thanks,


author: Troels Larsen
body: Hi Scotty, thanks for the link. For reason beyond my comprehension, we are now able to run these aforementioned tests without changing the session. But I will be sure to keep your link in case it crops up again.

Regards,

Troels


author: ReneR
body: Yes. How are you running the Bamboo agent and what credentials is it running with? A system account will NOT have access to the console. Your local tests succeed because you're already logged in to the Desktop with a user (yours) that has access to it.

Setup a local account for the bamboo agent, give it access to the Desktop and run your agent with that or give the system account access to the console.

comments: author: Troels Larsen
body: Hi, thanks for your answers.

To answer your questions:

- This is a WPF app, not WinForms.

- We are using the built-in MSTest Runner task, but have also tried an NAnt script and the MSTest Result Parser.

- We are running the Bamboo console as Administrator, which I would assume would have access to everything.

Maybe we are doing something wrong, but I can't see what that is.

We are logging in to remote desktop, running the console from the shortcut in the start menu (with elevated permissions) and starting the build from the web interface, remote desktop still logged in.

We will try again, but please point out any flaws in our execution if you can find them.


author: Joe Clark
body: I assume your Window is a WinForms app?

You won't be able to run the Bamboo agent as a Windows service - it will need to run as a console app from within a logged-on user session.

How are you running your .NET build tasks? Are you using a shell script to start the test process, or are you using the built-in tasks?