Search in sources :

Example 61 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project promoted-builds-plugin by jenkinsci.

the class ConfigurationDoCheckTest method testCheckProcessNameRequired.

@Issue("JENKINS-7972")
@Test
public void testCheckProcessNameRequired() throws Exception {
    FreeStyleProject down = j.createFreeStyleProject();
    FreeStyleProject p = j.createFreeStyleProject();
    JobPropertyImpl pp = new JobPropertyImpl(p);
    p.addProperty(pp);
    PromotionProcess proc = pp.addProcess("");
    assertEquals(1, pp.getItems().size());
    proc.conditions.add(new DownstreamPassCondition(down.getName()));
    proc.getBuildSteps().add(new JavadocArchiver("somedir", true));
    proc.icon = "star-blue";
    JenkinsRule.WebClient client = j.createWebClient();
    client.getOptions().setThrowExceptionOnFailingStatusCode(false);
    HtmlPage page = (HtmlPage) submit(client.getPage(p, "configure").getFormByName("config"));
    assertTrue(page.getVisibleText().contains("No name is specified"));
}
Also used : DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) JavadocArchiver(hudson.tasks.JavadocArchiver) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 62 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project yyl_example by Relucent.

the class HtmlUnitTest1 method main.

public static void main(String[] args) {
    // 得到浏览器对象
    WebClient webClient = null;
    try {
        webClient = new WebClient();
        webClient.waitForBackgroundJavaScript(60 * 1000);
        WebClientOptions options = webClient.getOptions();
        // 不加载css
        options.setCssEnabled(true);
        // 启用JS解释器,默认为true
        options.setJavaScriptEnabled(false);
        options.setUseInsecureSSL(true);
        // options.setRedirectEnabled(true);
        // 当出现HttpError时,是否抛出异常
        options.setThrowExceptionOnFailingStatusCode(false);
        // JS运行错误时,是否抛出异常
        options.setThrowExceptionOnScriptError(false);
        // 设置AJAX异步处理控制器(启用AJAX支持)
        webClient.setAjaxController(new NicelyResynchronizingAjaxController());
        // 拿到网页
        HtmlPage htmlpage = webClient.getPage("http://news.baidu.com/advanced_news.html");
        // 根据名字得到表单(表单的名字叫“f”)
        HtmlForm form = htmlpage.getFormByName("f");
        System.out.println(form);
        // 获取“百度一下”这个按钮
        HtmlSubmitInput button = form.getInputByValue("百度一下");
        System.out.println(button);
        // 得到搜索框
        HtmlTextInput textField = form.getInputByName("q1");
        System.out.println(textField);
        // 在搜索框内填入“HtmlUnit”
        textField.setValueAttribute("HtmlUnit");
        // 点击按钮
        HtmlPage nextPage = button.click();
        // 下一个页面
        System.out.println(nextPage);
        // 获得页面结果
        String result = nextPage.asXml();
        System.out.println(result);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (webClient != null) {
            webClient.close();
        }
    }
}
Also used : WebClientOptions(com.gargoylesoftware.htmlunit.WebClientOptions) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlTextInput(com.gargoylesoftware.htmlunit.html.HtmlTextInput) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) NicelyResynchronizingAjaxController(com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController) WebClient(com.gargoylesoftware.htmlunit.WebClient)

Example 63 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project yyl_example by Relucent.

the class HtmlUnitTest2 method main.

public static void main(String[] args) throws Exception {
    WebClient webClient = new WebClient(BrowserVersion.FIREFOX_68);
    webClient.setCssErrorHandler(new SilentCssErrorHandler());
    webClient.setAjaxController(new NicelyResynchronizingAjaxController());
    webClient.getOptions().setCssEnabled(true);
    webClient.getOptions().setRedirectEnabled(false);
    webClient.getOptions().setAppletEnabled(false);
    webClient.getOptions().setJavaScriptEnabled(true);
    webClient.getOptions().setPopupBlockerEnabled(true);
    webClient.getOptions().setTimeout(10000);
    // JS运行错误时,是否抛出异常
    webClient.getOptions().setThrowExceptionOnScriptError(false);
    HtmlPage page = webClient.getPage("http://huaban.com/favorite/home/");
    System.out.println(page.asXml());
    webClient.close();
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) NicelyResynchronizingAjaxController(com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController) SilentCssErrorHandler(com.gargoylesoftware.htmlunit.SilentCssErrorHandler) WebClient(com.gargoylesoftware.htmlunit.WebClient)

Example 64 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project spring-boot by spring-projects.

the class MyHtmlUnitTests method testExample.

@Test
void testExample() throws Exception {
    given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic"));
    HtmlPage page = this.webClient.getPage("/sboot/vehicle.html");
    assertThat(page.getBody().getTextContent()).isEqualTo("Honda Civic");
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Test(org.junit.jupiter.api.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 65 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project spring-boot by spring-projects.

the class WebMvcTestWebClientIntegrationTests method shouldAutoConfigureWebClient.

@Test
void shouldAutoConfigureWebClient() throws Exception {
    HtmlPage page = this.webClient.getPage("/html");
    assertThat(page.getBody().getTextContent()).isEqualTo("Hello");
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Test(org.junit.jupiter.api.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Aggregations

HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)159 Test (org.junit.Test)114 WebClient (com.gargoylesoftware.htmlunit.WebClient)51 HtmlSubmitInput (com.gargoylesoftware.htmlunit.html.HtmlSubmitInput)25 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)23 HtmlSpan (com.gargoylesoftware.htmlunit.html.HtmlSpan)21 File (java.io.File)17 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)15 Matchers.containsString (org.hamcrest.Matchers.containsString)13 IOException (java.io.IOException)11 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)10 FreeStyleProject (hudson.model.FreeStyleProject)9 URL (java.net.URL)9 Page (com.gargoylesoftware.htmlunit.Page)8 HtmlTextInput (com.gargoylesoftware.htmlunit.html.HtmlTextInput)7 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)6 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)6 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)5 HtmlButton (com.gargoylesoftware.htmlunit.html.HtmlButton)5 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)5