Reuse the browser for js and in brwsr test execution closure
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 06 May 2014 11:46:47 +0200
branchclosure
changeset 1537897d7f70c5a5
parent 1536 7f477a85dbff
child 1540 32531a9626bf
Reuse the browser for js and in brwsr test execution
rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java
     1.1 --- a/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java	Tue May 06 11:30:08 2014 +0200
     1.2 +++ b/rt/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java	Tue May 06 11:46:47 2014 +0200
     1.3 @@ -18,8 +18,10 @@
     1.4  package org.apidesign.bck2brwsr.vmtest.impl;
     1.5  
     1.6  import java.io.IOException;
     1.7 +import java.util.HashSet;
     1.8  import java.util.LinkedHashMap;
     1.9  import java.util.Map;
    1.10 +import java.util.Set;
    1.11  import org.apidesign.bck2brwsr.launcher.Launcher;
    1.12  import org.testng.annotations.AfterGroups;
    1.13  import org.testng.annotations.BeforeGroups;
    1.14 @@ -44,7 +46,14 @@
    1.15          if (js == null && create) {
    1.16              final String p = System.getProperty("vmtest.js", "script"); // NOI18N
    1.17              switch (p) {
    1.18 -                case "brwsr": js = Launcher.createBrowser(null); break; // NOI18N
    1.19 +                case "brwsr": // NOI18N
    1.20 +                    String cmd = null;
    1.21 +                    String pb = System.getProperty("vmtest.brwsrs"); // NOI18N
    1.22 +                    if (pb != null) {
    1.23 +                        cmd = pb.split(",")[0]; // NOI18N
    1.24 +                    }
    1.25 +                    js = brwsr(cmd);
    1.26 +                    break;
    1.27                  case "script": js = Launcher.createJavaScript(); break; // NOI18N
    1.28                  default: throw new IllegalArgumentException(
    1.29                      "Unknown value of vmtest.js property: " + p
    1.30 @@ -65,20 +74,22 @@
    1.31  
    1.32      @BeforeGroups("run")
    1.33      public void initializeLauncher() throws IOException {
    1.34 +        Set<Launcher> all = new HashSet<>(brwsrs.values());
    1.35          if (js(false) != null) {
    1.36 -            js(true).initialize();
    1.37 +            all.add(js(true));
    1.38          }
    1.39 -        for (Launcher launcher : brwsrs.values()) {
    1.40 +        for (Launcher launcher : all) {
    1.41              launcher.initialize();
    1.42          }
    1.43      }
    1.44  
    1.45      @AfterGroups("run")
    1.46      public void shutDownLauncher() throws IOException, InterruptedException {
    1.47 +        Set<Launcher> all = new HashSet<>(brwsrs.values());
    1.48          if (js(false) != null) {
    1.49 -            js(true).shutdown();
    1.50 +            all.add(js(true));
    1.51          }
    1.52 -        for (Launcher launcher : brwsrs.values()) {
    1.53 +        for (Launcher launcher : all) {
    1.54              launcher.shutdown();
    1.55          }
    1.56      }