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

Upgrade selenium version to get support of CORS in HtmlUnit library #43

Closed lukas-vlcek closed 10 years ago

lukas-vlcek commented 10 years ago

Currently used version of selenium is dated. We need to upgrade to new version which brings a lot better support of CORS.

I am hitting a use case where I want to call external http rest service from the integration test. This service is started as a part of pre-integration test phase and runs on localhost. Currently, when I do something like this in my javascript test:

var xhr = new goog.net.XhrManager();
xhr.send(
    "id",
    "http://localhost:9200",
    undefined,
    undefined,
    undefined,
    undefined,
    function(event) {
        assertNotNull(event);
    }
);

I get:

[INFO] --- closure-testing-maven-plugin:1.18.0:js-closure-test (default-js-closure-test) @ ... ---
[INFO] (ClosureTestingMojo.java:111) Generating Test Suite...
[INFO] (ClosureTestingMojo.java:281) Calculating File Set...
[INFO] (ClosureTestingMojo.java:184) Parsing 1 Test Files (1 threads)...
[ERROR] (StrictErrorReporter.java:79) runtimeError: message=[Access to restricted URI denied] sourceName=[file:/.../target/javascriptFramework/closure-library/closure/goog//net/xhrio.js] line=[481] lineSource=[null] lineOffset=[0]

Note the Access to restricted URI denied message.

It turns out that this is problem of HtmlUnit version 2.9 (which is used by selenium 2.24.1) as it does not support CORS. Better CORS support is available in HtmlUnit version 2.11 and higher. See HtmlUnit changes report.

I tested selenium 2.35.0 which uses HtmlUnit 2.12 and it works well. Upgrading to even newer version of selenium would require adaptation to changed API. But it might be worth too.

lukas-vlcek commented 10 years ago

In the end I prepared a new PR with upgrade to selenium 2.40.0 (the latest one). API changes were minimal. @jlgrock do you think you can have a look at this and merge if you are fine with this?

jlgrock commented 10 years ago

Oh yeah, these types of changes are definitely fine. No params changed to the end user and it works better. You'll get no complaints here :)

kavuri commented 10 years ago

I have started using Selenium 2.41.0 and I am facing issue related to CORS. I have a javascript based site that is served by apache2 which inturn uses webservices served by tomcat server (running in the same machine). When I run selenium to test, I get errors related to CORS.

Error below:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8080/v1//session/. This can be fixed by moving the resource to the same domain or enabling CORS.

But the same test runs perfectly fine when run from selenium plugin in firefox. My cmdline for running the test is as under:

java -jar selenium-server-standalone-2.41.0.jar -htmlSuite *firefox http://localhost/index.html /home/user/web/Automationtestcases/tests/Automationtestcases.html /tmp/test.html

Do I have set any options to get CORS working with selenium? Any pointers on what might be going wrong?

jlgrock commented 10 years ago

The last comment seems to be unrelated to this plugin, but more in the general usage of selenium server. Please visit the selenium forums for that information, as they will be able to better help you with that stuff.