Search in sources :

Example 6 with HtmlPage

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

the class NodeJSInstallationTest method test_persist_of_nodejs_installation.

/**
 * Simulates the addition of the new NodeJS via UI and makes sure it works
 * and persistent file was created.
 */
@Test
@Issue("JENKINS-41535")
public void test_persist_of_nodejs_installation() throws Exception {
    File jenkinsHome = r.jenkins.getRootDir();
    File installationsFile = new File(jenkinsHome, NodeJSInstallation.class.getName() + ".xml");
    assertFalse("NodeJS installations file already exists", installationsFile.exists());
    HtmlPage p = getConfigurePage();
    HtmlForm f = p.getFormByName("config");
    HtmlButton b = r.getButtonByCaption(f, "Add NodeJS");
    b.click();
    r.findPreviousInputElement(b, "name").setValueAttribute("myNode");
    r.findPreviousInputElement(b, "home").setValueAttribute("/tmp/foo");
    r.submit(f);
    verify();
    assertTrue("NodeJS installations file has not been saved", installationsFile.exists());
    // another submission and verify it survives a roundtrip
    p = getConfigurePage();
    f = p.getFormByName("config");
    r.submit(f);
    verify();
}
Also used : HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) File(java.io.File) HtmlButton(com.gargoylesoftware.htmlunit.html.HtmlButton) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 7 with HtmlPage

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

the class HtmlUnitLocalStorageTest method shouldStoreCoverageDataInLocalStorage.

@Test
public void shouldStoreCoverageDataInLocalStorage() 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);
    clickItem(3, 84, 62, 66);
    clickItem(4, 100, 87, 100);
// page.getHtmlElementById("storeTab").click();
// page.getElementById("storeButton").click();
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Test(org.junit.Test)

Example 8 with HtmlPage

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

the class HtmlUnitMergeTest method saveUnloadedJS.

private void saveUnloadedJS() throws IOException {
    WebClient webClient = new WebClient();
    HtmlPage page = webClient.getPage("http://localhost:9001/jscoverage.html");
    storeReport(webClient, page);
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) WebClient(com.gargoylesoftware.htmlunit.WebClient)

Example 9 with HtmlPage

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

the class HtmlUnitMergeTest method shouldMergeUnloadedButtonSavedAndJSSavedReports.

@Test
public void shouldMergeUnloadedButtonSavedAndJSSavedReports() throws Exception {
    File jsonFile = new File(reportDir + "/jscoverage.json");
    if (jsonFile.exists())
        jsonFile.delete();
    saveUnloadedJS();
    saveReportByJavaScript();
    saveReportByButton();
    String json = ioUtils.toString(jsonFile);
    assertThat(json, containsString("/root.js"));
    assertThat(json, containsString("/level1/level2/level2.js"));
    String url = "file:///" + new File(reportDir + "/jscoverage.html").getAbsolutePath();
    WebClient webClient = new WebClient();
    HtmlPage page = webClient.getPage(url);
    webClient.waitForBackgroundJavaScript(1000);
    assertEquals("53%", page.getElementById("summaryTotal").getTextContent());
    assertEquals("33%", page.getElementById("branchSummaryTotal").getTextContent());
    assertEquals("50%", page.getElementById("functionSummaryTotal").getTextContent());
    verifyCoverage(page, "/root.js", "80%", "50%", "100%");
    verifyCoverage(page, "/root-empty.js", "N/A", "N/A", "N/A");
    verifyCoverage(page, "/level1/level1.js", "75%", "50%", "N/A");
    verifyCoverage(page, "/level1/level2/level2.js", "0%", "0%", "0%");
    verifyCoverage(page, "/level1/level2/level2-empty.js", "N/A", "N/A", "N/A");
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 10 with HtmlPage

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

the class HtmlUnitServerTest method shouldStoreResultViaJavaScriptCall.

@Test
public void shouldStoreResultViaJavaScriptCall() throws Exception {
    File jsonFile = new File(getReportDir() + "/directory/jscoverage.json");
    if (jsonFile.exists())
        jsonFile.delete();
    HtmlPage page = webClient.getPage("http://localhost:9001/jscoverage.html");
    ((HtmlInput) page.getHtmlElementById("location")).setValueAttribute("http://localhost:9001/example/index.html");
    page.getHtmlElementById("openInWindowButton").click();
    webClient.waitForBackgroundJavaScript(100);
    verifyTotal(webClient, page, 15);
    WebWindow webWindow = webClient.getWebWindowByName("jscoverage_window");
    ((HtmlPage) webWindow.getEnclosedPage()).executeJavaScript("jscoverage_report('directory');");
    webClient.waitForBackgroundJavaScript(2000);
    String json = ioUtils.toString(jsonFile);
    assertThat(json, containsString("/script.js"));
    page = webClient.getPage("file:///" + new File(getReportDir() + "/directory/jscoverage.html").getAbsolutePath());
    verifyTotal(webClient, page, 15);
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) HtmlInput(com.gargoylesoftware.htmlunit.html.HtmlInput) WebWindow(com.gargoylesoftware.htmlunit.WebWindow) Test(org.junit.Test)

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