Search in sources :

Example 26 with ScriptResult

use of com.gargoylesoftware.htmlunit.ScriptResult in project code-coverage-api-plugin by jenkinsci.

the class ChartUtil method getDataOfOnlyChartOnPageWithGivenToolAttribute.

/**
 * Returns data of only chart with given tool attribute value on page.
 *
 * @param pageObject
 *         which contains only one chart with given tool attribute value
 * @param toolAttribute
 *         value in div tag of chart
 *
 * @return data as json
 */
public static String getDataOfOnlyChartOnPageWithGivenToolAttribute(final PageObject pageObject, final String toolAttribute) {
    if (isChartDisplayedByDivToolAttribute(pageObject, toolAttribute)) {
        for (int i = 0; i < MAX_ATTEMPTS; i++) {
            Object result = pageObject.executeScript(String.format("delete(window.Array.prototype.toJSON) %n" + "return JSON.stringify(echarts.getInstanceByDom(document.querySelector(\"div [tool='%s']\")).getOption())", toolAttribute));
            Object scriptResult = new ScriptResult(result).getJavaScriptResult();
            if (scriptResult != null) {
                return scriptResult.toString();
            }
            pageObject.elasticSleep(1000);
        }
    }
    throw new java.util.NoSuchElementException("Found no trend chart with ID '%s''" + toolAttribute);
}
Also used : ScriptResult(com.gargoylesoftware.htmlunit.ScriptResult) PageObject(org.jenkinsci.test.acceptance.po.PageObject) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Aggregations

ScriptResult (com.gargoylesoftware.htmlunit.ScriptResult)26 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)8 SgmlPage (com.gargoylesoftware.htmlunit.SgmlPage)5 WebClient (com.gargoylesoftware.htmlunit.WebClient)5 Page (com.gargoylesoftware.htmlunit.Page)4 Event (com.gargoylesoftware.htmlunit.javascript.host.event.Event)4 Test (org.junit.Test)4 JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)3 ScriptableObject (net.sourceforge.htmlunit.corejs.javascript.ScriptableObject)3 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)2 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)2 AbstractJavaScriptEngine (com.gargoylesoftware.htmlunit.javascript.AbstractJavaScriptEngine)2 JavaScriptEngine (com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine)2 Window (com.gargoylesoftware.htmlunit.javascript.host.Window)2 KeyboardEvent (com.gargoylesoftware.htmlunit.javascript.host.event.KeyboardEvent)2 MouseEvent (com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent)2 PointerEvent (com.gargoylesoftware.htmlunit.javascript.host.event.PointerEvent)2 IOException (java.io.IOException)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 PageObject (org.jenkinsci.test.acceptance.po.PageObject)2