public class HudsonTestCase.WebClient
extends com.gargoylesoftware.htmlunit.WebClient
WebClient
and provide convenience methods
for accessing Hudson.Constructor and Description |
---|
WebClient() |
Modifier and Type | Method and Description |
---|---|
com.gargoylesoftware.htmlunit.WebRequest |
addCrumb(com.gargoylesoftware.htmlunit.WebRequest req)
Adds a security crumb to the quest
|
void |
assertFails(String url,
int statusCode)
Verify that the server rejects an attempt to load the given page.
|
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.
|
<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.
|
String |
getContextPath()
Returns the URL of the webapp top page.
|
com.gargoylesoftware.htmlunit.html.HtmlPage |
getPage(hudson.model.Item item) |
com.gargoylesoftware.htmlunit.html.HtmlPage |
getPage(hudson.model.Item item,
String relative) |
com.gargoylesoftware.htmlunit.html.HtmlPage |
getPage(hudson.model.Node item) |
com.gargoylesoftware.htmlunit.html.HtmlPage |
getPage(hudson.model.Node item,
String relative) |
com.gargoylesoftware.htmlunit.html.HtmlPage |
getPage(hudson.model.Run r)
Short for
getPage(r,"") , to access the top page of a build. |
com.gargoylesoftware.htmlunit.html.HtmlPage |
getPage(hudson.model.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(hudson.model.View view) |
com.gargoylesoftware.htmlunit.html.HtmlPage |
getPage(hudson.model.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 Jenkins.
|
com.gargoylesoftware.htmlunit.html.HtmlPage |
search(String q) |
addCookie, addRequestHeader, addWebWindowListener, close, containsWebWindow, deregisterWebWindow, download, expandUrl, getActiveXObjectMap, getAjaxController, getAlertHandler, getAppletConfirmHandler, getAttachmentHandler, getBrowserVersion, getCache, getClipboardHandler, getConfirmHandler, getCookieManager, getCookies, getCredentialsProvider, getCssErrorHandler, getCurrentWindow, getExecutor, getFrameContentHandler, getHTMLParserListener, getIncorrectnessListener, getInternals, getJavaScriptEngine, getJavaScriptErrorListener, getJavaScriptTimeout, getMSXMLActiveXObjectFactory, getOnbeforeunloadHandler, getOptions, getPage, getPage, getPage, getPageCreator, 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, setActiveXObjectMap, setAjaxController, setAlertHandler, setAppletConfirmHandler, setAttachmentHandler, setCache, setClipboardHandler, setConfirmHandler, setCookieManager, setCredentialsProvider, setCssErrorHandler, setCurrentWindow, setExecutor, setFrameContentHandler, setHTMLParserListener, setIncorrectnessListener, setJavaScriptEngine, setJavaScriptErrorListener, setJavaScriptTimeout, setOnbeforeunloadHandler, setPageCreator, setPromptHandler, setRefreshHandler, setScriptPreProcessor, setStatusHandler, setWebConnection, setWebStartHandler, throwFailingHttpStatusCodeExceptionIfNecessary, waitForBackgroundJavaScript, waitForBackgroundJavaScriptStartingBefore
public HudsonTestCase.WebClient login(String username, String password) throws Exception
Exception
public HudsonTestCase.WebClient login(String username) throws Exception
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.
Exception
public <V> V executeOnServer(Callable<V> c) throws Exception
In HudsonTestCase
, a thread that's executing the test code is different from the thread
that carries out HTTP requests made through HudsonTestCase.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 StaplerRequest
and StaplerResponse
, or getting the credential
of the current user (via Jenkins.getAuthentication()
, and so on.
c
- The closure to be executed on the server.Exception
- If a closure throws any exception, that exception will be carried forward.public com.gargoylesoftware.htmlunit.html.HtmlPage search(String q) throws IOException, SAXException
IOException
SAXException
public com.gargoylesoftware.htmlunit.html.HtmlPage getPage(hudson.model.Run r) throws IOException, SAXException
getPage(r,"")
, to access the top page of a build.IOException
SAXException
public com.gargoylesoftware.htmlunit.html.HtmlPage getPage(hudson.model.Run r, String relative) throws IOException, SAXException
Run
.relative
- Relative URL within the build URL, like "changes". Doesn't start with '/'. Can be empty.IOException
SAXException
public com.gargoylesoftware.htmlunit.html.HtmlPage getPage(hudson.model.Item item) throws IOException, SAXException
IOException
SAXException
public com.gargoylesoftware.htmlunit.html.HtmlPage getPage(hudson.model.Item item, String relative) throws IOException, SAXException
IOException
SAXException
public com.gargoylesoftware.htmlunit.html.HtmlPage getPage(hudson.model.Node item) throws IOException, SAXException
IOException
SAXException
public com.gargoylesoftware.htmlunit.html.HtmlPage getPage(hudson.model.Node item, String relative) throws IOException, SAXException
IOException
SAXException
public com.gargoylesoftware.htmlunit.html.HtmlPage getPage(hudson.model.View view) throws IOException, SAXException
IOException
SAXException
public com.gargoylesoftware.htmlunit.html.HtmlPage getPage(hudson.model.View view, String relative) throws IOException, SAXException
IOException
SAXException
public com.gargoylesoftware.htmlunit.Page getPage(String url) throws IOException, com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException
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.)getPage
in class com.gargoylesoftware.htmlunit.WebClient
IOException
com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException
public com.gargoylesoftware.htmlunit.html.HtmlPage goTo(String relative) throws IOException, SAXException
relative
- Relative path within Hudson. Starts without '/'.
For example, "job/test/" to go to a job top page.IOException
SAXException
public com.gargoylesoftware.htmlunit.Page goTo(String relative, String expectedContentType) throws IOException, SAXException
IOException
SAXException
public com.gargoylesoftware.htmlunit.xml.XmlPage goToXml(String path) throws IOException, SAXException
path
- the path part of the url to visitIOException
SAXException
public void assertFails(String url, int statusCode) throws Exception
url
- a URL path (relative to Jenkins root)statusCode
- the expected failure code (such as HttpURLConnection.HTTP_FORBIDDEN
)Exception
public String getContextPath() throws IOException
IOException
public com.gargoylesoftware.htmlunit.WebRequest addCrumb(com.gargoylesoftware.htmlunit.WebRequest req)
public URL createCrumbedUrl(String relativePath) throws IOException
getContextPath()
IOException
public com.gargoylesoftware.htmlunit.html.HtmlPage eval(Runnable requestHandler) throws IOException, SAXException
IOException
SAXException
public org.mozilla.javascript.tools.debugger.Dim interactiveJavaScriptDebugger()
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 © 2004–2022. All rights reserved.