diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..652a8b6 --- /dev/null +++ b/circle.yml @@ -0,0 +1,6 @@ +machine: + node: + version: v6.1.0 +dependencies: + pre: + - npm i selenium-webdriver@2.53.1 diff --git a/lib/index.js b/lib/index.js index 783d068..fdb550c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -103,14 +103,14 @@ AxeBuilder.prototype.analyze = function(callback) { config = this._config, source = this._source; - inject(driver, source, function() { + inject(driver, source, config, function() { driver .executeAsyncScript(function(context, options, config) { /*global document, axe */ if (config !== null) { - axe.configure(config); + window.axe.configure(config); } - axe.a11yCheck(context || document, options, arguments[arguments.length - 1]); + window.axe.a11yCheck(context || document, options, arguments[arguments.length - 1]); }, context, options, config) .then(callback); }); diff --git a/lib/inject.js b/lib/inject.js index 767ff76..51bd165 100644 --- a/lib/inject.js +++ b/lib/inject.js @@ -37,18 +37,14 @@ function findFramesAndInject(parent, script, driver) { * @private * @param {WebDriver} driver Instance of WebDriver to inject into * @param {String} axeSource Optional Attest source and configure string + * @param {Object} config Optional configure object to pass to iframes * @param {Function} callback Callback to execute when aXe has been injected */ -module.exports = function(driver, axeSource, callback) { +module.exports = function(driver, axeSource, config, callback) { axeSource = axeSource || require('axe-core').source; - var script = '(function () {' + - 'if (typeof axe === "object" && axe.version) { return; }' + - 'var s = document.createElement("script");' + - // stringify so that quotes are properly escaped - 's.innerHTML = ' + JSON.stringify(axeSource + ';' + 'axe.configure({branding:{application:"webdriverjs"}});') + ';' + - 'document.body.appendChild(s);' + - '}());'; + var configSrc = config !== null ? 'axe.configure(' + JSON.stringify(config) + ');' : ''; + var script = axeSource + configSrc + 'axe.configure({branding:{application:"webdriverjs"}});'; driver .switchTo().defaultContent(); diff --git a/package.json b/package.json index fe560d8..04abb6f 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,8 @@ "test": "grunt test" }, "peerDependencies": { - "selenium-webdriver": "^3.0.0", - "axe-core": "^2.0.7" + "selenium-webdriver": ">= 2.53.1", + "axe-core": "^2.2.0" }, "devDependencies": { "chai": "^3.0.0", @@ -58,7 +58,8 @@ "proxyquire": "^1.5.0", "serve-static": "^1.9.3", "sinon": "^1.17.3", - "axe-core": "^2.0.7" + "selenium-webdriver": ">= 2.53.1", + "axe-core": "^2.2.0" }, "dependencies": { } diff --git a/test/fixtures/attest-config.json b/test/fixtures/attest-config.json index e3b3e97..9ff3073 100644 --- a/test/fixtures/attest-config.json +++ b/test/fixtures/attest-config.json @@ -5,7 +5,11 @@ "options": [ "dylan" ], - "evaluate": "function (node, options) {\n var lang = (node.getAttribute(\"lang\") || \"\").trim().toLowerCase();\n var xmlLang = (node.getAttribute(\"xml:lang\") || \"\").trim().toLowerCase();\n var invalid = [];\n (options || []).forEach(function(cc) {\n cc = cc.toLowerCase();\n if (lang && (lang === cc || lang.indexOf(cc.toLowerCase() + \"-\") === 0)) {\n lang = null;\n }\n if (xmlLang && (xmlLang === cc || xmlLang.indexOf(cc.toLowerCase() + \"-\") === 0)) {\n xmlLang = null;\n }\n });\n if (xmlLang) {\n invalid.push('xml:lang=\"' + xmlLang + '\"');\n }\n if (lang) {\n invalid.push('lang=\"' + lang + '\"');\n }\n if (invalid.length) {\n this.data(invalid);\n return true;\n }\n return false;\n }" + "evaluate": "function (node, options) {\n var lang = (node.getAttribute(\"lang\") || \"\").trim().toLowerCase();\n var xmlLang = (node.getAttribute(\"xml:lang\") || \"\").trim().toLowerCase();\n var invalid = [];\n (options || []).forEach(function(cc) {\n cc = cc.toLowerCase();\n if (lang && (lang === cc || lang.indexOf(cc.toLowerCase() + \"-\") === 0)) {\n lang = null;\n }\n if (xmlLang && (xmlLang === cc || xmlLang.indexOf(cc.toLowerCase() + \"-\") === 0)) {\n xmlLang = null;\n }\n });\n if (xmlLang) {\n invalid.push('xml:lang=\"' + xmlLang + '\"');\n }\n if (lang) {\n invalid.push('lang=\"' + lang + '\"');\n }\n if (invalid.length) {\n this.data(invalid);\n return true;\n }\n return false;\n }", + "messages": { + "pass": "Good language", + "fail": "You mst use the DYLAN language" + } } ], "rules": [ @@ -13,8 +17,7 @@ "id": "dylang", "metadata": { "description": "Ensures lang attributes have the value of 'dylan'", - "help": "lang attribute must have the value of 'dylan'", - "helpUrl": "https://example.com/dylang" + "help": "lang attribute must have the value of 'dylan'" }, "selector": "html", "any": [], @@ -26,5 +29,13 @@ "wcag2aa" ] } - ] + ], + "data": { + "rules": { + "dylang": { + "description": "Ensures lang attributes have the value of 'dylan'", + "help": "lang attribute must have the value of 'dylan'" + } + } + } } \ No newline at end of file diff --git a/test/fixtures/inner-configure-frame.html b/test/fixtures/inner-configure-frame.html new file mode 100644 index 0000000..661138d --- /dev/null +++ b/test/fixtures/inner-configure-frame.html @@ -0,0 +1,6 @@ + + +
+