Search in sources :

Example 96 with HtmlPage

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

the class HtmlFileNameTest method fileNameWithSpecialCharactersAndSingleSlash.

@Test
public void fileNameWithSpecialCharactersAndSingleSlash() throws Exception {
    final String content = "<html><head><title>test</title></head><body>Hello world!</body></html>";
    FreeStyleProject job = j.createFreeStyleProject();
    job.getBuildersList().add(new CreateFileBuilder("subdir/#$&+,;= @.html", content));
    job.getPublishersList().add(new HtmlPublisher(Arrays.asList(new HtmlPublisherTarget("report-name", "", "subdir/*.html", true, true, false))));
    job.save();
    j.buildAndAssertSuccess(job);
    JenkinsRule.WebClient client = j.createWebClient();
    assertEquals(content, client.getPage(job, "report-name/subdir/%23%24%26%2B%2C%3B%3D%20%40.html").getWebResponse().getContentAsString());
    // published html page(s)
    HtmlPage page = client.getPage(job, "report-name");
    HtmlInlineFrame iframe = (HtmlInlineFrame) page.getElementById("myframe");
    assertEquals("subdir/%23%24%26%2B%2C%3B%3D%20%40.html", iframe.getAttribute("src"));
    HtmlPage pageInIframe = (HtmlPage) iframe.getEnclosedPage();
    assertEquals("Hello world!", pageInIframe.getBody().asNormalizedText());
}
Also used : CreateFileBuilder(org.jvnet.hudson.test.CreateFileBuilder) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) HtmlInlineFrame(com.gargoylesoftware.htmlunit.html.HtmlInlineFrame) Test(org.junit.Test)

Example 97 with HtmlPage

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

the class Security784Test method security784upgradeTest.

@LocalData
@Test
public void security784upgradeTest() throws Exception {
    FreeStyleProject job = j.jenkins.getItemByFullName("thejob", FreeStyleProject.class);
    Assert.assertTrue(new File(job.getRootDir(), "htmlreports/foo!!!!bar/index.html").exists());
    HtmlPublisherTarget.HTMLAction action = job.getAction(HtmlPublisherTarget.HTMLAction.class);
    Assert.assertNotNull(action);
    Assert.assertEquals("foo!!!!bar", action.getHTMLTarget().getReportName());
    // legacy
    Assert.assertEquals("foo!!!!bar", action.getUrlName());
    JenkinsRule.WebClient client = j.createWebClient();
    HtmlPage page = client.getPage(job, "foo!!!!bar/index.html");
    String text = page.getWebResponse().getContentAsString();
    Assert.assertEquals("Sun Mar 25 15:42:10 CEST 2018", text.trim());
    job.getBuildersList().clear();
    String newDate = new Date().toString();
    job.getBuildersList().add(new CreateFileBuilder("index.html", newDate));
    job.save();
    j.buildAndAssertSuccess(job);
    Assert.assertTrue(new File(job.getRootDir(), "htmlreports/foo_21_21_21_21bar/index.html").exists());
    action = job.getAction(HtmlPublisherTarget.HTMLAction.class);
    Assert.assertNotNull(action);
    Assert.assertEquals("foo!!!!bar", action.getHTMLTarget().getReportName());
    // new
    Assert.assertEquals("foo_21_21_21_21bar", action.getUrlName());
    text = client.goTo("job/thejob/foo_21_21_21_21bar/index.html").getWebResponse().getContentAsString();
    Assert.assertEquals(newDate, text.trim());
    // leftovers from legacy naming
    Assert.assertTrue(new File(job.getRootDir(), "htmlreports/foo!!!!bar/index.html").exists());
}
Also used : CreateFileBuilder(org.jvnet.hudson.test.CreateFileBuilder) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) File(java.io.File) Date(java.util.Date) LocalData(org.jvnet.hudson.test.recipes.LocalData) Test(org.junit.Test)

Example 98 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project JSCover by tntim96.

the class HtmlUnitJSTest method shouldTestJavaScript.

@Test
public void shouldTestJavaScript() throws Exception {
    HtmlPage page = webClient.getPage("http://localhost:8081/jscoverage.html?src/test/javascript/spec/suite.html");
    webClient.waitForBackgroundJavaScript(2000);
    // Verify Jasmine test result
    HtmlPage frame = (HtmlPage) page.getFrameByName("browserIframe").getEnclosedPage();
    List<HtmlSpan> passed = frame.getByXPath("//span[contains(@class,'jasmine-passed')]");
    assertThat(passed.size(), equalTo(1));
    assertThat(frame.getByXPath("//span[contains(@class,'jasmine-failed')]").size(), equalTo(0));
    assertThat(frame.getByXPath("//span[contains(@class,'jasmine-skipped')]").size(), equalTo(0));
    assertThat(passed.get(0).asText(), startsWith("15 specs, 0 failures"));
    // Store Report
    frame.executeJavaScript("jscoverage_report();");
    webClient.waitForBackgroundJavaScript(2000);
    // Verify coverage
    page.getHtmlElementById("summaryTab").click();
    webClient.waitForBackgroundJavaScript(2000);
    assertEquals("100%", page.getElementById("summaryTotal").getTextContent());
}
Also used : HtmlSpan(com.gargoylesoftware.htmlunit.html.HtmlSpan) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Test(org.junit.Test)

Example 99 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project JSCover by tntim96.

the class HtmlUnitLocalStorageTest method shouldClearLocalStorage.

@Test
public void shouldClearLocalStorage() throws IOException, InterruptedException {
    webClient.getPage("http://localhost:9001/jscoverage-clear-local-storage.html");
    webClient.getPage("http://localhost:9001/" + getTestUrl());
    HtmlPage page = webClient.getPage("http://localhost:9001/jscoverage.html");
    verifyTotal(page, 15, 0, 0);
    clickItem(1, 57, 12, 33);
    clickItem(2, 73, 37, 66);
    webClient.getPage("http://localhost:9001/jscoverage-clear-local-storage.html");
    webClient.getPage("http://localhost:9001/" + getTestUrl());
    page = webClient.getPage("http://localhost:9001/jscoverage.html");
    verifyTotal(page, 15, 0, 0);
    clickItem(1, 57, 12, 33);
    clickItem(2, 73, 37, 66);
    clickItem(3, 84, 62, 66);
    clickItem(4, 100, 87, 100);
// page.getElementById("storeTab").click();
// page.getElementById("storeButton").click();
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Test(org.junit.Test)

Example 100 with HtmlPage

use of com.gargoylesoftware.htmlunit.html.HtmlPage in project JSCover by tntim96.

the class HtmlUnitLocalStorageTest method clickItem.

private void clickItem(int id, int linePercentage, int branchPercentage, int functionPercentage) throws IOException {
    HtmlPage page = webClient.getPage("http://localhost:9001/" + getTestUrl());
    page.getElementById("radio" + id).click();
    page = webClient.getPage("http://localhost:9001/jscoverage.html");
    verifyTotal(page, linePercentage, branchPercentage, functionPercentage);
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage)

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