Selenium times out / throws Exception when run in CCNET as a service - selenium

I'm currently working on wiring up Selenium tests to be run by CCNET which runs as a service in our build server.
This is my Project.build file:
<Target Name="AutomationTests">
<Message Text="~~~~~~~~~~~~~~~~$(HARD_NEW_LINE)" />
<Message Text="cmd.exe /interactive /c $(MSBuildProjectDirectory)\Nunit.bat $(SourceFolder)\Project.Web.UI.Automation\bin\Release\Project.Web.UI.Automation.dll"/>
<Exec Command="cmd.exe /interactive /c $(MSBuildProjectDirectory)\Nunit.bat /run:Project.Web.UI.Automation.Test.login $(SourceFolder)\Project.Web.UI.Automation\bin\Release\Project.Web.UI.Automation.dll" ContinueOnError="true" />
</Target>
Note : I resorted to run Nunit from a batch file following the advice in this post.
This is my CCNET.config file:
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>
<workingDirectory>C:\Projects\Project\AutomationUpdate\</workingDirectory>
<projectFile>Project.build</projectFile>
<buildArgs>/p:Configuration=Debug</buildArgs>
<targets>AutomationTests</targets>
<timeout>1800</timeout>
<logger>C:\CCNET\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
</msbuild>
My problem is that, even though Nunit starts up (I can see it's output in the MSBUILD log), Selenium is throwing a timeout exception. This is an excerpt from the build log as seen in CCNET.
<message level="high"><![CDATA[ProcessModel: Default DomainUsage: Single]]></message>
<message level="high"><![CDATA[Execution Runtime: net-4.5]]></message>
<message level="high"><![CDATA[Selected test(s): Project.Web.UI.Automation.Test.login]]></message>
<message level="high"><![CDATA[.F.F.F.F.F.F]]></message>
<message level="high"><![CDATA[Tests run: 6, Errors: 6, Failures: 0, Inconclusive: 0, Time: 223.3787765 seconds]]></message>
<message level="high"><![CDATA[ Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0]]></message>
<message level="high" />
<message level="high"><![CDATA[Errors and Failures:]]></message>
<warning file="EXEC" line="0" column="0" timeStamp="10/29/2013 12:38:16"><![CDATA[Project.Web.UI.Automation.Test.login.TestLogin.BlankPassword]]></warning>
<message level="normal"><![CDATA[The previous error was converted to a warning because the task was called with ContinueOnError=true.]]></message>
<message level="high"><![CDATA[ Selenium.SeleniumException : Timed out running command]]></message>
<message level="high"><![CDATA[ at Selenium.Internal.CommandTimer.Execute(SeleneseCommand commandToExecute, IWebDriver commandDriver, String[] commandArguments)]]></message>
<message level="high"><![CDATA[ at Selenium.WebDriverCommandProcessor.DoCommand(String command, String[] args)]]></message>
<message level="high"><![CDATA[ at Project.PageObjects.LoginPage.LoginToProject(String username, String password) in c:\Projects\Project\AutomationUpdate\Source\Project.Web.UI.Automation\PageObjects\login\LoginPage.cs:line 21]]></message>
<message level="high"><![CDATA[ at Project.Web.UI.Automation.Test.login.TestLogin.BlankPassword() in c:\Projects\Project\AutomationUpdate\Source\Project.Web.UI.Automation\Test\login\TestLogin.cs:line 60]]></message>
<message level="high" />
Anything I'm doing wrong here?
EDIT :
The previous error was due to an outdated Selenium driver. Now we're getting a different Exception:
SetUp : OpenQA.Selenium.WebDriverException : An error occurred while connecting to Firefox
----> System.IO.IOException : The directory is not empty.
at OpenQA.Selenium.Firefox.FirefoxDriver.StartClient()
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxBinary binary, FirefoxProfile profile, TimeSpan commandTimeout)
at Project.Web.UI.Automation.Test.login.TestLogin.SetUp() in c:\Projects\Project\AutomationUpdate\Source\Project.Web.UI.Automation\Test\login\TestLogin.cs:line 16
--IOException
at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound)
at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
at OpenQA.Selenium.Firefox.FirefoxExtension.Install(String profileDir)
at OpenQA.Selenium.Firefox.FirefoxProfile.InstallExtensions()
at OpenQA.Selenium.Firefox.FirefoxProfile.WriteToDisk()
at OpenQA.Selenium.Firefox.Internal.ExtensionConnection.Start()
at OpenQA.Selenium.Firefox.FirefoxDriver.StartClient()
The same code runs perfect when run under CCNET console. Any ideas?

probably a security problem, or a 'user interactive one'
since ccnet runs as local system, it does not have a real 'home' folder.
so probably it can not find the firefox exe, did you specify a path to it?
or it may not access the path
there are a few things you can do :
run ccnet service as the same user you do interactively
alter the security of the folders, so that local system may access them
option 1 is the easiest :-)

Seems my requirement cannot be met by CCNET after all. This is a technical impossibility. We chose to go with another CI server.

Related

How to override value of TeamCity System Variable Using MSBuild?

TeamCity Configuration:
Below is the Build Number format setting done in TeamCity
%system.BuildVersion%
Where BuildVersion is defined as system parameter.
MSBuildScript
<GetAssemblyIdentity
AssemblyFiles="$(PPTCompiledOutputDirPath)\$(FileNameForAssembly)">
<Output TaskParameter="Assemblies" ItemName="AssemblyIdentity"/>
</GetAssemblyIdentity>
<PropertyGroup>
<Pattern>(\d+)\.(\d+)\.(\d+)\.</Pattern>
<In>%(AssemblyIdentity.Version)</In>
<OutVersion>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern)))</OutVersion>
</PropertyGroup>
<Message Text="$(OutVersion)" />
<Message Text="##teamcity[buildNumber '$(OutVersion)$(BuildCounter)']" />
<Message Text="##teamcity[setParameter name='BuildVersion' value='$(OutVersion)$(BuildCounter)']"/>
I want to update the value for parameter 'BuildVersion' as Assembly Version and Build Counter.
Here I am getting the issue on execution of the Teamcity and execution get cancelled.
The proper way to set the buildNumber is:
<Message Importance="High" Text="##teamcity[buildNumber '$(OutVersion)$(BuildCounter)']" />

Why doesn't Visual Studio Build output the Message in the Target element having a custom name?

My project has a different behaviour locally and on production.
I have concluded that some Tasks in my .vbproj don't get executed locally neither in DEBUG or RELEASE mode. For example, I have a Message in a element, and it doesn't appear in the OUTPUT window after build.
Is my conclusion wrong? Am I missing something here?
doesn't display message in console:
<Target Name="test12345">
<Message Text="This is a test message" Importance="high" />
</Target>
displays message in console:
<Target Name="AfterBuild">
<Message Text="This is a test message" Importance="high" />
</Target>
The AfterBuild name makes it automatically run after a project is built (to be specific, AfterBuild is already defined but meant to be overwritten in custom projects).
When you define a target with a custom name, you need to hook it into the build as well, e.g. by using AfterTargets:
<Target Name="test12345" AfterTargets="Build">
<Message Text="This is a test message" Importance="high" />
</Target>

ccnet error with msbuild and nuget error code="MSB3073"

I've been struggling with this error for quite some time.
I've scrubbed the paths, but I've checked the paths and the sources and they are correct. I've checked the proxy and it works. I've run the command in a command line and it works fine, but ccnet / msbuild logs these errors.
<message level="high"><![CDATA["C:\Develop\Web\.nuget\NuGet.exe" install "C:\Develop\Web\MyCompany.MyProject\packages.config" -nocache -source "https://www.nuget.org/api/v2/;http://ec2-54-201-44-121.us-west-2.compute.amazonaws.com/nuget/" -NonInteractive -solutionDir "C:\Develop\Web\ "]]></message>
<error file="WARNING" line="0" column="0" timeStamp="02/27/2014 11:40:52"><![CDATA[(403) Forbidden.]]></error>
<error file="WARNING" line="0" column="0" timeStamp="02/27/2014 11:40:52"><![CDATA[(403) Forbidden.]]></error>
<error file="WARNING" line="0" column="0" timeStamp="02/27/2014 11:40:52"><![CDATA[(403) Forbidden.]]></error>
<error file="WARNING" line="0" column="0" timeStamp="02/27/2014 11:40:52"><![CDATA[(403) Forbidden.]]></error>
<message level="high"><![CDATA[Installing 'MyProject.MyCompany.Common 1.0.0'.]]></message>
<message level="high"><![CDATA[Installing 'MyProject.EnterpriseLibrary.4.1 1.0.1'.]]></message>
<message level="high"><![CDATA[Installing 'MyProject.Web.Cms.Libraries 1.0.0'.]]></message>
<message level="high"><![CDATA[Installing 'MyProject.MyCompany.Interactive.DataAccess 1.0.0'.]]></message>
<message level="high"><![CDATA[Successfully installed 'MyProject.MyCompany.Interactive.DataAccess 1.0.0'.]]></message>
<message level="high"><![CDATA[Successfully installed 'MyProject.MyCompany.Common 1.0.0'.]]></message>
<message level="high"><![CDATA[Successfully installed 'MyProject.EnterpriseLibrary.4.1 1.0.1'.]]></message>
<message level="high"><![CDATA[Successfully installed 'MyProject.Web.Cms.Libraries 1.0.0'.]]></message>
<error code="MSB3073" file="C:\Develop\Web\.nuget\NuGet.targets" line="88" column="9" timeStamp="02/27/2014 11:41:03"><![CDATA[The command ""C:\Develop\Web\.nuget\NuGet.exe" install "C:\Develop\Web\MyCompany.MyProject\packages.config" -nocache -source "https://www.nuget.org/api/v2/;http://ec2-54-201-44-121.us-west-2.compute.amazonaws.com/nuget/" -NonInteractive -solutionDir "C:\Develop\Web\ "" exited with code -1.]]></error>
</project>
Log in as the IDENTIY (domain\username) that CC.NET service is running.
I had something similar with a source-control command line tool.
Once I logged in as the identity the service was using.......and ran the command line (that you say works ), I saw the error quickly.
So this is kind of an educated guess. But I've seen something similar.
If you don't have a dedicated identity (domain\username) to run the CC.NET Service.........I'd create one.
You can also stop the service..and (temporarily) run cc.net from the command line........but again.....logged in as the identity that runs the cc.net-service.

MSBuild /m:4 fails because it builds the same project twice

My team has a large solution (~500 csproj's). We use VS2012, and build using TFS Build, which uses MSBuild 4. Currently we build serially, but we want to build in parallel (using msbuild /maxcpucount:4). However, when I try it on my 4-proc machine, I get a weird failure:
11:2>CSC : fatal error CS0042: Unexpected error creating debug information file 'C:\Common\obj\Debug\Common.PDB' -- 'C:\Common\obj\Debug\Common.pdb: The process cannot access the file because it is being used by another process. [C:\Common\Common.csproj]
Looking at the log, 2 msbuild nodes were trying to build that same csproj, and thus colliding on writing some output:
10>Project "C:\Utils\Utils.csproj" (10) is building "C:\Common\Common.csproj" (11) on node 4 (default targets).
46:2>Project "C:\Objects\Objects.csproj" (46:2) is building "C:\Common\Common.csproj" (11:2) on node 1 (default targets).
Why would MSBuild try to build the same project twice?
Cause: Someone was calling <MSBuild Projects="Common.csproj" Properties="..." />. Then, MSBuild thinks that it should build Common.csproj again with those different properties, and it happened to occur at the same time with the regular compilation of Common.csproj.
Fix: Call <MSBuild ... /> without those unneeded properties.
Test:
Common.targets
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<Message Importance="high" Text="Build in $(MSBuildThisFile)" />
</Target>
<Target Name="After" DependsOnTargets="Build">
<Message Importance="high" Text="After in $(MSBuildThisFile)" />
</Target>
</Project>
Other.targets
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<Message Importance="high" Text="Build in $(MSBuildThisFile)" />
<MSBuild Projects="common.targets" Targets="Build" /> <!-- regular builds -->
<MSBuild Projects="common.targets" <!-- custom invocation with properties -->
Targets="After"
Properties="myprop=myvalue"
/>
</Target>
</Project>
Run:
> msbuild other.targets /clp:verbosity=minimal
Build in other.targets
Build in common.targets
Build in common.targets <<<< Common.targets Build is invoked again
After in common.targets
And indeed, removing Properties="myprop=myvalue" solves the issue.
I found someone had added two project references (from the same project) and that apparently caused msbuild to build twice also.. something to watch out for

MSBuild hangs after NUnit is finished

I'm trying to set up a MSBuild with NUnit as unit test driver but the script keeps hanging after NUnit is done. It doesn't seem to finalize its work and let MSBuild get on with its job.
I'm working in .NET 4.0 and using NUnit 2.5.8.
If I run the test manually or using the gui (either VS2010 or NUnit) it works fine but not when called by MSBuild.
I'd appreciate any help with error finding or just a heads up on where to looks for answers.
The manual command looks like this:
C:\....>nunit\nunit-console.exe buildbinaries\YYYY.XXXX.Extractor.Test.IntegrationTest.dll /xml=nunit.xml
and the abbreviated MSBuild:
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- define folders for build output and reports -->
<PropertyGroup>
<BuildPath>buildbinaries\</BuildPath>
<ReportPath>buildreports\</ReportPath>
<ReleaseFolder>release_artefacts\</ReleaseFolder>
<PublishFolder>c:\ZZZ Applications\published builds\</PublishFolder>
<DeploymentFolder>\\seldclq99\ZZZ_Costanza_Dev$\</DeploymentFolder>
</PropertyGroup>
<PropertyGroup>
<!-- specify assemblies that should be included in coverage report -->
<NCoverAssemblyList>YYYY.XXXX.Extractor.Business.dll; YYYY.XXXX.Extractor.Common.dll YYYY.XXXX.Extractor.Configuration.dll YYYY.XXXX.Extractor.DAL.Access.dll YYYY.XXXX.Extractor.DAL.Facade.dll YYYY.XXXX.Extractor.Service.Contracts.dll YYYY.XXXX.Extractor.Service.dll YYYY.XXXX.Extractor.Service.Host.WebHost.dll YYYY.XXXX.Extractor.ServiceGateway.dll</NCoverAssemblyList>
</PropertyGroup>
<!-- define item group for deliverables -->
<ItemGroup>
<Binaries Include="$(BuildPath)/**/*.*" Exclude="$(BuildPath)nunit*" />
</ItemGroup>
<!--
This is the default target that will be executed if MSBuild is not started
with a specific target (this is decided by the DefaultTargets attribute in
the root element of this XML document)
-->
<Target Name="BuildAndTest">
<CallTarget Targets="SetupDirs" />
<CallTarget Targets="Build" />
<CallTarget Targets="UnitAndIntegrationTest" />
<CallTarget Targets="FxCop" />
<CallTarget Targets="CopyToReleaseFolder" />
</Target>
<!-- Setup folders used during the build -->
<Target Name="SetupDirs">
<RemoveDir Directories="$(ReportPath);$(BuildPath);$(ReleaseFolder)" ContinueOnError="true"/>
<MakeDir Directories="$(ReportPath);$(BuildPath);$(ReleaseFolder);$(AssemblyVersionFolder)" ContinueOnError="true"/>
</Target>
<Target Name="Build">
<!-- build the software using msbuild -->
<!-- Build error in the Install build-->
<MSBuild ContinueOnError="true" RebaseOutputs="false" Targets="Clean;Rebuild" Projects="YYYYXXXXExtractor.sln" Properties="Configuration=Release;OutDir=..\$(BuildPath)" />
</Target>
<!--Run the coverage stats-->
<Target Name="UnitAndIntegrationTest">
<Exec Command="nunit\nunit-console.exe buildbinaries\YYYY.XXXX.Extractor.Test.IntegrationTest.dll /xml=$(ReportPath)nunit.xml "/>
<CallTarget Targets="UnitTest" />
</Target>
<Target Name="UnitTest">
<Exec Command="nunit\nunit-console.exe buildbinaries\YYYY.XXXX.Extractor.Test.UnitTest.dll /xml=$(ReportPath)nunit.xml"/>
</Target>
<!-- Run FxCop -->
<!-- The ForceError.bat fires if the xml file is not found... aka an error was found -->
<!-- The quiet command forces an Xml file ONLY if warnings or Errors are found -->
<Target Name="FxCop">
<Exec Command="..\tools\fxcop\FxCopCmd.exe /p:..\FxCopSettings.FxCop /o:$(ReportPath)fxcop.xml" />
<Exec Condition="Exists('$(ReportPath)fxcop.xml')" Command="..\tools\fxcop\FX_Cop_Failed_Rule_Checks.bat" />
<!--STATS: Run again but don't fail and this time run for all rules.-->
<Exec Command="..\tools\fxcop\FxCopCmd.exe /p:..\FxCopSettingsALLRULES.FxCop /o:$(ReportPath)fxCopAllRules.xml" />
</Target >
I had the same problem with NUnit 2.5.8. There is some discussion of this at the nunit site about the test process hanging. I switched to NUnit 2.5.7 and the problem went away.
It looks like this was fixed a couple of weeks ago in 2.5.9.
I have noticed similar behaviour on out build server since upgrading to .NET 4. MsBuild seems to intermittently hang on either NUnit, FxCop or Dotcover EXEC commands. If you check task manager the process for externally executed command (e.g. Nunit.exe) is still hanging around. If you manually kill the process MsBuild continues on it's merry way - which is far from ideal!
Could this be a bug in the latest version of MsBuild? Our build server was running quite happily until the .NET 4 upgrade.
If you run ProcessExplorer on your server you will notice that an out of band process called nunit-agent is spawned which ends up blocking the nunit runner.
I have not validated that this is fixed in 2.5.9, but it might be some info that could be helpful.