Watin tests fail at CC.Net

I am running Watin tests using xUnit on CC.Net under Windows Server 2003.

I have many tests that all work perfectly in the development blocks with TestDriven.Net and on the server with the xUnit gui application. However, when CC.Net runs the tests (as part of the MSBuild task), the function

ie.ContainsText("some text to find"); 

never returns the expected value. Other functions and properties of the IE object work fine: Button (...). Click (), TextBox (...). Value etc.

I know that the service account requires "Allow the service to interact with the desktop."

I tried this running CC service on local system and local administrator. The administrator account just hangs and never completes the test (although it creates an instance of the iexplorer.exe process.

Is this a problem when resolving on the server, or did I leave something outside the configuration?

+4
source share
6 answers

We just finished figuring out how to get around this problem. We now have watin tests running through CruiseControl.net that work as a service.

We need our cc.net service to run as a specific user to access the website we are testing because of how security is configured. Because the service works as a domain user, the "Allow user to interact with the desktop" checkbox is disabled on the service’s security tab. We do not want to simply start the team process from an always registered user, because we want the process to start automatically when it reboots. Now we have figured out

We worked on this by first creating a batch file to call nunit-console.exe. The parameters for nunit-console.exe are passed to the batch file as parameters, which then pass the parameters. The second and last line of the batch file returns the return code returned from nunit-console.exe. The batch file looks something like this:

  nunit-console.exe %1 %2 exit /b %ERRORLEVEL% 

The number of parameters you pass to nunit-console may vary depending on your needs.

We use nant for our builds, so we replaced our existing nant task with a nunit-console call with an exec task that calls cmd.exe, which looks like this:

  <exec program="cmd.exe" failonerror="true"> <arg value="/interactive" /> <arg value="/c" /> <arg value="[batch file name]" /> <arg value="[parameter one value]" /> <arg value="[parameter two value" /> </exec> 

I don't know what the task will look like in msbuild, but I'm sure you can find it. The end result is a command that looks like this:

  cmd.exe /interactive /c [batch file name] [parameter one value] [parameter two value] 

Alternatively, you can use nant and just create msbuld nant tasks to invoke existing assemblies.

The '/ interactive' parameter for cmd.exe is the key; it runs the batch file in a process that has permission to interact with the desktop. I'm actually not sure if the / c option is required, but it works as it is. We still tell nunit to write the results to the same XML file so that our merge task does not need to be changed, and reporting the test results for cruise control works fine.

+10
source

Watin relies on browser automation to do the job, which is why the setting is "allow desktop service."

When Watin tries to start, it will do it under the service account, and not on the desktop that is currently logged in, and since it is going to deploy IE, it is possible that the account on which you are running Watin under launched IE earlier, and it could sit in the initial startup sequence for IE, where it asks for settings and all that hoo-hah.

In addition, if I remember correctly, an active login is required for interaction with the desktop settings. If at that moment no one has registered, there will be nothing to talk about for the service, and it is not going to create a new desktop for you.

+1
source

I got a couple of suggestions offline:

  • Trying to run tests with msbuild on the server.
  • Try starting CC.Net from the console instead of the service.

Will edit the results.

EDIT:

Results:

  • I can fully run tests with msbuild on the server.
  • When I run ccnet.exe from the command line, the tests pass fine. However, when I configure the task to run ccnet.exe from the command line at startup, the tests freeze and never end (eventually shutting down).

A partial workaround is to run a command line executable on a session that never dies. I really don't like this solution, so any additional input would be appreciated.

0
source

I don't know why this answer was correctly tagged with an incorrect exec example.

I rewrote it:

<exec> <baseDirectory>WatinTestDir</baseDirectory> <executable>cmd.exe</executable> <buildArgs>/interactive /C nunit-launcher.bat Test.dll /xml:../Test-results.xml</buildArgs> <buildTimeoutSeconds>2400</buildTimeoutSeconds> </exec>

What works ... but still doesn't work.

0
source

I followed this example, but this, unfortunately, did not help me. Since this question is about nant, and I'm using msbuild, I have opened a separate question here for.

0
source

This is a good solution, but does not solve the problem, you are trying to upload files using Watin.

http://blog.kikicode.com/2011/10/run-minimized-batch-file-in-task.html

It worked for me. The problem was that the cmd prompt blocked IE from starting. When I managed to minimize the cmd hint, it allowed IE to get focus and upload the files I needed in my process.

0
source

All Articles