When running Selenium web tests through TeamCity build agents, many developers encounter the frustrating limitation where tests fail when executed as Windows services. The core issue stems from service sessions lacking:
- GUI interaction capabilities
- Proper rendering contexts
- User-specific registry hives
Here's the verified method I've used in production environments with Server 2008 R2 (works on standard 2008 as well). First, create a backup of your registry before proceeding:
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon] "AutoAdminLogon"="1" "DefaultUserName"="YourUsername" "DefaultPassword"="YourPassword" "DefaultDomainName"="YourDomain" "ForceAutoLogon"="1"
Save this as autologin.reg and merge it via command line:
regedit /s autologin.reg
Since this stores credentials in plaintext, implement these safeguards:
# PowerShell script to encrypt credentials (run once) $secureString = ConvertTo-SecureString "YourPassword" -AsPlainText -Force $encrypted = ConvertFrom-SecureString $secureString Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name "DefaultPassword" -Value $encrypted
For those preferring GUI tools, Microsoft's official solution works reliably:
Autologon.exe username domain password
Download from:
https://docs.microsoft.com/en-us/sysinternals/downloads/autologon
Configure your build agent to trigger test execution after auto-login completes:
@echo off timeout /t 30 /nobreak > NUL start "" "C:\TeamCity\buildAgent\bin\agent.bat" start
Add this batch script to the user's Startup folder.
If auto-login fails, check:
- User must have "Log on locally" rights (secpol.msc)
- Password expiration policies
- Remote Desktop connections blocking console session
When running Selenium web tests on a TeamCity build agent, executing them as a Windows service often leads to issues. The tests perform more reliably when running in an actual user session. This requires the system to automatically log in a specific user after each reboot.
The most reliable method for Windows Server 2008 involves modifying registry values. Here's how to implement it:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
"DefaultUserName"="YourUsername"
"DefaultPassword"="YourPassword"
"AutoAdminLogon"="1"
"ForceAutoLogon"="1"
To apply these changes:
- Open Notepad and paste the above code
- Replace YourUsername and YourPassword with actual credentials
- Save as
autologin.reg - Double-click the file to merge into registry
Storing passwords in plaintext in the registry is a security risk. Consider these alternatives:
- Use a dedicated test account with limited privileges
- Implement additional security measures like IP restrictions
- Regularly rotate the test account password
Microsoft's Sysinternals suite offers a more secure autologon tool:
Autologon.exe username domain password
This encrypts the credentials while providing the same functionality.
If autologin fails:
- Verify the user has "Log on locally" rights
- Check for Group Policy conflicts
- Ensure Terminal Services aren't blocking the login
- Confirm the registry values are correctly set