Search in sources :

Example 11 with HtmlPage

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

the class HtmlUnitServerTest method shouldStoreResultViaJavaScriptCallWithoutUIAsync.

@Test
public void shouldStoreResultViaJavaScriptCallWithoutUIAsync() throws Exception {
    File jsonFile = new File(getReportDir() + "/directory-no-ui-cb/jscoverage.json");
    if (jsonFile.exists())
        jsonFile.delete();
    HtmlPage page = webClient.getPage("http://localhost:9001/example/index.html");
    page.executeJavaScript("jscoverage_report('directory-no-ui-cb', function(response){});");
    webClient.waitForBackgroundJavaScript(100);
    String json = ioUtils.toString(jsonFile);
    assertThat(json, containsString("/script.js"));
    page = webClient.getPage("file:///" + new File(getReportDir() + "/directory-no-ui-cb/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) Test(org.junit.Test)

Example 12 with HtmlPage

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

the class HtmlUnitServerTest method shouldWorkWithServerIFrameByNavigationButtons.

@Test
public void shouldWorkWithServerIFrameByNavigationButtons() throws Exception {
    HtmlPage page = webClient.getPage("http://localhost:9001/jscoverage.html");
    ((HtmlInput) page.getHtmlElementById("location")).setValueAttribute("http://localhost:9001/example/index.html");
    page.getHtmlElementById("openInFrameButton").click();
    webClient.waitForBackgroundJavaScript(100);
    verifyTotal(webClient, page, 15);
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlInput(com.gargoylesoftware.htmlunit.html.HtmlInput) Test(org.junit.Test)

Example 13 with HtmlPage

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

the class HtmlUnitServerTest method testFileUpload.

private void testFileUpload(String postFile) throws IOException {
    HtmlPage page = webClient.getPage("http://localhost:9001/example/upload.html");
    ((HtmlInput) page.getHtmlElementById("uploader")).setValueAttribute(postFile);
    page = page.getHtmlElementById("submitButton").click();
    String data = page.getHtmlElementById("postData").getTextContent();
    assertThat(data, containsString("Line 1\nLine 2"));
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Matchers.containsString(org.hamcrest.Matchers.containsString) HtmlInput(com.gargoylesoftware.htmlunit.html.HtmlInput)

Example 14 with HtmlPage

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

the class HtmlUnitServerTest method shouldStoreResultViaJavaScriptCallWithoutUI.

@Test
public void shouldStoreResultViaJavaScriptCallWithoutUI() throws Exception {
    File jsonFile = new File(getReportDir() + "/directory-no-ui/jscoverage.json");
    if (jsonFile.exists())
        jsonFile.delete();
    HtmlPage page = webClient.getPage("http://localhost:9001/example/index.html");
    page.executeJavaScript("jscoverage_report('directory-no-ui');");
    webClient.waitForBackgroundJavaScript(2000);
    String json = ioUtils.toString(jsonFile);
    assertThat(json, containsString("/script.js"));
    page = webClient.getPage("file:///" + new File(getReportDir() + "/directory-no-ui/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) Test(org.junit.Test)

Example 15 with HtmlPage

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

the class HtmlUnitServerTest method testWorkInInvertedMode.

protected void testWorkInInvertedMode(int branchPercentage1, int branchPercentage2, int functionPercentage1, int functionPercentage2) throws IOException {
    HtmlPage page = webClient.getPage("http://localhost:9001/example/index.html");
    page.getHtmlElementById("launchJSCover").click();
    webClient.waitForBackgroundJavaScript(100);
    WebWindow webWindow = webClient.getWebWindowByName("JSCoverInvertedMode");
    HtmlPage jsCoverPage = (HtmlPage) webWindow.getEnclosedPage();
    verifyTotal(webClient, jsCoverPage, 15, branchPercentage1, functionPercentage1);
    page.getHtmlElementById("radio3").click();
    webClient.waitForBackgroundJavaScript(100);
    jsCoverPage.executeJavaScript("jscoverage_recalculateSummaryTab();");
    webClient.waitForBackgroundJavaScript(500);
    verifyTotal(webClient, jsCoverPage, 73, branchPercentage2, functionPercentage2);
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) WebWindow(com.gargoylesoftware.htmlunit.WebWindow)

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