diff --git a/tools/junit/pom.xml b/tools/junit/pom.xml index e8fc0ea6a..9055f81c7 100644 --- a/tools/junit/pom.xml +++ b/tools/junit/pom.xml @@ -40,18 +40,6 @@ teavm-tooling ${project.version} - - org.seleniumhq.selenium - selenium-java - - - org.seleniumhq.selenium - selenium-remote-driver - - - com.fasterxml.jackson.core - jackson-databind - net.sourceforge.htmlunit htmlunit diff --git a/tools/junit/src/main/java/org/teavm/junit/JavaScriptResultParser.java b/tools/junit/src/main/java/org/teavm/junit/JavaScriptResultParser.java deleted file mode 100644 index f6ecaf4de..000000000 --- a/tools/junit/src/main/java/org/teavm/junit/JavaScriptResultParser.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2018 Alexey Andreev. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.teavm.junit; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; -import java.io.IOException; - -final class JavaScriptResultParser { - private JavaScriptResultParser() { - } - - static void parseResult(String result, TestRunCallback callback) throws IOException { - if (result == null) { - callback.complete(); - return; - } - ObjectMapper mapper = new ObjectMapper(); - ObjectNode resultObject = (ObjectNode) mapper.readTree(result); - String status = resultObject.get("status").asText(); - switch (status) { - case "ok": - callback.complete(); - break; - case "exception": { - String stack = resultObject.get("stack").asText(); - String exception = resultObject.has("exception") ? resultObject.get("exception").asText() : null; - callback.error(new AssertionError(exception + "\n" + stack)); - break; - } - } - } -} diff --git a/tools/junit/src/main/java/org/teavm/junit/SeleniumRunStrategy.java b/tools/junit/src/main/java/org/teavm/junit/SeleniumRunStrategy.java deleted file mode 100644 index a8caf7a3f..000000000 --- a/tools/junit/src/main/java/org/teavm/junit/SeleniumRunStrategy.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2016 Alexey Andreev. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.teavm.junit; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.List; -import java.util.concurrent.TimeUnit; -import org.apache.commons.io.IOUtils; -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; - -class SeleniumRunStrategy implements TestRunStrategy { - private URL url; - private ThreadLocal webDriver = new ThreadLocal<>(); - private ThreadLocal commandsSent = new ThreadLocal<>(); - - public SeleniumRunStrategy(URL url) { - this.url = url; - } - - @Override - public void beforeThread() { - RemoteWebDriver driver = new RemoteWebDriver(url, DesiredCapabilities.firefox()); - webDriver.set(driver); - commandsSent.set(0); - } - - @Override - public void afterThread() { - webDriver.get().close(); - webDriver.get().quit(); - webDriver.remove(); - } - - @Override - public void runTest(TestRun run) throws IOException { - commandsSent.set(commandsSent.get() + 1); - if (commandsSent.get().equals(100)) { - commandsSent.set(0); - webDriver.get().close(); - webDriver.get().quit(); - webDriver.set(new RemoteWebDriver(url, DesiredCapabilities.firefox())); - } - - webDriver.get().manage().timeouts().setScriptTimeout(2, TimeUnit.SECONDS); - JavascriptExecutor js = (JavascriptExecutor) webDriver.get(); - String result; - try { - result = (String) js.executeAsyncScript( - readResource("teavm-selenium.js"), - readFile(new File(run.getBaseDirectory(), "runtime.js")), - readFile(new File(run.getBaseDirectory(), run.getFileName())), - readResource("teavm-selenium-adapter.js")); - } catch (Throwable e) { - run.getCallback().error(e); - @SuppressWarnings("unchecked") - List errors = (List) js.executeScript("return window.jsErrors;"); - if (errors != null) { - for (Object error : errors) { - run.getCallback().error(new AssertionError(error)); - } - } - return; - } - - JavaScriptResultParser.parseResult(result, run.getCallback()); - } - - private String readFile(File file) throws IOException { - try (InputStream input = new FileInputStream(file)) { - return IOUtils.toString(input, "UTF-8"); - } - } - - private String readResource(String resourceName) throws IOException { - try (InputStream input = SeleniumRunStrategy.class.getClassLoader().getResourceAsStream(resourceName)) { - if (input == null) { - return ""; - } - return IOUtils.toString(input, "UTF-8"); - } - } -} diff --git a/tools/junit/src/main/java/org/teavm/junit/TeaVMTestRunner.java b/tools/junit/src/main/java/org/teavm/junit/TeaVMTestRunner.java index 79bdd4f70..04c4a7980 100644 --- a/tools/junit/src/main/java/org/teavm/junit/TeaVMTestRunner.java +++ b/tools/junit/src/main/java/org/teavm/junit/TeaVMTestRunner.java @@ -25,8 +25,6 @@ import java.io.OutputStreamWriter; import java.io.Writer; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -93,7 +91,6 @@ public class TeaVMTestRunner extends Runner implements Filterable { private static final String PATH_PARAM = "teavm.junit.target"; private static final String JS_RUNNER = "teavm.junit.js.runner"; private static final String THREAD_COUNT = "teavm.junit.js.threads"; - private static final String SELENIUM_URL = "teavm.junit.js.selenium.url"; private static final String JS_ENABLED = "teavm.junit.js"; private static final String C_ENABLED = "teavm.junit.c"; private static final String WASM_ENABLED = "teavm.junit.wasm"; @@ -151,13 +148,6 @@ public class TeaVMTestRunner extends Runner implements Filterable { if (runStrategyName != null) { TestRunStrategy jsRunStrategy; switch (runStrategyName) { - case "selenium": - try { - jsRunStrategy = new SeleniumRunStrategy(new URL(System.getProperty(SELENIUM_URL))); - } catch (MalformedURLException e) { - throw new InitializationError(e); - } - break; case "htmlunit": jsRunStrategy = new HtmlUnitRunStrategy(); break;