message: Added browser tests for the error handler
diff: @@ -8,8 +8,13 @@ var firefox = require('selenium-webdriver/firefox');
  var chrome = require('selenium-webdriver/chrome');
  var error = require('selenium-webdriver/lib/error');
  -var browsers = { 'Firefox': new firefox.Options().addArguments('-headless'), 'Chrome': new chrome.Options().addArguments('headless', 'disable-gpu', 'disable-software-rasterizer', 'no-sandbox', 'disable-dev-shm-usage') };
  -if(process.env.DA_NOHEADLESS == 1) var browsers = { 'Firefox': new firefox.Options(), 'Chrome': new chrome.Options() };
  +let logging_prefs = new webdriver.logging.Preferences();
  +logging_prefs.setLevel(webdriver.logging.Type.BROWSER, webdriver.logging.Level.ALL)
  +var browsers = { 'Firefox': new firefox.Options(), 'Chrome': new chrome.Options().setLoggingPrefs(logging_prefs) };
  +if(process.env.DA_NOHEADLESS != 1) {
  + browsers['Firefox'].addArguments('-headless');
  + browsers['Chrome'].addArguments('headless', 'disable-gpu', 'disable-software-rasterizer', 'no-sandbox', 'disable-dev-shm-usage')
  +}
  Object.keys(browsers).forEach(function(browser) {
  describe('Browser testing with ' + browser, function() {
  @@ -117,6 +122,35 @@ Object.keys(browsers).forEach(function(browser) {
  });
  });
  + describe('Error handler', function() {
  + beforeEach(async function() { await driver.get('http://localhost:8080/en'); });
  +
  + // Reading the console logs is only possible in Chrome as that interface is not in the webdriver spec.
  + if(browser == 'Chrome') {
  + it('Errors should be logged to the console', async function() {
  + // I feel like this might need some explaining. Our error handler does not fire for errors caused by code executed in certain ways, like code entered into the console, for example. The same appears to be the case for code executed through driver.executeScript(). Now, for some reason, it does however fire for code executed using the `javascript:` 'protocol'. The problem then is that `driver.get(url)` does not support that protocol. Someone however kindly decided that `document.location = 'javascript:somecode'` should indeed execute said code, which seems incredibly odd and wrong to me but I'll gladly take it, of course.
  + await driver.executeScript('document.location = \'javascript:(function(){throw new Error("Browsers are awesome!")})();\';').catch(() => {});
  + expect((await driver.manage().logs().get(webdriver.logging.Type.BROWSER))[0].message).to.include('%cAn unexpected error occurred:');
  +
  + });
  + }
  +
  + // Error modals are only ever shown in Firefox since Chrome discards all useful information on error events. For more details, see the comments in `error-handler.js`.
  + if(browser == 'Firefox') {
  + it('Errors with level <= 3 should show a modal', async function() {
  + expect(await $('.modal'), 'For this test to work, there cannot be a previous modal.').to.not.be.ok;
  +
  + // code > 3
  + await driver.executeScript('document.location = \'javascript:(function(){let error = new Error("Not too bad."); error.code = 4; throw error;})();\';').catch(() => {});
  + expect(await $('.modal'), 'Error modal shown for code 4.').to.not.be.ok;
  +
  + // code <= 3
  + await driver.executeScript('document.location = \'javascript:(function(){let error = new Error("Oh dear, this is awful."); error.code = 0; throw error;})();\';').catch(() => {});
  + expect(await $('.modal'), 'Error modal not shown for code 0.').to.be.ok;
  + });
  + }
  + });
  +
  after(function() {
  if(!process.env.DA_NOHEADLESS) driver.quit();
  });
  