Skip to content

Instantly share code, notes, and snippets.

@antony
Created October 24, 2016 10:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antony/5bc8d768946972ab0a2bfca57b857313 to your computer and use it in GitHub Desktop.
Save antony/5bc8d768946972ab0a2bfca57b857313 to your computer and use it in GitHub Desktop.
Get JavaScript console errors in Geb
package myapp.specs.base
import geb.spock.GebReportingSpec
import spock.lang.Shared
import static org.openqa.selenium.logging.LogType.BROWSER
abstract class BrowserLoggingBaseSpec extends GebReportingSpec {
void cleanup() {
try {
driver.executeScript("console.log('Test finished')")
def logEntries = driver.manage().logs().get(BROWSER).all
println "START WebDriver $BROWSER logs"
logEntries.each {
println(it)
}
println "END WebDriver $BROWSER logs"
} catch (error) {
error.printStackTrace()
}
}
}
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.logging.LoggingPreferences
import org.openqa.selenium.remote.DesiredCapabilities
import static java.util.logging.Level.ALL
import static org.openqa.selenium.logging.LogType.BROWSER
import static org.openqa.selenium.remote.CapabilityType.LOGGING_PREFS
driver = {
DesiredCapabilities capabilities = DesiredCapabilities.chrome()
ChromeOptions options = new ChromeOptions()
options.setExperimentalOption("prefs", ["browser.custom_chrome_frame": false])
capabilities.setCapability(ChromeOptions.CAPABILITY, options)
LoggingPreferences logPrefs = new LoggingPreferences()
logPrefs.enable(BROWSER, ALL)
capabilities.setCapability(LOGGING_PREFS, logPrefs)
return new ChromeDriver(capabilities)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment