0

I am trying to run an asynchronous test and need to send a request to my server, which has a REST-API. So my problem is that the tests are executed on the local machine, but this obviously violates the same origin policy and I get a RuntimeError if I try to run the GWTtestCase:

com.google.gwt.http.client.RequestPermissionException: The URL http://<url-to-my-rest-service> is invalid or violates the same-origin security restriction
    at com.google.gwt.http.client.RequestBuilder.doSend(RequestBuilder.java:394)
    at com.google.gwt.http.client.RequestBuilder.send(RequestBuilder.java:242)
    ...

I know that I can run these tests manually, but with the latest updates of my browser (chromium), the GWT-Plugin was removed. So I don't know how to launch the tests in SuperDevMode.

Questions:

  • Is there a way to ignore the same-origin policy for the GWT JUnit Tests?
  • Can I change the browser which is used for the test to Chrome/Chromium?
  • How can I manually run the tests with SuperDevMode in a browser?

Edit:

If I want to run the tests manually I write the following into the terminal:

mvn gwt:test -Dgwt.args="-prod -userAgents safari -runStyle Manual:1"

Maven then will print an URL to the terminal which I should enter into the browser to execute the tests:

http://127.0.1.1:57818/<my-package>.JUnit/junit-standards.html?gwt.codesvr=127.0.1.1:40387

But if I enter this URL into my browser (Chromium) it will notify me that the GWT-Plugin is currently not installed. If I remove the part behind the question mark (like I do if I want to run the GWT-Code in SuperDevMode on the localhost) ?gwt.codesvr=127.0.1.1:40387 then the browser will show only a blank page, and also if I started the codeserver with:

mvn process-classes gwt:run-codeserver

the codeserver-bookmarks (Dev Mode On) are not working and GWT is not able to detect a module which is "compilable".

Question:

So how excatly do I compile the JUnit-Test-Module with the SuperDevMode?

Community
  • 1
  • 1
Tobias Helbich
  • 447
  • 14
  • 32

1 Answers1

1

You can't bypass the SOP, but you could use a servlet to proxy requests to your remote server (servlets declared with <servlet> in your gwt.xml files are honored by JUnitShell).

And if you want to run the tests in Chrome/Chromium, you can either use -runStyle Manual or Selenium (note: there's even a custom run style for PhantomJS), and because DevMode no longer works, as you noted, you'd have to run tests in prod mode: -prod -userAgents safari

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Thanks for the answer, I'll try to run the tests manually in production mode in an external browser. But I have still two more questions: I think the test should also fail on a servlet, because the servlet is still deployed on the localhost, but the REST-API server is not - right? Don't I need to run the codeserver manually for the prdouction mode - like when I run the GWT code on localhost in SuperDevMode? – Tobias Helbich Oct 01 '14 at 14:44