Closed anukodali83 closed 1 year ago
@sridharbandi i tried with the Java-a11y-example-master code you shared --same issue.. when i give my application end point or driver.get("https://github.com/sridharbandi/Java-a11y/issues/25") ......i am seeing the same error --please help us here getting error at : Object issues = javascriptExecutor.executeScript(script);
is there something in our webpages , which is giving this error?
@sridharbandi can you please help on this
@anukodali83 this issue is not because of the java-a11y. Few of the websites with the Chrome strictly enables content security policy: https://stackoverflow.com/questions/53304222/relaxing-chromes-csp-while-running-tests-webdriver-content-security-policy
If you see your developer console, you can see the error:
Workarounds are you need to disable Chrome CSP.
The second alternative is to modify your framework, as mentioned below
driver.get("https://github.com/sridharbandi/Java-a11y/issues/25");
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
String htmlcs = Reader.getInstance().getHTMLCS();
javascriptExecutor.executeScript(htmlcs);
Remaining, this should be as default Here is the complete example with above suggested changes. https://github.com/sridharbandi/Java-a11y-example/tree/workaround/issue-26
Thanks @sridharbandi , can you share the simalr for Axe code also...now htmlcs working.. we need axe.js too..thanks a lot @sridharbandi
Thanks @sridharbandi , can you share the simalr for Axe code also...now htmlcs working.. we need axe.js too..thanks a lot @sridharbandi
Hi @anukodali83 It is pretty the same as HtmlCodeSniffer. Below are the same steps for AXE
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
String axe = Reader.getInstance().getAXE();
javascriptExecutor.executeScript(axe);
}
Remaining, this should be as default Updated https://github.com/sridharbandi/Java-a11y-example/tree/workaround/issue-26 same for AXE.
Hi @sridharbandi same script with one url wrorking fine , but when try another url in driver.get(); --getting below error and report not generating
org.openqa.selenium.WebDriverException: unknown error: Runtime.evaluate threw exception: unknown (Session info: chrome=109.0.5414.120) Build info: version: '4.0.0', revision: '3a21814679' System info: host: 'IND9FKYYD3', ip: '192.168.0.11', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.11' Driver info: org.openqa.selenium.chrome.ChromeDriver Command: [246937baa4fd700b96e911f72e3b493c, executeScript {script=return axeData('{"standard":null,"ignoreCodes":null,"pageTitle":null}');async function axeData(params) { const obj = JSON.parse(params); await injectAxeScript(); var results = await runAxe() results.id = 'id_' + (Date.now().toString(36) + Math.random().toString(36).substr(2, 5)); results.title = obj.pageTitle == null ? document.title : obj.pageTitle; results.dimension = window.innerWidth + ' X ' + window.innerHeight; results.device = device(); results.browser = getBrowser(); results.date = getFormattedDate(); return results; }
function getBrowser() { const userAgent = navigator.userAgent; var browser = "Unkown"; // Detect browser name browser = (/ucbrowser/i).test(userAgent) ? 'UCBrowser' : browser; browser = (/edg/i).test(userAgent) ? 'Edge' : browser; browser = (/googlebot/i).test(userAgent) ? 'GoogleBot' : browser; browser = (/chromium/i).test(userAgent) ? 'Chromium' : browser; browser = (/firefox|fxios/i).test(userAgent) && !(/seamonkey/i).test(userAgent) ? 'Firefox' : browser; browser = (/; msie|trident/i).test(userAgent) && !(/ucbrowser/i).test(userAgent) ? 'IE' : browser; browser = (/chrome|crios/i).test(userAgent) && !(/opr|opera|chromium|edg|ucbrowser|googlebot/i).test(userAgent) ? 'Chrome' : browser; browser = (/safari/i).test(userAgent) && !(/chromium|edg|ucbrowser|chrome|crios|opr|opera|fxios|firefox/i).test(userAgent) ? 'Safari' : browser; browser = (/opr|opera/i).test(userAgent) ? 'Opera' : browser;
}
function browserVersion(userAgent, regex) { return userAgent.match(regex) ? userAgent.match(regex)[2] : null; }
function device() { var width = window.innerWidth; if (width < 768) { return 'Phone'; } else if (width < 992) { return 'Tablet'; } else if (width < 1200) { return 'Small Laptop'; } else { return 'Laptop/Desktop'; } }
function getFormattedDate() { var date = new Date(); var formattedDate = date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); return formattedDate; }
function runAxe() { return new Promise(function (resolve, reject) { axe.run(document, { runOnly: {type: 'tag', values: ['wcag2a', 'wcag2aa', 'section508']}, resultTypes: ['violations', 'incomplete', 'inapplicable'], rules: { 'accesskeys': { enabled: false } }, reporter: 'v2' }).then(results => resolve(results)) }); }
function injectAxeScript() { return new Promise((resolve, reject) => { const script = document.createElement('script'); script.src = "https://cdn.jsdelivr.net/npm/axe-core@latest/axe.min.js"; script.addEventListener('load', resolve); script.addEventListener('error', e => reject(e.error)); document.head.appendChild(script); }); }, args=[]}] Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 109.0.5414.120, chrome: {chromedriverVersion: 109.0.5414.74 (e7c5703604da..., userDataDir: C:\Users\akoda1\AppData\Loc...}, goog:chromeOptions: {debuggerAddress: localhost:59544}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:cdp: ws://localhost:59544/devtoo..., se:cdpVersion: 109.0.5414.120, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true} Session ID: 246937baa4fd700b96e911f72e3b493c