Search in sources :

Example 6 with JavaScriptException

use of net.sourceforge.htmlunit.corejs.javascript.JavaScriptException in project selenium_tests by sergueik.

the class FirefoxPreferencesTest method testClearCacheOld.

// for Firefox version 40
@Test(enabled = false, priority = 20)
public void testClearCacheOld() {
    // Arrange
    driver.get("about:preferences#advanced");
    // Wait page to load
    wait.until(ExpectedConditions.urlContains("#advanced"));
    System.err.println("Waited on URL contains: " + driver.getCurrentUrl());
    // Click the "Clear Now" button under "Cached Web Content"
    WebElement networkTabElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("networkTab"))));
    assertThat(networkTabElement, notNullValue());
    try {
        highlight(networkTabElement);
    } catch (JavaScriptException e) {
        // org.openqa.selenium.JavascriptException: waiting for doc.body
        // failed
        System.err.println("Exception (ignored) " + e.toString());
    }
    System.err.println("Clicking on tab: " + networkTabElement.getAttribute("outerHTML"));
    // TODO: figure which method is working
    networkTabElement.click();
    networkTabElement.sendKeys(Keys.SPACE);
    actions.moveToElement(networkTabElement).click().build().perform();
    WebElement clearCacheButtonElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("clearCacheButton"))));
    assertThat(clearCacheButtonElement, notNullValue());
    System.err.println("Clicking on button: " + clearCacheButtonElement.getAttribute("outerHTML"));
    clearCacheButtonElement.click();
    WebElement clearOfflineAppCacheButtonElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("clearOfflineAppCacheButton"))));
    assertThat(clearOfflineAppCacheButtonElement, notNullValue());
    System.err.println("Clicking on button: " + clearOfflineAppCacheButtonElement.getAttribute("outerHTML"));
    clearOfflineAppCacheButtonElement.click();
    // Click the "Clear All Data" button under "Site Data"
    // this button is no longer shown in preferences, keep the code
    WebElement clearSiteDataButtonElement = null;
    try {
        clearSiteDataButtonElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("clearSiteDataButton"))));
    } catch (NoSuchElementException e) {
        return;
    }
    assertThat(clearSiteDataButtonElement, notNullValue());
    clearSiteDataButtonElement.click();
    // and accept the alert
    // TODO: Generics ?
    wait.until(ExpectedConditions.alertIsPresent());
    try {
        alert = driver.switchTo().alert();
        alert.accept();
    } catch (NoAlertPresentException e) {
    // Alert not present - ignore
    } catch (WebDriverException e) {
        System.err.println("Alert was not handled : " + e.getStackTrace().toString());
        return;
    }
}
Also used : NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) JavaScriptException(net.sourceforge.htmlunit.corejs.javascript.JavaScriptException) WebDriverException(org.openqa.selenium.WebDriverException) Test(org.testng.annotations.Test) BaseTest(com.github.sergueik.selenium.BaseTest)

Example 7 with JavaScriptException

use of net.sourceforge.htmlunit.corejs.javascript.JavaScriptException in project htmlunit-core-js by HtmlUnit.

the class StackTraceTest method runWithExpectedStackTrace.

private static void runWithExpectedStackTrace(final String _source, final String _expectedStackTrace) {
    final ContextAction<Object> action = new ContextAction<Object>() {

        @Override
        public Object run(final Context cx) {
            final Scriptable scope = cx.initSafeStandardObjects();
            try {
                cx.evaluateString(scope, _source, "test.js", 0, null);
            } catch (final JavaScriptException e) {
                assertEquals(_expectedStackTrace, e.getScriptStackTrace());
                return null;
            }
            throw new RuntimeException("Exception expected!");
        }
    };
    Utils.runWithOptimizationLevel(action, -1);
}
Also used : Context(net.sourceforge.htmlunit.corejs.javascript.Context) ContextAction(net.sourceforge.htmlunit.corejs.javascript.ContextAction) Scriptable(net.sourceforge.htmlunit.corejs.javascript.Scriptable) JavaScriptException(net.sourceforge.htmlunit.corejs.javascript.JavaScriptException)

Aggregations

JavaScriptException (net.sourceforge.htmlunit.corejs.javascript.JavaScriptException)7 Context (net.sourceforge.htmlunit.corejs.javascript.Context)3 ScriptableObject (net.sourceforge.htmlunit.corejs.javascript.ScriptableObject)3 WebClient (com.gargoylesoftware.htmlunit.WebClient)2 JavaScriptEngine (com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine)2 ContextFactory (net.sourceforge.htmlunit.corejs.javascript.ContextFactory)2 EcmaError (net.sourceforge.htmlunit.corejs.javascript.EcmaError)2 Scriptable (net.sourceforge.htmlunit.corejs.javascript.Scriptable)2 Test (org.junit.Test)2 HtmlObject (com.gargoylesoftware.htmlunit.html.HtmlObject)1 HtmlUnitScriptable (com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable)1 JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)1 Window (com.gargoylesoftware.htmlunit.javascript.host.Window)1 BaseTest (com.github.sergueik.selenium.BaseTest)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ContextAction (net.sourceforge.htmlunit.corejs.javascript.ContextAction)1 Function (net.sourceforge.htmlunit.corejs.javascript.Function)1 Interpreter (net.sourceforge.htmlunit.corejs.javascript.Interpreter)1 WrappedException (net.sourceforge.htmlunit.corejs.javascript.WrappedException)1