DIfferent encoding when running TC agent as service vs batch script
Hi!
I am trying TC to start a UI test job on selenium but for some reason it does not work as expected. The problem is that when test script tries to enter a "@" into an input field no character is actually displayed. I modified the script to see if SHIFT+2 would enter a "@" but instead I get double quotes symbol ("). That implies that the keyboard layout is set to some other language. In fact, the system locale default is Slovenian and explains the double quote. Now, the funny part.
The TC agent service is running under account userx. If I stop the service and start it from command line (C:\BuildAgent\bin\agent.bat start, under the same account from a console with administrative privileges) it works just fine - @ is entered as expected.
I have tried to supply -Dfile.encoding=UTF-8 (and user.language=en, user.country=US) to java. While the parameter's new values can be seen in TC web console it does not affect the result - still fails.
I run UI tests within a powershell script. Before I even try to execute the selenium tests I print out the available keyboard layouts and I only get English (which I found strange since I can't get @). I see Slovenian only as a default locale by executing [System.Text.Encoding]::Default.
I've checked the environment variables on TC web console when agent is started from batch file and when started as service.There are a few differences but nothing that would suggest a change in locale.
I also tried by removing -NoProfile from the build step that starts powershell but results were the same.
I also tried to run the agent from command line (logged in as userx but run as Administrator) manually with the same java command that is used to run the agent by the service (e.g. c:\BuildAgent\jre\bin\java.exe -ea -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -Xrs -Dlog4j.configuration=file:../conf/teamcity-agent-log4j.xml -Dteamcity_logs=../logs/ -classpath ..... ). It works!
The only difference I can think of is that the service is starting the agent with TeamCityAgentService-windows-x86-32.exe parameter -s c:\BuildAgent\launcher\conf\wrapper.conf while on the command line I use either agent.bat start or directly starting it by running java command with all the parameters.
Is there a way to make this work with TeamCityAgentService-windows-x86-32.exe as a service? Can I still run the agent as a service without using TeamCityAgentService-windows-x86-32.exe?
environment: Windows server 2019
Thanks in advance
-----------------
Edit 1: Added November 2nd, 2020:
I've noticed the following in the TC documentation:
When a TeamCity agent is started as a Windows service and automated tests for .NET applications use Selenium WebDriver, the tests may fail due to browser drivers limitations. As a solution, consider starting the agent manually.
What does that mean?
Edit 2: Added November 2nd, 2020:
It seems the problem is not TeamCityAgentService-windows-x86-32.exe but maybe it is user impersonation. I have created a scheduled task to start the agent as user userx when system boots up and it does not work either.
Please sign in to leave a comment.
Hi,
I tried reproducing the issue on a Windows Server 2019 agent with Slovenian system locale. I do not have a Selenium project, so I started Notepad and used PowerShell to emulate the keystrokes:
That way it works. The @ sign shows up and not the " sign, even when the agent is running as a Windows service. I am not sure if my test is equivalent to how you are doing it, though. If you could post a sample project that demonstrates the issue, that would help to confirm it.
-Anatoly
Regarding the manual agent start, the documentation page implies that in the described use case the agent has to be started using the agent.bat script as opposed to Windows service. If that doesn't answer your question, please elaborate it.