Package com.gargoylesoftware.htmlunit

Examples of com.gargoylesoftware.htmlunit.ScriptResult


    protected TestsResult getTestsResult() {
        TestsResult result = new TestsResult();

        executeTimer();

        ScriptResult scriptResult = page.executeJavaScript("window.simulationContext.results");
        NativeArray array = (NativeArray) scriptResult.getJavaScriptResult();

        for (int i = 0; i < array.getLength(); i++) {
            NativeObject object = (NativeObject) array.get(i, array);
            String data = null;
            Object dataObject = object.get("data", object);

            if (!(dataObject instanceof Undefined)) {
                data = (String) dataObject;
            }

            Object startTimeObject = object.get("startTime", object);
            Double startTime =  startTimeObject instanceof Double ? (Double) startTimeObject : Double.NaN;
            Object endTimeObject = object.get("endTime", object);
            Double endTime =  endTimeObject instanceof Double ? (Double) endTimeObject : Double.NaN;
            Object aborted = object.get("aborted", object);
            boolean abortedBoolean = aborted instanceof Boolean && (Boolean) aborted;

            result.addData(new RequestData(data, startTime, endTime, abortedBoolean));
        }

        scriptResult = page.executeJavaScript("Timer.currentTime");
        result.setCurrentTime((Double) scriptResult.getJavaScriptResult());

        System.out.println();
        System.out.println("Logged Javascript statements:");
        System.out.println("*****************************");
        System.out.println(loggedJavaScript.toString());
View Full Code Here


    protected TestsResult getTestsResult() {
        TestsResult result = new TestsResult();

        executeTimer();

        ScriptResult scriptResult = page.executeJavaScript("window.simulationContext.results");
        NativeArray array = (NativeArray) scriptResult.getJavaScriptResult();

        for (int i = 0; i < array.getLength(); i++) {
            NativeObject object = (NativeObject) array.get(i, array);
            String data = null;
            Object dataObject = object.get("data", object);

            if (!(dataObject instanceof Undefined)) {
                data = (String) dataObject;
            }

            Double startTime = (Double) object.get("startTime", object);
            Double endTime = (Double) object.get("endTime", object);
            Object aborted = object.get("aborted", object);
            boolean abortedBoolean = aborted instanceof Boolean && (Boolean) aborted;

            result.addData(new RequestData(data, startTime, endTime, abortedBoolean));
        }

        scriptResult = page.executeJavaScript("Timer.currentTime");
        result.setCurrentTime((Double) scriptResult.getJavaScriptResult());

        return result;
    }
View Full Code Here

        HtmlPage p = createWebClient().goTo("self/testBehaviour");

        p.executeJavaScript("renderOnDemand(document.getElementsBySelector('.lazy')[0])");
        // all AJAX calls complete before the above method returns

        ScriptResult r = p.executeJavaScript("var r=document.getElementsBySelector('DIV.a'); r[0].innerHTML+r[1].innerHTML+r[2].innerHTML");
        assertEquals("AlphaBravoCharlie",r.getJavaScriptResult().toString());
    }
View Full Code Here

        "InvokeSpecial must not be called on the client side");
  }

  public void loadJsni(BrowserChannel channel, String jsniString) {
    logger.log(TreeLogger.SPAM, "LOAD_JSNI: " + jsniString);
    ScriptResult scriptResult = htmlPage.executeJavaScript(jsniString);
    logger.log(TreeLogger.INFO, "LOAD_JSNI: scriptResult=" + scriptResult);
  }
View Full Code Here

        "InvokeSpecial must not be called on the client side");
  }

  public void loadJsni(BrowserChannel channel, String jsniString) {
    logger.log(TreeLogger.SPAM, "LOAD_JSNI: " + jsniString);
    ScriptResult scriptResult = htmlPage.executeJavaScript(jsniString);
    logger.log(TreeLogger.INFO, "LOAD_JSNI: scriptResult=" + scriptResult);
  }
View Full Code Here

  @Override
  public void loadJsni(BrowserChannelClient channel, String jsniString) {
    if (logger.isLoggable(TreeLogger.SPAM)) {
      logger.log(TreeLogger.SPAM, "LOAD_JSNI: " + jsniString);
    }
    ScriptResult scriptResult = htmlPage.executeJavaScript(jsniString);
    if (logger.isLoggable(TreeLogger.INFO)) {
      logger.log(TreeLogger.INFO, "LOAD_JSNI: scriptResult=" + scriptResult);
    }
  }
View Full Code Here

    String escapedCoffee = StringEscapeUtils.escapeEcmaScript(coffee);
    return cache.containsKey(escapedCoffee) ? cache.get(escapedCoffee) : compileAndCache(escapedCoffee);
  }

  private String compileAndCache(String input) {
    ScriptResult scriptResult = htmlPage.get().executeJavaScript(String.format("CoffeeScript.compile(\"%s\");", input));
    String result = (String) scriptResult.getJavaScriptResult();
    cache.put(input,result);
    return result;
  }
View Full Code Here

        webClient.waitForBackgroundJavaScript(100);

        verifyTotal(webClient, page, 15);

        WebWindow webWindow = webClient.getWebWindowByName("jscoverage_window");
        ScriptResult result = ((HtmlPage)webWindow.getEnclosedPage()).executeJavaScript("jscoverage_report('directory');");

        assertThat(result.getJavaScriptResult().toString(), equalTo("Coverage data stored at " + new File(getReportDir() + "/directory").getPath()));

        String json = ioUtils.toString(jsonFile);
        assertThat(json, containsString("/script.js"));

        page = webClient.getPage("file:///"+ new File(getReportDir()+"/directory/jscoverage.html").getAbsolutePath());
View Full Code Here

        webClient.waitForBackgroundJavaScript(100);

        //verifyTotal(webClient, page, 15);

        WebWindow webWindow = webClient.getWebWindowByName("jscoverage_window");
        ScriptResult result = ((HtmlPage)webWindow.getEnclosedPage()).executeJavaScript("jscoverage_report();");

        assertThat(result.getJavaScriptResult().toString(), equalTo("Coverage data stored at " + new File(reportDir).getPath()));
    }
View Full Code Here

        assertThat(frame.getByXPath("//span[contains(@class,'failed')]").size(), equalTo(0));
        assertThat(frame.getByXPath("//span[contains(@class,'skipped')]").size(), equalTo(0));
        assertThat(passed.get(0).asText(), equalTo("16 specs, 0 failures"));

        //Store Report
        ScriptResult result = frame.executeJavaScript("jscoverage_report();");

        //Verify coverage
        page.getHtmlElementById("summaryTab").click();
        webClient.waitForBackgroundJavaScript(2000);
        assertEquals("100%", page.getElementById("summaryTotal").getTextContent());
View Full Code Here

TOP

Related Classes of com.gargoylesoftware.htmlunit.ScriptResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.