During my Selenium WebDriver testing of a webpage, I encountered a situation where I needed to make an assertion on a JavaScript file but was uncertain about the process.
The specific assertion I wanted to make was regarding the length of the servers
array, which should ideally be 2.
Within my JavaScript file named config.js
, I have defined the following array that needs to be confirmed:
var location = location || {};
location.Config = {
servers: [
{name: "a"},
{name: "b"}
]
}
In attempting to complete this assertion, I initially used the className
method but unfortunately, it did not yield the desired outcome:
Assert.assertThat(webDriver
.findElement(className("config.js"))
.getAttribute("servers")
.length(),
Matchers.is(2));