ChromeDriverService and Azure DevOps Agents - selenium

I am currently running Selenium tests through an Azure DevOps pipeline using C#.
I made a change to my code to write ChromeDriver logs, which necessitated a change to using the ChromeDriverService.
string binaryDir = Manager.GetWebDriver(Manager.BrowserType.CHROME,os,browser);
if (options == null) options = new ChromeOptions();
options.AddUserProfilePreference("download.default_directory", ExtentReporter.ReportDir);
options.SetLoggingPreference(LogType.Browser, LogLevel.Info);
options.UnhandledPromptBehavior = UnhandledPromptBehavior.Ignore;
Console.WriteLine("Chrome Logging path: "+chromeLogPath);
var service = ChromeDriverService.CreateDefaultService(binaryDir);
service.LogPath = chromeLogPath;
service.EnableVerboseLogging = true;
_driver = new ChromeDriver(service, options);
_driver.Manage().Window.Maximize();
return _driver;
After making this change the chromedriver is no longer able to open with the error:
OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:52257/
I have also copied the compiled code out of the Agent directory and executed it via command line and it was able to run all tests. BUT when executed via command line within the Agent work directory the ChromeDriverService threw the previous exception.
I believe the issue is related to the creation of the ChromeDriver logs, but I am also generating files in the Agent Work directory without any errors.
Any previous experience of the WebDriveService or generating ChromeDriver logs through Azure DevOps will be much obliged.

I solved this shortly after eventually posting.
Run the agent as administrator resolves it.

Related

C# : Cannot run selenium tests in parallel while using a Chrome profile

I am trying to run tests in parallel , however I am not able to. It triggers only one failing the other. I am using Chrome profiling option ("user-data-dir") to launch Chrome. If I disable this option, the tests run just fine in parallel. Can somebody tell me what I could be missing?
The argument that I have added is
public string ChromeProfilePath= "C:\Users\myuser\AppData\Local\Google\Chrome\User Data";
ChromeOptions options = new ChromeOptions();
options.AddArgument(string.Format("user-data-dir={0}", ChromeProfilePath));
ChromeDriver driver = new ChromeDriver(options);
It invokes the driver session with the current chrome profile successfully when a test is run but fails when run in parallel (invokes one instance, test it and fails the rest).
The error I receives for the failed one is
OpenQA.Selenium.WebDriverException : unknown error: failed to write prefs file
Note: I am using NUnit as test framework, C# and Selenium

Selenium navigate().to() stuck without error

I am running tests using TestNG, chromium and Selenium, in Java, on two machines:
my own laptop
a Mac Mini I do not have physical access to, that I connect via SSH, that has the same identical project structure as the project on my laptop.
Both machines operate behind the same corporate proxy.
The issue I am having is the following:
while the tests run smoothly on my machine, when I execute the command to start them on the Mac Mini, the execution stops when telling the Selenium WebDriver to navigate to any specified url using driver.navigate().to(url) or driver.get(url); causing the program to freeze without throwing any exception, essentially remaining on hold.
The code resembles the following:
in the #BeforeClass beforeClass() driver is initialized with an instance of ChromeDriver using ChromeOptions. Among other settings, I add the following arguments to the ChromeOptions like such chromeOptions.addArguments(options): where options is things like --disable-web-security, --allow-running-insecure-content, --allow-insecure-localhost and most importantly: --proxy-server=address:port (e.g. --proxy-server=172.26.44.146:3128).
in the #BeforeMethod beforeMethod() after checking that the driver is not null and that the URL url is a valid one, I execute something similar to the stylized following code:
try {
log.debug("Navigating to: " + url);
driver.navigate().to(url);
log.debug("Navigated to url: " + driver.getCurrentUrl());
} catch (Exception e) {
log.error("Unable to navigate at page: " + url.toString());
throw e;
}
As I said, when running the test on the Mac Mini via SSH using the command line in a similar fashion to: java -cp WORKSPACE org.testng.TestNG testng.xml the code stops executing and freezes at log.debug("Navigating to: " + url); essentially not producing other output and forcing me to manually stop the execution of the test.
As additional information, tests are run using chromium version 72.0.3609.0.
The ChromeOptions also receive the following proxy setting (like such: chromeOptions.setProxy(p);) where p is a Proxy with
p.setProxyType(ProxyType.MANUAL);
p.setAutodetect(false);
I suspect an issue with the proxy (and am doubtful I have correctly preconfigured the program), but, quite frankly, I am puzzled by the fact that the same script runs locally on my machine and is unable to run locally on the Mac Mini when the tests are launched via SSH.

Selenium tests works in local but not in Gitlab CI

I am currently working on a Java Spring Boot project which involves a classic backend/frontend architecture. I am trying to write some basic integration test by using the Selenium WebDriver.
The problem is that the tests I write pass without any problem on my local development machine but do not pass when I run them thorugh the continuous integration setup (Gitlab CI).
The code of the example test is the following:
#RunWith(SpringRunner.class)
#SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
#ActiveProfiles("test")
public class ExampleTest {
#LocalServerPort
private int port;
WebDriver wd;
#Test
public void successfulLogin(){
String url = "http://localhost:" + port;
wd = new HtmlUnitDriver();
wd.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
wd.get(url);
}
}
The relative gitlab-ci.yml portion is:
stages:
- test
maven-test:
image: maven:3.5.0-jdk-8
stage: test
script: "mvn test -B -Dmaven.repo.local=/root/.m2/"
only:
- master
The CI has a single runner (version 9.5.0) with concurrency 1. It uses the docker executor with the docker:stable image. I don't know if it is needed, but it is running in priviledged mode.
When running the tests on the CI environment, they fail with the following error:
org.openqa.selenium.TimeoutException: java.net.SocketTimeoutException: Read timed out
I have tried both with url = "http://localhost:" + port and url = InetAddress.getLocalHost().getHostName() + ":" + port, both passed locally, none passed in the CI environment.
What am I doing wrong?
EDIT: Alfageme suggested a more accurate testing methodology. On the same server on which the CI is running, I cloned my repository with git clone and then run the following command:
sudo gitlab-runner exec docker maven-test
The test passed without any problem. I am really running out of ideas, does someone have any?
I am not exactly sure why, but clearing the various runner-XXXXX-project-21-concurrent-0-cache-XXXXXXXXXXXXXXXXXXX docker containers on the CI machine seemed to have solved the issue.
EDIT: This fixed the issue only momentarely. The problem happened again, this time clearing the cache voulmes did not help. Anyone has any suggestion?

"you are using an unsupported command-line flag: --ignore-certificate-errors." error displayed in slave while executing selenium script

I am executing selenium scripts in slave machine using Jenkins where I am getting below error.
"you are using an unsupported command-line flag:
--ignore-certificate-errors."
Same scripts are working fine on my local using same chromedriver.exe file. Please note that I have placed chromedriver.exe file in a seperate folder from where script is launching it.
Chrome Version:59.0.3071.115
Selenium Version:2.52.0
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--test-type");// this is the one that helped
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("https://www.google.com");
This resolved similar issue
--disable-infobars seems not to be working as well
As of 2022, what your looking for is CommandLineFlagSecurityWarningsEnabled
On Debian, you can create a managed policy via the following command:
mkdir -p /etc/opt/chrome/policies/managed && echo '{"CommandLineFlagSecurityWarningsEnabled":false}' >> /etc/opt/chrome/policies/managed/managed_policies.json

How to run Firefox in a Scheduled Task in Windows 2012 R2

Context: Microsoft Azure / Windows 2012 R2; C#; Selenium.Webdriver 3.4.0; Selenium.Support 3.4.0; Selenium.WebDriver.GeckoDriver.Win64 0.18.0; Firefox 54.0.1 (64-bit); geckodriver 0.18.0
I'm having enormous difficulty getting the Firefox session to launch inside a Windows Service Scheduled Task. I have no problem launching a Selenium-driven Firefox session from a C# exe interactively.
The Scheduled Task is set to "Run whether user is logged on or not", and "Run with highest privilege" is checked.
Part of the code in this boiled-down exe:
FirefoxProfile fp = new FirefoxProfile(#"C:\web\FirefoxProfiles\Thingo");
fp.AcceptUntrustedCertificates = true;
FirefoxOptions fo = new FirefoxOptions();
fo.Profile = fp;
fo.LogLevel = FirefoxDriverLogLevel.Debug;
fo.BrowserExecutableLocation = #"C:\Program Files\Mozilla Firefox\firefox.exe";
var ts = TimeSpan.FromMinutes(1);
IWebDriver driver = null;
try
{
driver = new FirefoxDriver(fo);
}
catch (Exception E)
{
Console.WriteLine(E.Message);
Environment.Exit(255);
}
After a minute of running that code I get the following Message:
The HTTP request to the remote WebDriver server for URL http://localhost:51289/session timed out after 60 seconds.
Interestingly, according to Task Manager, geckodriver.exe has --port 51289 on its command line.
I've been trying various combinations of FirefoxDriver invocations. None work as expected giving the above error or
Unable to find a matching set of capabilities
which makes even less sense. I've also tried a couple of different versions of Firefox, all to no avail.
Is there some Selenium, Firefox or, for that matter, Windows setting that might be affecting the running of the scheduled task? The task launches, and the binary runs, but Firefox is not launched.