Skip to content
This repository was archived by the owner on Dec 7, 2022. It is now read-only.

Commit f61fd04

Browse files
author
Alice
committed
Merge pull request #142 from kristapsmelderis/master
+ Selenium WebDriver example (scala)
2 parents f70fc0c + cc07c9a commit f61fd04

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,33 @@ The Accessibility Developer Tools project includes a command line runner for the
7676

7777
The runner will load the specified file or URL in a headless browser, inject axs_testing.js, run the audit and output the report text.
7878

79+
### Run audit from Selenium WebDriver (Scala):
80+
val driver = org.openqa.selenium.firefox.FirefoxDriver //use driver of your choice
81+
val jse = driver.asInstanceOf[JavascriptExecutor]
82+
jse.executeScript(scala.io.Source.fromURL("https://raw.githubusercontent.com/GoogleChrome/" +
83+
"accessibility-developer-tools/stable/dist/js/axs_testing.js").mkString)
84+
val report = js.executeScript("var results = axs.Audit.run();return axs.Audit.createReport(results);")
85+
println(report)
86+
87+
### Run audit from Selenium WebDriver (Scala)(with caching):
88+
val cache = collection.mutable.Map[String, String]()
89+
val driver = org.openqa.selenium.firefox.FirefoxDriver //use driver of your choice
90+
val jse = driver.asInstanceOf[JavascriptExecutor]
91+
def getUrlSource(arg: String): String = cache get arg match {
92+
case Some(result) => result
93+
case None =>
94+
val result: String = scala.io.Source.fromURL(arg).mkString
95+
cache(arg) = result
96+
result
97+
}
98+
jse.executeScript(getUrlSource("https://raw.githubusercontent.com/GoogleChrome/" +
99+
"accessibility-developer-tools/stable/dist/js/axs_testing.js"))
100+
val report = js.executeScript("var results = axs.Audit.run();return axs.Audit.createReport(results);")
101+
println(report)
102+
103+
If println() outputs nothing, check if you need to set DesiredCapabilities for your WebDriver (such as loggingPrefs):
104+
https://code.google.com/p/selenium/wiki/DesiredCapabilities
105+
79106
## Using the results
80107

81108
### Interpreting the result

0 commit comments

Comments
 (0)