I have my code like below for initializing edge browser
var options = new EdgeOptions();
options.UseChromium = true;
options.AddArgument("disable-gpu");
options.AddUserProfilePreference("download.default_directory", directoryPath);
options.AddUserProfilePreference("intl.accept_languages", "en");
options.AddUserProfilePreference("disable-popup-blocking", "true");
options.AddUserProfilePreference("download.prompt_for_download", false);
options.AddUserProfilePreference("download.directory_upgrade", true);
options.AddUserProfilePreference("credentials_enable_service", false);
options.AddUserProfilePreference("plugins.always_open_pdf_externally", true);
options.AddUserProfilePreference("profile.password_manager_enabled", false);
options.AddUserProfilePreference("pdfjs.disabled", true);
options.AddArguments("--disable-backgrounding-occluded-windows");
options.AddArgument("--no-sandbox");
options.AddArgument("start-maximized");
var edgeInfo = FileVersionInfo.GetVersionInfo(ConfigurationManager.AppSettings["EdgePath"]);
var version = edgeInfo.FileVersion;
TestContext.Progress.WriteLine($"Edge executable path (under EdgePath in CommonSettings.config): {ConfigurationManager.AppSettings["EdgePath"]}. Edge version: {version}");
new DriverManager().SetUpDriver(new EdgeConfig(), version);
Driver = new EdgeDriver(options);
break;
And when I run my tests with Jenkins and use Chrome browser then tests run fine but when I set it to run with edge browser I face the following issue in Jenkins. NOTE: My Jenkins pipeline is in my local machine only.
OpenQA.Selenium.WebDriverException : unknown error: Microsoft Edge failed to start: crashed.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from msedge location C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe is no longer running, so msedgedriver is assuming that msedge has crashed.)
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.WebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities)
at OpenQA.Selenium.Chromium.ChromiumDriver..ctor(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Edge.EdgeDriver..ctor(EdgeDriverService service, EdgeOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Edge.EdgeDriver..ctor(String edgeDriverDirectory, EdgeOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Edge.EdgeDriver..ctor(String edgeDriverDirectory, EdgeOptions options)
at Moshocart.Tests.Infrastructure.TestCore.Launch(String browserType) in C:\ProgramData\Jenkins\.jenkins\workspace\UIDemo\Tests\Infrastructure\TestCore.cs:line 179
at Moshocart.Tests.Infrastructure.TestBase.InitializeOnce() in C:\ProgramData\Jenkins\.jenkins\workspace\UIDemo\Tests\Infrastructure\TestBase.cs:line 112
--TearDown
at Moshocart.Tests.Infrastructure.TestBase.LogToReports() in C:\ProgramData\Jenkins\.jenkins\workspace\UIDemo\Tests\Infrastructure\TestBase.cs:line 205
at Moshocart.Tests.Infrastructure.TestBase.Quit() in C:\ProgramData\Jenkins\.jenkins\workspace\UIDemo\Tests\Infrastructure\TestBase.cs:line 125
Need help to resolve this above issue. I have tried giving a path for driver like below.
var options = new EdgeOptions();
options.AddArgument("disable-gpu");
options.AddUserProfilePreference("intl.accept_languages", "en");
options.AddUserProfilePreference("disable-popup-blocking", "true");
options.AddUserProfilePreference("download.prompt_for_download", false);
options.AddUserProfilePreference("download.directory_upgrade", true);
options.AddUserProfilePreference("credentials_enable_service", false);
options.AddUserProfilePreference("plugins.always_open_pdf_externally", true);
options.AddUserProfilePreference("profile.password_manager_enabled", false);
options.AddUserProfilePreference("pdfjs.disabled", true);
options.AddArguments("--disable-backgrounding-occluded-windows");
options.AddArgument("--no-sandbox");
options.AddArgument("start-maximized");
var edge = new EdgeConfig();
new DriverManager().SetUpDriver(edge, VersionResolveStrategy.MatchingBrowser);
Thread.Sleep(10000);
var CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var NewDir = $"{CurrentDirectory}\\Edge";
string directoryPath = NewDir;
string fileName = "msedgedriver.exe";
string filePath = SearchFile(directoryPath, fileName);
string filePath1 = "cmd" + " " + filePath;
if (!string.IsNullOrEmpty(filePath))
{
Console.WriteLine("File found: " + filePath);
}
else
{
Console.WriteLine("File not found.");
}
static string SearchFile(string directoryPath, string fileName)
{
string[] files = Directory.GetFiles(directoryPath, fileName);
if (files.Length > 0)
{
return files[0];
}
string[] subDirectories = Directory.GetDirectories(directoryPath);
foreach (string subDirectory in subDirectories)
{
string filePath = SearchFile(subDirectory, fileName);
if (!string.IsNullOrEmpty(filePath))
{
return filePath;
}
}
return null;
}
Console.WriteLine(filePath1);
LogTestOutput("Driver Started $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
Driver = new EdgeDriver(filePath1, options);
LogTestOutput("Driver Ended &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
break;