如何使用Java在Axe-Core中运行具有特定标签的可访问性测试。

huangapple go评论87阅读模式
英文:

How to run the accessibility test with specific tags in Axe-Core with Java

问题

所以,我正在尝试使用Axe-core和Selenium进行辅助功能测试。Axe-core看起来很有前途,但我在一个地方卡住了。

我想要使用特定标签(如wcag2a、wcag2aa)运行测试。通过查看他们的API文档页面 - https://www.deque.com/axe/axe-for-web/documentation/api-documentation/,很明显我们需要传递像这样的值:

axe.run(
    {
        runOnly: {
            type: 'tag',
            values: ['wcag2a', 'wcag2aa']
        }
    },
    (err, results) => {
        // ...
    }
);

但问题是,我正在用Java编写我的测试,我们如何将这些传递到代码中。我查看了他们Java示例项目的代码 https://github.com/dequelabs/axe-selenium-java,但在那里没有提到如何传递这些参数。

我在这方面进行了很多尝试,并尝试了像下面这样的代码,但是出现错误:

JSONObject responseJSON = new AXE.Builder(driver, scriptUrl)
    .options("axe.run({ runOnly: ['wcag2a', 'wcag2aa'] },(err, results)=>{});")
    .analyze();

我还尝试了 https://stackoverflow.com/questions/52886928/how-to-configure-rules-for-wcag2aa-in-axe-core-for-selenium-java 中提到的解决方案,虽然该解决方案没有抛出任何错误,但它显示了不在列表中的标签的结果。

非常感谢任何帮助。谢谢。

英文:

So, I am trying to figure out the accessibility testing using Axe-core with Selenium. Axe-core look promising but I am stuck in one place.

I wants to run the test with specific tags like wcag2a, wcag2aa. By looking at their api documentation page - https://www.deque.com/axe/axe-for-web/documentation/api-documentation/, it is clear that we have to pass values something like

 axe.run(
     {
	     runOnly: {
		     type: 'tag',
		     values: ['wcag2a', 'wcag2aa']
	     }
     },
     (err, results) => {
	     // ...
      }
 ); 

But the problem is I am writing my test in Java and how can we pass this to the code. I looked into the code of their Java sample project https://github.com/dequelabs/axe-selenium-java but there it has not mentioned anything about how to pass these argument.

I did lots of rnd around it and tried code like given below but getting error

> org.openqa.selenium.JavascriptException: javascript error: axe.run arguments are invalid

  JSONObject responseJSON = new AXE.Builder (driver, scriptUrl)
	  .options("axe.run({ runOnly: ['wcag2a', 'wcag2aa'] },(err, results)=>{});").
	  analyze();

I also tried the solution mentioned in the https://stackoverflow.com/questions/52886928/how-to-configure-rules-for-wcag2aa-in-axe-core-for-selenium-java but though that solution is not throwing any error but it is showing the results for tags which are not there in the list.

Any help is appreciated. Thanks.

答案1

得分: 1

所以,我从网址https://gitter.im/dequelabs/axe-core# 得到了答案。我在这里为其他人贴出来。

 JSONObject responseJSON1 = new AXE.Builder(driver, scriptUrl).options("runOnly: 
 ['wcag2a', 'wcag2aa']").analyze();
英文:

So, I got the answer from portal https://gitter.im/dequelabs/axe-core#. Posting it here for others.

 JSONObject responseJSON1 = new AXE.Builder(driver, scriptUrl).options("{runOnly: 
 ['wcag2a', 'wcag2aa']}").analyze();

huangapple
  • 本文由 发表于 2020年4月7日 12:26:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/61072837.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定