我有以下代码以无头模式运行测试。我想知道如何将无头模式关闭为在实际浏览器中运行测试以进行调试。
public static void InitBrowser(BrowserEnum browserName)
{
const string _seleniumGridUrl = "http://devops-seleniumhub.vuturegroup.local:4444/wd/hub";
switch (browserName)
{
case BrowserEnum.Chrome:
if (driver == null)
{
var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--headless");
remoteDriver = new RemoteWebDriver(new Uri(_seleniumGridUrl), chromeOptions.ToCapabilities());
remoteDriver.Manage().Timeouts().PageLoad = new TimeSpan(0, 0, 20);
remoteDriver.Manage().Timeouts().AsynchronousJavaScript = new TimeSpan(0, 0, 30);
ngDriver = new NgWebDriver(remoteDriver);
ngDriver.Manage().Timeouts().PageLoad = new TimeSpan(0, 0, 20);
driver = remoteDriver;
Drivers.Add(BrowserEnum.Chrome, ngDriver);
}
break;}}
删除无头参数时,出现以下错误
Message: OneTimeSetUp: System.InvalidOperationException : unknown error: Chrome failed to start: exited abnormally (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 3.10.0-862.11.6.el7.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 175 milliseconds
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:32:19.891Z'
System info: host: 'devops-lseln01', ip: '192.168.10.16', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-862.11.6.el7.x86_64', java.version: '1.8.0_181'
Driver info: driver.version: unknown
答案 0 :(得分:0)
您只需删除以下传递“无头”参数的行:
chromeOptions.AddArgument("--headless");