mirror of
https://github.com/konsoletyper/teavm.git
synced 2024-11-21 01:00:54 +08:00
JUnit: remove selenium runner
This commit is contained in:
parent
2c8b0b55bb
commit
3e152f4bb8
@ -40,18 +40,6 @@
|
||||
<artifactId>teavm-tooling</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-remote-driver</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.htmlunit</groupId>
|
||||
<artifactId>htmlunit</artifactId>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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> webDriver = new ThreadLocal<>();
|
||||
private ThreadLocal<Integer> 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<Object> errors = (List<Object>) 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");
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user