When dealing with Element.innerHTML in Selenium tests result can differ depending on the used browser. HtmlUnitDriver allows to specify which BrowserVersion to use.
The idea is to allow configuration of browserVersion
for both the closure-testing-framework-plugin
and closure-testing-report-maven-plugin
. As a results user can control output of sensitive operations (like above mentioned Element.innerHTML
).
Example of configuration
<plugin>
<groupId>com.github.jlgrock.javascript-framework</groupId>
<artifactId>closure-testing-maven-plugin</artifactId>
<version>${jsframework.version}</version>
<configuration>
<browserVersion>FF</browserVersion>
</configuration>
</plugin>
Supported values
Value | Description |
CHROME | Chrome browser |
FIREFOX | Firefox browser |
FF | Firefox browser |
INTERNET EXPLORER | Internet Explorer browser |
IE | Internet Explorer browser |
If browserVersion
is empty of not specified at all then the default BrowserVersion is used, which usually defaults to INTERNET EXPLORER
but it is an internal implementation detail of BrowserVersion and is subject to change depending on used library version.
Example Unit Test
To give specific example of unit test where it was important to control browser version imagine the following use case. We generate HTML elements using the following code:
var captionDiv = goog.dom.createDom(goog.dom.TagName.DIV,"captionClass");
goog.dom.appendChild(caption, goog.dom.createTextNode("Caption"));
This creates a DIV element with class="captionClass" and text node containing text "Caption". Now, we can easily use innerHTML
in test like this:
assertEquals(
captionDiv.innerHTML.toLowerCase(),
'<div class="captionClass">Caption</div>'
);
Now, without specifying browserVersion
such test would fail:
* Test = testMethod : FAILED
Expected <<div class="captionClass">Caption</div>> (String) but was <<div class=captionClass>Caption</div>> (String)
Difference was at position 11. Expected [...s="captionClass"...] vs. actual [...s=captionClass...]
This is caused by the fact that if INTERNET EXPLORER
browser version is used (which is used by default) then element attribute values are output without quotation. When we specify browserVersion
equal for example to FF
then such test would pass.