Menu

#1714 WebSocket authentication

2.18
closed
None
1
2016-07-23
2015-08-29
No

I am using HtmlUnit 2.18 as part of an integration test.

When I try to use WebSockets API I am getting the error

"WebSocket" is not defined

According to change history, initial WebSockets support was added in 2.11
see http://htmlunit.sourceforge.net/changes-report.html

What am I missing?

Discussion

  • RBRi

    RBRi - 2015-08-29

    At first: please use the user maining list for this kind of questions.

    And regarding your problem: I guess you are simulation IE8 instead of FF or IE11. WebSockets are not supported by IE8.

     
  • eliasbalasis

    eliasbalasis - 2015-08-29

    Indeed, simulating a browser supporting websockets enabled Java Websockets API wiring.

    However, I am unexpectedly getting the error
    c.g.h.javascript.host.WebSocket - java.util.concurrent.ExecutionException: org.eclipse.jetty.websocket.api.UpgradeException: Didn't switch protocols, expected status <101>, but got <302>

    I say unexpectedly because WebSockets connectivity is successfully being tested separately

    The problem is the same both with HtmlUnit Selenium WebDriver and plain HtmlUnit.
    This works perfectly using Selenium Firefox Driver.

    My WebSockets endpoint requires CAS authentication. (so the 302 code above)
    I am always successfully authenticating the browser before testing the WebSockets connectivity.

    The HtmlUnit page instance is thus already authenticated. It looks like HtmlUnit tries to create a new connection to my websockets endpoint from zero instead of re-using the browser's authenticated channel (like my Firefox test does or any real browser does in a real scenario)

    This is now a totally different problem and complex too.
    I hope my description helps

    Any ideas?

     
  • Ahmed Ashour

    Ahmed Ashour - 2015-08-30
    • summary: "WebSocket" is not defined --> WebSocket authentication
     
  • Ahmed Ashour

    Ahmed Ashour - 2015-08-30

    Do you have a public website for testing?

     
  • eliasbalasis

    eliasbalasis - 2015-08-30

    Thanks,

    Yes, I do have a public website for testing

    http://eliasbalasis.net:8080/connectivity/delivery?destination="your page URL"

    This will take you to a CAS login page, which will indirectly return you, after passing the credentials I will secretly give you, to "your page URL"

    "your page URL" can now connect to the WebSockets end-point ws://eliasbalasis.net:8080/connectivity/form/ws/web/main

    Please choose a way to secretly transfer the credentials and related testing code parts

     

    Last edit: eliasbalasis 2015-08-30
  • Ahmed Ashour

    Ahmed Ashour - 2015-08-31
    • status: open --> accepted
    • assigned_to: Ahmed Ashour
     
  • Ahmed Ashour

    Ahmed Ashour - 2016-03-07
    • status: accepted --> pending
     
  • Ahmed Ashour

    Ahmed Ashour - 2016-03-07

    Sorry for late response.

    WebSocket was changed some time back to use the cookies from the WebClient.

    Can you test with latest version, and provide your feedback.

    You can directly contact me: asashour [at] yahoo

     
    • eliasbalasis

      eliasbalasis - 2016-03-08

      Thanks,

      I will try and get back to you the sooner.

       
  • eliasbalasis

    eliasbalasis - 2016-03-11

    Hi,

    Unfortunately the problem persists,

    Using "org.seleniumhq.selenium" 2.52.0 maven artifacts with HtmlUnit WebDriver I am getting the following exception

    It is worth mentionin no errors are produced while running the exact same tests under the exact same conditions using Firefox WebDriver instead.

    org.openqa.selenium.WebDriverException: com.gargoylesoftware.htmlunit.ScriptException: Exception invoking setOnopen
    Build info: version: '2.42.0', revision: '5e824302019c86eae9c8c3ca9155e7307b410cf8', time: '2014-05-24 09:48:41'
    System info: host: 'MYCOMPUTER', ip: '192.168.0.2', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_60'
    Driver info: driver.version: HtmlUnitDriver
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.executeScript(HtmlUnitDriver.java:693)
    at net.eliasbalasis.finance.trading.platform.client.connectivity.test.AbstractClientConnectivityTestMethodsForBrowser$1.process(AbstractClientConnectivityTestMethodsForBrowser.java:141)
    at net.eliasbalasis.finance.trading.platform.client.connectivity.test.AbstractClientConnectivityTestMethodsForBrowser.execute(AbstractClientConnectivityTestMethodsForBrowser.java:79)
    at net.eliasbalasis.finance.trading.platform.client.connectivity.test.AbstractClientConnectivityTestMethodsForBrowser.execute(AbstractClientConnectivityTestMethodsForBrowser.java:70)
    at net.eliasbalasis.finance.trading.platform.client.connectivity.test.AbstractClientConnectivityTestMethodsForBrowser.connectivityWebSocketsConnectToMAIN(AbstractClientConnectivityTestMethodsForBrowser.java:158)
    at net.eliasbalasis.finance.trading.platform.client.connectivity.test.ClientConnectivityTestMethodsForBrowserImplOnMAIN.connectivityWebSocketsConnectToMAIN(ClientConnectivityTestMethodsForBrowserImplOnMAIN.java:36)
    at net.eliasbalasis.finance.trading.platform.client.connectivity.ClientConnectivityExternalContainerTest.browserConnectivityAsWebSocketsForMAIN(ClientConnectivityExternalContainerTest.java:78)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
    Caused by: com.gargoylesoftware.htmlunit.ScriptException: Exception invoking setOnopen
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:865)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:796)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:768)
    at com.gargoylesoftware.htmlunit.InteractivePage.executeJavaScriptFunctionIfPossible(InteractivePage.java:201)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.executeScript(HtmlUnitDriver.java:687)
    ... 29 more
    Caused by: java.lang.RuntimeException: Exception invoking setOnopen
    at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:181)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject$GetterSlot.setValue(ScriptableObject.java:311)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject$RelinkedSlot.setValue(ScriptableObject.java:384)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.putImpl(ScriptableObject.java:2887)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.put(ScriptableObject.java:547)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.putProperty(ScriptableObject.java:2570)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1674)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1669)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1255)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:411)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:310)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3286)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:789)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:850)
    ... 35 more
    Caused by: java.lang.NullPointerException
    at com.gargoylesoftware.htmlunit.javascript.host.WebSocket.fireOnOpen(WebSocket.java:259)
    at com.gargoylesoftware.htmlunit.javascript.host.WebSocket.setOnopen(WebSocket.java:202)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:153)
    ... 50 more

    at com.gargoylesoftware.htmlunit.javascript.host.WebSocket.fireOnOpen(WebSocket.java:259)
    the null variable if containingPage_

    Any ideas?

     
  • eliasbalasis

    eliasbalasis - 2016-07-22

    It finally works, the problem was selenium dependency inconsistency on "htmlunit", overriding to match solved the problem. Using now selenium 2.53.1, webdriver 0.9.7376, htmlunit 2.21, htmlunit-core-js 2.17, org.apache.httpcomponents:httpclient:4.5.2 and a websockets implementation in the classpath.

    This can now be closed

     
  • RBRi

    RBRi - 2016-07-23

    Thanks for the feedback.

     
  • RBRi

    RBRi - 2016-07-23
    • status: pending --> closed
     

Log in to post a comment.