jlgrock / ClosureJavascriptFramework

A group of plug-ins that can be used in conjunction with maven to execute the Google Closure Compiler on JavaScript code. This Framework allows for scaling and modularity.
MIT License
16 stars 7 forks source link

Allow browser version configuration for HtmlUnitDriver #45

Closed lukas-vlcek closed 10 years ago

lukas-vlcek commented 10 years ago

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

ValueDescription
CHROMEChrome browser
FIREFOXFirefox browser
FFFirefox browser
INTERNET EXPLORERInternet Explorer browser
IEInternet 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.