org.jvnet.hudson.test
Class HudsonTestCase.WebClient

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.WebClient
      extended by org.jvnet.hudson.test.HudsonTestCase.WebClient
All Implemented Interfaces:
Serializable
Enclosing class:
HudsonTestCase

public class HudsonTestCase.WebClient
extends com.gargoylesoftware.htmlunit.WebClient

Extends WebClient and provide convenience methods for accessing Hudson.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.gargoylesoftware.htmlunit.WebClient
URL_ABOUT_BLANK
 
Constructor Summary
HudsonTestCase.WebClient()
           
 
Method Summary
 com.gargoylesoftware.htmlunit.WebRequestSettings addCrumb(com.gargoylesoftware.htmlunit.WebRequestSettings req)
          Adds a security crumb to the quest
 URL createCrumbedUrl(String relativePath)
          Creates a URL with crumb parameters relative to {getContextPath()
 com.gargoylesoftware.htmlunit.html.HtmlPage eval(Runnable requestHandler)
          Makes an HTTP request, process it with the given request handler, and returns the response.
 String getContextPath()
          Returns the URL of the webapp top page.
 com.gargoylesoftware.htmlunit.html.HtmlPage getPage(Item item)
           
 com.gargoylesoftware.htmlunit.html.HtmlPage getPage(Item item, String relative)
           
 com.gargoylesoftware.htmlunit.html.HtmlPage getPage(Node item)
           
 com.gargoylesoftware.htmlunit.html.HtmlPage getPage(Node item, String relative)
           
 com.gargoylesoftware.htmlunit.html.HtmlPage getPage(Run r)
          Short for getPage(r,""), to access the top page of a build.
 com.gargoylesoftware.htmlunit.html.HtmlPage getPage(Run r, String relative)
          Accesses a page inside Run.
 com.gargoylesoftware.htmlunit.Page getPage(String url)
          Deprecated. This method expects a full URL. This method is marked as deprecated to warn you that you probably should be using goTo(String) method, which accepts a relative path within the Hudson being tested. (IOW, if you really need to hit a website on the internet, there's nothing wrong with using this method.)
 com.gargoylesoftware.htmlunit.html.HtmlPage getPage(View view)
           
 com.gargoylesoftware.htmlunit.html.HtmlPage getPage(View view, String relative)
           
 com.gargoylesoftware.htmlunit.html.HtmlPage goTo(String relative)
          Requests a page within Hudson.
 com.gargoylesoftware.htmlunit.Page goTo(String relative, String expectedContentType)
           
 com.gargoylesoftware.htmlunit.xml.XmlPage goToXml(String path)
          Loads a page as XML.
 org.mozilla.javascript.tools.debugger.Dim interactiveJavaScriptDebugger()
          Starts an interactive JavaScript debugger, and break at the next JavaScript execution.
 HudsonTestCase.WebClient login(String username)
          Logs in to Hudson, by using the user name as the password.
 HudsonTestCase.WebClient login(String username, String password)
          Logs in to Hudson.
 com.gargoylesoftware.htmlunit.html.HtmlPage search(String q)
           
 
Methods inherited from class com.gargoylesoftware.htmlunit.WebClient
addRequestHeader, addWebWindowListener, closeAllWindows, deregisterWebWindow, encodeQuery, encodeUrl, expandUrl, getActiveXObjectMap, getAjaxController, getAlertHandler, getAttachmentHandler, getBrowserVersion, getCache, getConfirmHandler, getCookieManager, getCredentialsProvider, getCssErrorHandler, getCurrentWindow, getHomePage, getHTMLParserListener, getIgnoreOutsideContent, getIncorrectnessListener, getJavaScriptEngine, getJavaScriptTimeout, getOnbeforeunloadHandler, getPage, getPage, getPage, getPage, getPageCreator, getPrintContentOnFailingStatusCode, getPromptHandler, getProxyConfig, getRefreshHandler, getScriptPreProcessor, getStatusHandler, getTimeout, getTopLevelWindows, getWebConnection, getWebWindowByName, getWebWindows, guessContentType, initialize, initialize, initializeEmptyWindow, isActiveXNative, isAppletEnabled, isCssEnabled, isJavaScriptEnabled, isPopupBlockerEnabled, isRedirectEnabled, isThrowExceptionOnFailingAjax, isThrowExceptionOnFailingStatusCode, isThrowExceptionOnScriptError, loadWebResponse, loadWebResponseInto, openDialogWindow, openWindow, openWindow, printContentIfNecessary, registerWebWindow, removeRequestHeader, removeWebWindowListener, setActiveXNative, setActiveXObjectMap, setAjaxController, setAlertHandler, setAppletEnabled, setAttachmentHandler, setCache, setConfirmHandler, setCookieManager, setCredentialsProvider, setCssEnabled, setCssErrorHandler, setCurrentWindow, setHomePage, setHTMLParserListener, setIgnoreOutsideContent, setIncorrectnessListener, setJavaScriptEnabled, setJavaScriptEngine, setJavaScriptTimeout, setOnbeforeunloadHandler, setPageCreator, setPopupBlockerEnabled, setPrintContentOnFailingStatusCode, setPromptHandler, setProxyConfig, setRedirectEnabled, setRefreshHandler, setScriptPreProcessor, setStatusHandler, setThrowExceptionOnFailingAjax, setThrowExceptionOnFailingStatusCode, setThrowExceptionOnScriptError, setTimeout, setUseInsecureSSL, setWebConnection, throwFailingHttpStatusCodeExceptionIfNecessary, waitForBackgroundJavaScript, waitForBackgroundJavaScriptStartingBefore
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HudsonTestCase.WebClient

public HudsonTestCase.WebClient()
Method Detail

login

public HudsonTestCase.WebClient login(String username,
                                      String password)
                               throws Exception
Logs in to Hudson.

Throws:
Exception

login

public HudsonTestCase.WebClient login(String username)
                               throws Exception
Logs in to Hudson, by using the user name as the password.

See HudsonTestCase.configureUserRealm() for how the container is set up with the user names and passwords. All the test accounts have the same user name and password.

Throws:
Exception

search

public com.gargoylesoftware.htmlunit.html.HtmlPage search(String q)
                                                   throws IOException,
                                                          SAXException
Throws:
IOException
SAXException

getPage

public com.gargoylesoftware.htmlunit.html.HtmlPage getPage(Run r)
                                                    throws IOException,
                                                           SAXException
Short for getPage(r,""), to access the top page of a build.

Throws:
IOException
SAXException

getPage

public com.gargoylesoftware.htmlunit.html.HtmlPage getPage(Run r,
                                                           String relative)
                                                    throws IOException,
                                                           SAXException
Accesses a page inside Run.

Parameters:
relative - Relative URL within the build URL, like "changes". Doesn't start with '/'. Can be empty.
Throws:
IOException
SAXException

getPage

public com.gargoylesoftware.htmlunit.html.HtmlPage getPage(Item item)
                                                    throws IOException,
                                                           SAXException
Throws:
IOException
SAXException

getPage

public com.gargoylesoftware.htmlunit.html.HtmlPage getPage(Item item,
                                                           String relative)
                                                    throws IOException,
                                                           SAXException
Throws:
IOException
SAXException

getPage

public com.gargoylesoftware.htmlunit.html.HtmlPage getPage(Node item)
                                                    throws IOException,
                                                           SAXException
Throws:
IOException
SAXException

getPage

public com.gargoylesoftware.htmlunit.html.HtmlPage getPage(Node item,
                                                           String relative)
                                                    throws IOException,
                                                           SAXException
Throws:
IOException
SAXException

getPage

public com.gargoylesoftware.htmlunit.html.HtmlPage getPage(View view)
                                                    throws IOException,
                                                           SAXException
Throws:
IOException
SAXException

getPage

public com.gargoylesoftware.htmlunit.html.HtmlPage getPage(View view,
                                                           String relative)
                                                    throws IOException,
                                                           SAXException
Throws:
IOException
SAXException

getPage

public com.gargoylesoftware.htmlunit.Page getPage(String url)
                                           throws IOException,
                                                  com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException
Deprecated. This method expects a full URL. This method is marked as deprecated to warn you that you probably should be using goTo(String) method, which accepts a relative path within the Hudson being tested. (IOW, if you really need to hit a website on the internet, there's nothing wrong with using this method.)

Overrides:
getPage in class com.gargoylesoftware.htmlunit.WebClient
Throws:
IOException
com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException

goTo

public com.gargoylesoftware.htmlunit.html.HtmlPage goTo(String relative)
                                                 throws IOException,
                                                        SAXException
Requests a page within Hudson.

Parameters:
relative - Relative path within Hudson. Starts without '/'. For example, "job/test/" to go to a job top page.
Throws:
IOException
SAXException

goTo

public com.gargoylesoftware.htmlunit.Page goTo(String relative,
                                               String expectedContentType)
                                        throws IOException,
                                               SAXException
Throws:
IOException
SAXException

goToXml

public com.gargoylesoftware.htmlunit.xml.XmlPage goToXml(String path)
                                                  throws IOException,
                                                         SAXException
Loads a page as XML. Useful for testing Hudson's xml api, in concert with assertXPath(DomNode page, String xpath)

Parameters:
path - the path part of the url to visit
Returns:
the XmlPage found at that url
Throws:
IOException
SAXException

getContextPath

public String getContextPath()
                      throws IOException
Returns the URL of the webapp top page. URL ends with '/'.

Throws:
IOException

addCrumb

public com.gargoylesoftware.htmlunit.WebRequestSettings addCrumb(com.gargoylesoftware.htmlunit.WebRequestSettings req)
Adds a security crumb to the quest


createCrumbedUrl

public URL createCrumbedUrl(String relativePath)
                     throws IOException
Creates a URL with crumb parameters relative to {getContextPath()

Throws:
IOException

eval

public com.gargoylesoftware.htmlunit.html.HtmlPage eval(Runnable requestHandler)
                                                 throws IOException,
                                                        SAXException
Makes an HTTP request, process it with the given request handler, and returns the response.

Throws:
IOException
SAXException

interactiveJavaScriptDebugger

public org.mozilla.javascript.tools.debugger.Dim interactiveJavaScriptDebugger()
Starts an interactive JavaScript debugger, and break at the next JavaScript execution.

This is useful during debugging a test so that you can step execute and inspect state of JavaScript. This will launch a Swing GUI, and the method returns immediately.

Note that installing a debugger appears to make an execution of JavaScript substantially slower.

TODO: because each script block evaluation in HtmlUnit is done in a separate Rhino context, if you step over from one script block, the debugger fails to kick in on the beginning of the next script block. This makes it difficult to set a break point on arbitrary script block in the HTML page. We need to fix this by tweaking Dim.StackFrame#onLineChange(Context, int).



Copyright © 2010. All Rights Reserved.