Skip to content

Commit

Permalink
support run test in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
jumperchen committed Sep 23, 2022
1 parent 99533a0 commit 4bdacb7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
The ZK Webdriver utility library.
-----

### Support Version
* JDK 11+
* Servlet 3 (with Jetty v10+)

### How to specify ContextPath in System Property
For example in Gradle,
Expand Down
5 changes: 1 addition & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# from puppeteer v15.5.0 Chromium 105.0.5173.0 (r1022525)
#
# same as Chrome version
version=1.0.2
version=1.0.3

# dependencies
junitVersion=5.8.1
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/org/zkoss/test/webdriver/WebDriverTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
public abstract class WebDriverTestCase {
private static final Logger log = LoggerFactory.getLogger(WebDriverTestCase.class);
public static final String PACKAGE = System.getProperty("zkWebdriverTestURLPackage", "");
private static final ThreadLocal<Server> server = new ThreadLocal<>();
private static final ThreadLocal<Integer> port = new ThreadLocal<>();
private static Server server;
private static Integer port;
private static final ThreadLocal<WebDriver> _local = new ThreadLocal<WebDriver>();
private static final String JS_DROP_FILES = "var c=arguments,b=c[0],k=c[1];c=c[2];for(var d=b.ownerDocument||document,l=0;;){var e=b.getBoundingClientRect(),g=e.left+(k||e.width/2),h=e.top+(c||e.height/2),f=d.elementFromPoint(g,h);if(f&&b.contains(f))break;if(1<++l)throw b=Error('Element not interactable'),b.code=15,b;b.scrollIntoView({behavior:'instant',block:'center',inline:'center'})}var a=d.createElement('INPUT');a.setAttribute('type','file');a.setAttribute('multiple','');a.setAttribute('style','position:fixed;z-index:2147483647;left:0;top:0;');a.onchange=function(b){a.parentElement.removeChild(a);b.stopPropagation();var c={constructor:DataTransfer,effectAllowed:'all',dropEffect:'none',types:['Files'],files:a.files,setData:function(){},getData:function(){},clearData:function(){},setDragImage:function(){}};window.DataTransferItemList&&(c.items=Object.setPrototypeOf(Array.prototype.map.call(a.files,function(a){return{constructor:DataTransferItem,kind:'file',type:a.type,getAsFile:function(){return a},getAsString:function(b){var c=new FileReader;c.onload=function(a){b(a.target.result)};c.readAsText(a)}}}),{constructor:DataTransferItemList,add:function(){},clear:function(){},remove:function(){}}));['dragenter','dragover','drop'].forEach(function(a){var b=d.createEvent('DragEvent');b.initMouseEvent(a,!0,!0,d.defaultView,0,0,0,g,h,!1,!1,!1,!1,0,null);Object.setPrototypeOf(b,null);b.dataTransfer=c;Object.setPrototypeOf(b,DragEvent.prototype);f.dispatchEvent(b)})};d.documentElement.appendChild(a);a.getBoundingClientRect();return a;";
private static final boolean IS_JENKINS = System.getenv("JENKINS_HOME") != null;
Expand Down Expand Up @@ -170,7 +170,7 @@ else if (candidateAddress == null) {
protected WebDriver driver;

protected static int getPort() {
return port.get();
return port;
}

protected static String getContextPath() {
Expand Down Expand Up @@ -323,12 +323,12 @@ public static void init() throws Exception {

protected static void initServer(Server currentServer) throws Exception {
currentServer.start();
server.set(currentServer);
server = currentServer;

for (Connector c : currentServer.getConnectors()) {
if (c instanceof NetworkConnector) {
if (((NetworkConnector) c).getLocalPort() > 0) {
port.set(((NetworkConnector) c).getLocalPort());
port = ((NetworkConnector) c).getLocalPort();
break;
}
}
Expand All @@ -337,12 +337,9 @@ protected static void initServer(Server currentServer) throws Exception {

@AfterAll
public static void end() throws Exception {
Server currentServer = server.get();
if (currentServer != null) {
currentServer.stop();
if (server != null) {
server.stop();
}
server.set(null);
port.set(0);
}

/**
Expand Down

0 comments on commit 4bdacb7

Please sign in to comment.