Package org.jvnet.hudson.test
Class HudsonTestCase.WebClient
java.lang.Object
org.htmlunit.WebClient
org.jvnet.hudson.test.HudsonTestCase.WebClient
- All Implemented Interfaces:
Serializable
,AutoCloseable
- Enclosing class:
- HudsonTestCase
public class HudsonTestCase.WebClient
extends org.htmlunit.WebClient
Extends
WebClient
and provide convenience methods
for accessing Hudson.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.htmlunit.WebClient
org.htmlunit.WebClient.PooledCSS3Parser
-
Field Summary
Fields inherited from class org.htmlunit.WebClient
TARGET_BLANK, TARGET_SELF
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionorg.htmlunit.WebRequest
addCrumb
(org.htmlunit.WebRequest req) Adds a security crumb to the request.void
assertFails
(String url, int statusCode) Verify that the server rejects an attempt to load the given page.createCrumbedUrl
(String relativePath) Creates a URL with crumb parameters relative to {getContextPath()
org.htmlunit.html.HtmlPage
Makes an HTTP request, process it with the given request handler, and returns the response.<V> V
executeOnServer
(Callable<V> c) Executes the given closure on the server, by the servlet request handling thread, in the context of an HTTP request.Returns the URL of the webapp top page.org.htmlunit.html.HtmlPage
getPage
(hudson.model.Item item) org.htmlunit.html.HtmlPage
org.htmlunit.html.HtmlPage
getPage
(hudson.model.Node item) org.htmlunit.html.HtmlPage
org.htmlunit.html.HtmlPage
getPage
(hudson.model.Run r) Short forgetPage(r,"")
, to access the top page of a build.org.htmlunit.html.HtmlPage
Accesses a page insideRun
.org.htmlunit.html.HtmlPage
getPage
(hudson.model.View view) org.htmlunit.html.HtmlPage
org.htmlunit.Page
Deprecated.This method expects a full URL.org.htmlunit.html.HtmlPage
Requests a page within Jenkins.org.htmlunit.Page
org.htmlunit.xml.XmlPage
Loads a page as XML.Logs in to Hudson, by using the user name as the password.Logs in to Jenkins.org.htmlunit.html.HtmlPage
Methods inherited from class org.htmlunit.WebClient
addCookie, addRequestHeader, addWebWindowListener, close, containsWebWindow, deregisterWebWindow, download, expandUrl, getAjaxController, getAlertHandler, getAttachmentHandler, getBrowserVersion, getCache, getClipboardHandler, getConfirmHandler, getCookieManager, getCookies, getCredentialsProvider, getCSS3Parser, getCssErrorHandler, getCurrentWindow, getExecutor, getFrameContentHandler, getHTMLParserListener, getIncorrectnessListener, getJavaScriptEngine, getJavaScriptErrorListener, getJavaScriptTimeout, getOnbeforeunloadHandler, getOptions, getPage, getPage, getPage, getPageCreator, getPrintHandler, getPromptHandler, getRefreshHandler, getScriptPreProcessor, getStatusHandler, getStorageHolder, getTopLevelWindows, getWebConnection, getWebConsole, getWebStartHandler, getWebWindowByName, getWebWindows, guessContentType, initialize, initializeEmptyWindow, isJavaScriptEnabled, isJavaScriptEngineEnabled, loadDownloadedResponses, loadHtmlCodeIntoCurrentWindow, loadWebResponse, loadWebResponseInto, loadWebResponseInto, loadXHtmlCodeIntoCurrentWindow, openDialogWindow, openTargetWindow, openWindow, openWindow, printContentIfNecessary, registerWebWindow, removeRequestHeader, removeWebWindowListener, reset, setAjaxController, setAlertHandler, setAttachmentHandler, setCache, setClipboardHandler, setConfirmHandler, setCookieManager, setCredentialsProvider, setCssErrorHandler, setCurrentWindow, setExecutor, setFrameContentHandler, setHTMLParserListener, setIncorrectnessListener, setJavaScriptEngine, setJavaScriptErrorListener, setJavaScriptTimeout, setOnbeforeunloadHandler, setPageCreator, setPrintHandler, setPromptHandler, setRefreshHandler, setScriptPreProcessor, setStatusHandler, setWebConnection, setWebStartHandler, throwFailingHttpStatusCodeExceptionIfNecessary, waitForBackgroundJavaScript, waitForBackgroundJavaScriptStartingBefore
-
Constructor Details
-
WebClient
public WebClient()
-
-
Method Details
-
login
Logs in to Jenkins.- Throws:
Exception
-
login
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
-
executeOnServer
Executes the given closure on the server, by the servlet request handling thread, in the context of an HTTP request.In
HudsonTestCase
, a thread that's executing the test code is different from the thread that carries out HTTP requests made throughHudsonTestCase.WebClient
. But sometimes you want to make assertions and other calls with side-effect from within the request handling thread.This method allows you to do just that. It is useful for testing some methods that require
StaplerRequest2
andStaplerResponse2
, or getting the credential of the current user (viaJenkins.getAuthentication()
, and so on.- Parameters:
c
- The closure to be executed on the server.- Returns:
- The return value from the closure.
- Throws:
Exception
- If a closure throws any exception, that exception will be carried forward.
-
search
- Throws:
IOException
SAXException
-
getPage
Short forgetPage(r,"")
, to access the top page of a build.- Throws:
IOException
SAXException
-
getPage
public org.htmlunit.html.HtmlPage getPage(hudson.model.Run r, String relative) throws IOException, SAXException Accesses a page insideRun
.- Parameters:
relative
- Relative URL within the build URL, like "changes". Doesn't start with '/'. Can be empty.- Throws:
IOException
SAXException
-
getPage
- Throws:
IOException
SAXException
-
getPage
public org.htmlunit.html.HtmlPage getPage(hudson.model.Item item, String relative) throws IOException, SAXException - Throws:
IOException
SAXException
-
getPage
- Throws:
IOException
SAXException
-
getPage
public org.htmlunit.html.HtmlPage getPage(hudson.model.Node item, String relative) throws IOException, SAXException - Throws:
IOException
SAXException
-
getPage
- Throws:
IOException
SAXException
-
getPage
public org.htmlunit.html.HtmlPage getPage(hudson.model.View view, String relative) throws IOException, SAXException - Throws:
IOException
SAXException
-
getPage
@Deprecated public org.htmlunit.Page getPage(String url) throws IOException, org.htmlunit.FailingHttpStatusCodeException Deprecated.This method expects a full URL. This method is marked as deprecated to warn you that you probably should be usinggoTo(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 classorg.htmlunit.WebClient
- Throws:
IOException
org.htmlunit.FailingHttpStatusCodeException
-
goTo
Requests a page within Jenkins.- Parameters:
relative
- Relative path within Jenkins. Starts without '/'. For example, "job/test/" to go to a job top page.- Throws:
IOException
SAXException
-
goTo
public org.htmlunit.Page goTo(String relative, String expectedContentType) throws IOException, SAXException - Throws:
IOException
SAXException
-
goToXml
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
-
assertFails
Verify that the server rejects an attempt to load the given page.- Parameters:
url
- a URL path (relative to Jenkins root)statusCode
- the expected failure code (such asHttpURLConnection.HTTP_FORBIDDEN
)- Throws:
Exception
- Since:
- 1.502
-
getContextPath
Returns the URL of the webapp top page. URL ends with '/'.- Throws:
IOException
-
addCrumb
public org.htmlunit.WebRequest addCrumb(org.htmlunit.WebRequest req) Adds a security crumb to the request. -
createCrumbedUrl
Creates a URL with crumb parameters relative to {getContextPath()
- Throws:
IOException
-
eval
Makes an HTTP request, process it with the given request handler, and returns the response.- Throws:
IOException
SAXException
-