Selenium Chromdriver Tests on TeamCity is loading indefinitely
I want to run my Selenium test in TeamCity and I'm using ChromeDriver for initialization. When I click "run" in TeamCity, the test starts loading but as soon as it reaches the ChromeDriver in the setup the build just keeps loading indefinitely and nothing happens. There is no error message it just keeps loading and it seems like it doesn't enter the test. Strangely it works fine locally.
private static ChromeDriverService instance = null;
public static ChromeDriverService Instance
{
get
{
Console.WriteLine("Instance start");
if (instance == null)
{
instance = new ChromeDriverService();
}
Console.WriteLine("Instance end");
return instance;
}
}
public IWebDriver Driver = null;
public ChromeDriverService()
{
if (instance != null) throw new InvalidOperationException();
}
private IWebDriver InitializeWebDriver()
{
Console.WriteLine("InitializeWebDriver start");
if (Driver != null) return Driver;
ChromeOptions options = new ChromeOptions();
options.AddArgument("headless");
options.AddArgument("--disable-gpu");
options.AddArgument("disable-search-engine-choice-screen");
new DriverManager().SetUpDriver(new ChromeConfig());
Driver = new ChromeDriver(options);
Console.WriteLine("InitializeWebDriver end");
return Driver;
}
Please sign in to leave a comment.
If you're running UI tests with the TeamCity build agent as a Windows service, which is common, you might want to check for potential limitations in that setup:https://www.jetbrains.com/help/teamcity/known-issues.html#Issues+with+automated+GUI+and+browser+testing.
To overcome these restrictions, run TeamCity agent via console (https://www.jetbrains.com/help/teamcity/start-teamcity-agent.html).
While I can't confirm if your issue is exactly related to this, you can find some troubleshooting tips here: https://www.jetbrains.com/help/teamcity/common-problems.html#Build+works+locally+but+fails+or+misbehaves+in+TeamCity. The issue likely stems from differences between your development environment and the TeamCity build agent environment, which can cause unexpected behavior.
Hi Tom,
thanks for your help but we have multiple environments and only one agent. The agent can be selected at the TeamCity webinterface:
But I dont know the way to choose the correct environment with the command line.
Could you help me with that please?
Hi Josh,
In your case, it seems that the issue might be related to the known .NET Selenium (https://www.jetbrains.com/help/teamcity/known-issues.html#Issues+with+.NET+Selenium).
When a TeamCity agent is started as a Windows service, automated tests for .NET applications using Selenium WebDriver may fail due to browser driver limitations. To resolve this, consider starting the agent manually instead of running it automatically as a service.
You can use the following script to start the agent manually(https://www.jetbrains.com/help/teamcity/start-teamcity-agent.html):
On Windows: