org.stjs.testing.driver.browser
Class LongPollingBrowser

java.lang.Object
  extended by org.stjs.testing.driver.browser.AbstractBrowser
      extended by org.stjs.testing.driver.browser.LongPollingBrowser
All Implemented Interfaces:
AsyncProcess, Browser
Direct Known Subclasses:
ChromeBrowser, DesktopDefaultBrowser, FirefoxBrowser, HeadlessBrowser, PhantomjsBrowser, RemoteBrowser, RhinoBrowser

public abstract class LongPollingBrowser
extends AbstractBrowser

Represents a testing session opened with one instance of a browser that uses long-polling to fetch new tests to execute from the HTTP server. LongPollingBrowser handles multithreading synchronization between the browser, the HTTP server and the JUnit runner. The JUnit runner notifies this browser that a new test method must be executed by calling executeTest(MultiTestMethod), or that it has finished executing all the tests by calling notifyNoMoreTests(). The HTTP server waits for a new test to send to the browser by calling awaitNewTestReady().

On top of that, LongPollinBrowser delegates the details of starting and stopping the browser itself to its concrete subclasses.

Author:
lordofthepigs

Constructor Summary
LongPollingBrowser(DriverConfiguration config)
           
 
Method Summary
 MultiTestMethod awaitNextTest()
          Blocks until JUnit notifies this browser session that either a new test must be executed (ie: executeTest() is called), or there are no more tests (ie: notifyNoMoreTests() is called).
protected abstract  void doStart()
           
 void executeTest(MultiTestMethod method)
          Notifies this browser that the specified test must be executed.
 long getId()
           
 MultiTestMethod getMethodUnderExecution()
          Returns the test is currently being executed by this browser.
 Set<Class<? extends AsyncProcess>> getSharedDependencies()
          Returns a list of AsyncProcess that the JUnit session must start before attempting to start this browser.
protected  String getStartPageUri(long browserId, boolean persistent)
           
protected  String getStartPageUrl(long browserId, boolean persistent)
           
protected  void markAsDead()
           
 void markAsDead(Throwable throwable, String userAgent)
           
 void notifyNoMoreTests()
          Notifies this browser that there are no more tests to execute.
protected  void registerWithLongPollingServer()
           
 void sendNoMoreTestFixture(com.sun.net.httpserver.HttpExchange exchange)
          Writes to the HTTP response the HTML and/or javascript code that is necessary for the browser understand that there will be no more tests.
 void sendTestFixture(MultiTestMethod meth, com.sun.net.httpserver.HttpExchange exchange)
          Writes to the HTTP response the HTML and/or javascript code that is necessary for the browser to execute the specified test.
 void start()
          Starts the browser session.
 
Methods inherited from class org.stjs.testing.driver.browser.AbstractBrowser
appendScriptTag, buildProcess, buildResult, getConfig, isRunningOnWindows, processSet, sendResponse, startProcess, startProcess, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LongPollingBrowser

public LongPollingBrowser(DriverConfiguration config)
Method Detail

getStartPageUri

protected String getStartPageUri(long browserId,
                                 boolean persistent)

getStartPageUrl

protected String getStartPageUrl(long browserId,
                                 boolean persistent)

registerWithLongPollingServer

protected void registerWithLongPollingServer()

start

public void start()
           throws org.junit.runners.model.InitializationError
Starts the browser session. This will open a browser and navigate it to some page where the unit testing procedure can be started. The decision about exactly which browser binary is started, how it is started and which page is opened is delegated to the Browser implementation that this AsynBrowserSession was constructed with. This method performs some error handling, and the real implementation of the browser starting procedure is delegated to doStart().

Throws:
org.junit.runners.model.InitializationError

doStart

protected abstract void doStart()
                         throws org.junit.runners.model.InitializationError
Throws:
org.junit.runners.model.InitializationError

awaitNextTest

public MultiTestMethod awaitNextTest()
Blocks until JUnit notifies this browser session that either a new test must be executed (ie: executeTest() is called), or there are no more tests (ie: notifyNoMoreTests() is called). If there is a new test to execute, then this method returns it. If there are no more tests, this method returns null.

This method is typically called right after the results of the previous test were reported.

Returns:
The next test to execute, or null if there isn't any

executeTest

public void executeTest(MultiTestMethod method)
Notifies this browser that the specified test must be executed. This method blocks until this browser picks up the test by calling awaitNextTest(). If the browser does not pick up the test within the timeout specified in DriverConfiguration.getTestTimeout(), then the browser is assumed to be dead. The test is failed, and the browser does not receive any more tests at all.

Parameters:
method - The test to execute.

notifyNoMoreTests

public void notifyNoMoreTests()
Notifies this browser that there are no more tests to execute. This method blocks until this browser attempts to pick up a new test by calling awaitNewTestReady(). If the browser does not attempt to pick up a new test within the timeout specified in DriverConfiguration.getTestTimeout(), then the browser is assumed to be dead.


getMethodUnderExecution

public MultiTestMethod getMethodUnderExecution()
Returns the test is currently being executed by this browser.


sendTestFixture

public void sendTestFixture(MultiTestMethod meth,
                            com.sun.net.httpserver.HttpExchange exchange)
                     throws Exception
Writes to the HTTP response the HTML and/or javascript code that is necessary for the browser to execute the specified test.

Parameters:
meth - The test to send to the browser
browserSession - The session to which the test is sent
exchange - contains the HTTP response that must be written to
Throws:
Exception

sendNoMoreTestFixture

public void sendNoMoreTestFixture(com.sun.net.httpserver.HttpExchange exchange)
                           throws IOException
Writes to the HTTP response the HTML and/or javascript code that is necessary for the browser understand that there will be no more tests.

Parameters:
browserSession - The session to be notified
exchange - contains the HTTP response that must be written to
Throws:
IOException

getSharedDependencies

public Set<Class<? extends AsyncProcess>> getSharedDependencies()
Description copied from interface: Browser
Returns a list of AsyncProcess that the JUnit session must start before attempting to start this browser. If any of the dependencies fails to start, the JUnit session fails.


markAsDead

protected void markAsDead()

markAsDead

public void markAsDead(Throwable throwable,
                       String userAgent)

getId

public long getId()


Copyright © 2013. All Rights Reserved.