Java Code Examples for com.gargoylesoftware.htmlunit.html.HtmlImage#getSrcAttribute()

The following examples show how to use com.gargoylesoftware.htmlunit.html.HtmlImage#getSrcAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HTMLImageElement.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the value of the {@code src} attribute.
 * @return the value of the {@code src} attribute
 */
@JsxGetter
public String getSrc() {
    final HtmlImage img = (HtmlImage) getDomNodeOrDie();
    final String src = img.getSrcAttribute();
    if ("".equals(src)) {
        return src;
    }
    try {
        final HtmlPage page = (HtmlPage) img.getPage();
        return page.getFullyQualifiedUrl(src).toExternalForm();
    }
    catch (final MalformedURLException e) {
        final String msg = "Unable to create fully qualified URL for src attribute of image " + e.getMessage();
        throw Context.reportRuntimeError(msg);
    }
}
 
Example 2
Source File: HTMLImageElement.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the value of the {@code src} attribute.
 * @return the value of the {@code src} attribute
 */
@JsxGetter
public String getSrc() {
    final HtmlImage img = (HtmlImage) getDomNodeOrDie();
    final String src = img.getSrcAttribute();
    if ("".equals(src)) {
        return src;
    }
    try {
        final HtmlPage page = (HtmlPage) img.getPage();
        return page.getFullyQualifiedUrl(src).toExternalForm();
    }
    catch (final MalformedURLException e) {
        final String msg = "Unable to create fully qualified URL for src attribute of image " + e.getMessage();
        throw Context.reportRuntimeError(msg);
    }
}
 
Example 3
Source File: JenkinsRule.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
/**
 * Makes sure that all the images in the page loads successfully.
 * (By default, HtmlUnit doesn't load images.)
 */
public void assertAllImageLoadSuccessfully(HtmlPage p) {
    for (HtmlImage img : DomNodeUtil.<HtmlImage>selectNodes(p, "//IMG")) {
        try {
            assertEquals("Failed to load " + img.getSrcAttribute(),
                    200,
                    img.getWebResponse(true).getStatusCode());
        } catch (IOException e) {
            throw new AssertionError("Failed to load " + img.getSrcAttribute());
        }
    }
}
 
Example 4
Source File: HudsonTestCase.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
/**
 * Makes sure that all the images in the page loads successfully.
 * (By default, HtmlUnit doesn't load images.)
 */
public void assertAllImageLoadSuccessfully(HtmlPage p) {
    for (HtmlImage img : DomNodeUtil.<HtmlImage>selectNodes(p, "//IMG")) {
        try {
            assertEquals("Failed to load " + img.getSrcAttribute(),
                    200,
                    img.getWebResponse(true).getStatusCode());
        } catch (IOException e) {
            throw new AssertionError("Failed to load " + img.getSrcAttribute());
        }
    }
}