遵循git集线器- https://github.com/dequelabs/axe-selenium-java的一个简单程序。
public class CheckAxe {
@Rule
public TestName testName = new TestName();
private WebDriver driver;
private static final URL scriptUrl = CheckAxe.class.getResource("/axe.min.js");
@BeforeClass
public void setUp() {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "//Drivers//chromedriver.exe");
driver = new ChromeDriver();
}
@Test
public void testAccessibility() {
driver.get("https://www.amazon.com");
JSONObject responseJSON = new AXE.Builder(driver, scriptUrl).analyze();
JSONArray violations = responseJSON.getJSONArray("violations");
if (violations.length() == 0) {
Assert.assertTrue(true, "No violations found");
} else {
AXE.writeResults(testName.getMethodName(), responseJSON);
Assert.assertTrue(false, AXE.report(violations));
}
}
@AfterClass
public void tearDown() {
driver.quit();
}
}
在执行过程中,得到错误如下-
javascript : java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native方法中的意外令牌“<”(会话信息: chrome=84.0.4147.89),java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62),java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45),java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500),java.base/java.lang.rem.Constructor.newInstance(Constructor.java:481) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:489) at com.deque.axe.AXE.injectIntoFrames(AXE.java:111) at com.deque.axe.AXE.inject(AXE.java:74)在com.deque.axe.AXE$Builder.execute(AXE.java:368) at com.deque.axe.AXE$Builder.analyze(AXE.java:335) at utils.CheckAxe.testAccessibility(CheckAxe.java:35) at java.base/jdk。( internal.reflect.NativeMethodAccessorImpl.invoke0(Native方法)在java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:567) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:134) at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:597) at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker在org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46) at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:816) at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128) at java.base/java.util.ArrayList.forEach(ArrayList.java:1507) at org.testng.TestRunner.privateRun(TestRunner )。org.testng.TestRunner.run(TestRunner.java:587) at org.testng.SuiteRunner.runTest(SuiteRunner.java:384) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337) at org.testng.SuiteRunner.run(SuiteRunner.java:286) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96) at org.testng.TestNG.runSuitesSequentially(TestNG.org.testng.TestNG.runSuitesLocally(TestNG.java:1109) at org.testng.TestNG.runSuites(TestNG.java:1039) at org.testng.TestNG.run(TestNG.java:1007) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
你能告诉我,我在这里错过了什么吗?我的js文件位于下面的位置。样本截图-
发布于 2020-07-27 09:48:50
似乎是Chrome驱动程序可执行问题。
没有ChromeDriver可执行文件,在Google浏览器上运行Selenium测试脚本是不可能的。
请下载ChromeDriver exe文件表格ChromeExe
您可以将此文件保存在“C://driver//chromedriver_ can 32”文件夹中。
在安装方法中的ExampleTest.java类中
public void setUp() {
// ChromeDriver needed to test for Shadow DOM testing support
System.setProperty("webdriver.chrome.driver",
"C://driver//chromedriver_win32//chromedriver.exe");
driver = new ChromeDriver();
}
https://stackoverflow.com/questions/63100902
复制相似问题