如何在ChromeDriver中启用详细日志记录? (GebConfig)

时间:2017-11-07 10:13:02

标签: google-chrome selenium selenium-webdriver webdriver selenium-chromedriver

我必须在Chrome / ChromeDriver中启用详细日志记录才能查看我的geb测试失败的原因。有谁知道我怎么能做到这一点。继承人我的GebConfig:

String chromeDriverDownloadFullPath = "https://chromedriver.storage.googleapis.com/${chromeDriverVersion}/${chromeDriverZipFileName}"
File chromeDriverLocalFile = downloadDriver(
        currentPlatformName,
        chromeDriverDownloadFullPath,
        chromeDriverExecFileName,
        'zip',
        "chrome",
        chromeDriverVersion)

System.setProperty('webdriver.chrome.driver', chromeDriverLocalFile.absolutePath)

Locale locale = getLocale()
ChromeOptions options = new ChromeOptions();
options.addArguments("--lang=" + locale.country);
options.addArguments("--headless");
options.addArguments("--disable-gpu");
options.addArguments("--no-sandbox");
options.addArguments("--user-data-dir=/data");


DesiredCapabilities jsCapabilities = DesiredCapabilities.chrome()
Map<String, Object> prefs = new HashMap<>()
prefs.put("intl.accept_languages", locale.toLanguageTag())
options.setExperimentalOption("prefs", prefs)
jsCapabilities.setCapability(ChromeOptions.CAPABILITY, options)

ChromeDriver chromeDriver = new ChromeDriver(options)
chromeDriver.manage().window().setSize(getDimension())
return chromeDriver

2 个答案:

答案 0 :(得分:2)

要从 ChromeDriver 获取详细日志,我们可以配置 logfile type_of_logging 如下:

System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
System.setProperty("webdriver.chrome.logfile", "C:\\Utility\\BrowserDrivers\\chromedriver.log");
System.setProperty("webdriver.chrome.verboseLogging", "true");

更新:

我可以从您提供的代码中看到:

System.setProperty('webdriver.chrome.driver', chromeDriverLocalFile.absolutePath) 

以类似的方式尝试提供:

System.setProperty('webdriver.chrome.logfile', chromeDriverLocalFile.absolutePath);
System.setProperty('webdriver.chrome.verboseLogging', boolean);

答案 1 :(得分:0)

来自documentation of ChromeDriver - WebDriver for Chrome

System.setProperty("webdriver.chrome.logfile", "Your path");
System.setProperty("webdriver.chrome.verboseLogging", "true");