portals-pluto-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asfgr...@apache.org
Subject [07/22] portals-pluto git commit: PLUTO-733 Only close the browser after all tests are done
Date Thu, 25 Oct 2018 20:19:39 GMT
PLUTO-733 Only close the browser after all tests are done


Project: http://git-wip-us.apache.org/repos/asf/portals-pluto/repo
Commit: http://git-wip-us.apache.org/repos/asf/portals-pluto/commit/3090b959
Tree: http://git-wip-us.apache.org/repos/asf/portals-pluto/tree/3090b959
Diff: http://git-wip-us.apache.org/repos/asf/portals-pluto/diff/3090b959

Branch: refs/heads/master
Commit: 3090b95928f6bc00b18494bea32ad8fa1c219bc4
Parents: 5ea9551
Author: Kyle Stiemann <stiemannkj1@gmail.com>
Authored: Wed Oct 10 17:06:22 2018 -0400
Committer: Neil Griffin <neil.griffin.scm@gmail.com>
Committed: Thu Oct 25 15:48:30 2018 -0400

----------------------------------------------------------------------
 .../demo/integration/test/DemoTestDriver.java   |   5 +-
 .../pluto/test/utilities/SimpleTestDriver.java  | 231 ++++++++++---------
 2 files changed, 122 insertions(+), 114 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/3090b959/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/DemoTestDriver.java
----------------------------------------------------------------------
diff --git a/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/DemoTestDriver.java
b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/DemoTestDriver.java
index e0b87a9..6ccd254 100644
--- a/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/DemoTestDriver.java
+++ b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/DemoTestDriver.java
@@ -30,6 +30,9 @@ public class DemoTestDriver extends SimpleTestDriver {
 
    @BeforeClass
    public static void setUpBeforeDemoSimpleTestDriverClass() {
-      waitingAsserter = new WaitingAsserter(driver, timeout);
+
+      if (waitingAsserter == null) {
+         waitingAsserter = new WaitingAsserter(driver, timeout);
+      }
    }
 }

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/3090b959/test-base/src/main/java/org/apache/portals/pluto/test/utilities/SimpleTestDriver.java
----------------------------------------------------------------------
diff --git a/test-base/src/main/java/org/apache/portals/pluto/test/utilities/SimpleTestDriver.java
b/test-base/src/main/java/org/apache/portals/pluto/test/utilities/SimpleTestDriver.java
index ee40644..9c45e49 100644
--- a/test-base/src/main/java/org/apache/portals/pluto/test/utilities/SimpleTestDriver.java
+++ b/test-base/src/main/java/org/apache/portals/pluto/test/utilities/SimpleTestDriver.java
@@ -55,124 +55,132 @@ public class SimpleTestDriver {
    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
 
-      loginUrl = System.getProperty("test.server.login.url");
-      host = System.getProperty("test.server.host");
-      port = System.getProperty("test.server.port");
-      username = System.getProperty("test.server.username");
-      usernameId = System.getProperty("test.server.username.id");
-      password = System.getProperty("test.server.password");
-      passwordId = System.getProperty("test.server.password.id");
-      browser = System.getProperty("test.browser");
-      testContextBase = System.getProperty("test.context.base");
-      StringBuilder sb = new StringBuilder();
-      sb.append("http://");
-      sb.append(host);
-      if (port != null && !port.isEmpty()) {
-         sb.append(":");
-         sb.append(port);
-      }
-      sb.append("/");
-      sb.append(testContextBase);
-      baseUrl = sb.toString();
-      String str = System.getProperty("test.url.strategy");
-      useGeneratedUrl = str.equalsIgnoreCase("generateURLs");
-      str = System.getProperty("test.debug");
-      debug = str.equalsIgnoreCase("true");
-      str = System.getProperty("test.timeout");
-      dryrun = new Boolean(System.getProperty("test.dryrun"));
-      timeout = ((str != null) && str.matches("\\d+")) ? Integer.parseInt(str) :
3;
-      String wd = System.getProperty("test.browser.webDriver");
-      String binary = System.getProperty("test.browser.binary");
-      String headlessProperty = System.getProperty("test.browser.headless");
-      boolean headless = (((headlessProperty == null) || (headlessProperty.length() == 0)
||
-            Boolean.valueOf(headlessProperty)));
-      String maximizedProperty = System.getProperty("test.browser.maximized");
-      boolean maximized = "true".equalsIgnoreCase(maximizedProperty);
-
-      System.out.println("before class.");
-      System.out.println("   Debug        =" + debug);
-      System.out.println("   Dryrun       =" + dryrun);
-      System.out.println("   Timeout      =" + timeout);
-      System.out.println("   Login URL    =" + loginUrl);
-      System.out.println("   Host         =" + host);
-      System.out.println("   Port         =" + port);
-      System.out.println("   Context      =" + testContextBase);
-      System.out.println("   Generate URL =" + useGeneratedUrl);
-      System.out.println("   Username     =" + username);
-      System.out.println("   UsernameId   =" + usernameId);
-      System.out.println("   Password     =" + password);
-      System.out.println("   PasswordId   =" + passwordId);
-      System.out.println("   Browser      =" + browser);
-      System.out.println("   Driver       =" + wd);
-      System.out.println("   binary       =" + binary);
-      System.out.println("   headless     =" + headless);
-      System.out.println("   maximized    =" + maximized);
-
-      if (browser.equalsIgnoreCase("firefox")) {
-
-         System.setProperty("webdriver.gecko.driver", wd);
-         FirefoxOptions options = new FirefoxOptions();
-         options.setLegacy(true);
-         options.setAcceptInsecureCerts(true);
-
-         if ((binary != null) && (binary.length() != 0)) {
-            options.setBinary(binary);
-         }
-
-         if (headless) {
-            options.setHeadless(true);
-         }
-
-         driver = new FirefoxDriver(options);
-
-      } else if (browser.equalsIgnoreCase("internetExplorer")) {
-         System.setProperty("webdriver.ie.driver", wd);
-         driver = new InternetExplorerDriver();
-      } else if (browser.equalsIgnoreCase("chrome")) {
-
-         System.setProperty("webdriver.chrome.driver", wd);
-         ChromeOptions options = new ChromeOptions();
-
-         if ((binary != null) && (binary.length() > 0)) {
-            options.setBinary(binary);
+      if (driver == null) {
+         loginUrl = System.getProperty("test.server.login.url");
+         host = System.getProperty("test.server.host");
+         port = System.getProperty("test.server.port");
+         username = System.getProperty("test.server.username");
+         usernameId = System.getProperty("test.server.username.id");
+         password = System.getProperty("test.server.password");
+         passwordId = System.getProperty("test.server.password.id");
+         browser = System.getProperty("test.browser");
+         testContextBase = System.getProperty("test.context.base");
+         StringBuilder sb = new StringBuilder();
+         sb.append("http://");
+         sb.append(host);
+         if (port != null && !port.isEmpty()) {
+            sb.append(":");
+            sb.append(port);
          }
-
-         if (headless) {
-            options.addArguments("--headless");
+         sb.append("/");
+         sb.append(testContextBase);
+         baseUrl = sb.toString();
+         String str = System.getProperty("test.url.strategy");
+         useGeneratedUrl = str.equalsIgnoreCase("generateURLs");
+         str = System.getProperty("test.debug");
+         debug = str.equalsIgnoreCase("true");
+         str = System.getProperty("test.timeout");
+         dryrun = Boolean.valueOf(System.getProperty("test.dryrun"));
+         timeout = ((str != null) && str.matches("\\d+")) ? Integer.parseInt(str)
: 3;
+         String wd = System.getProperty("test.browser.webDriver");
+         String binary = System.getProperty("test.browser.binary");
+         String headlessProperty = System.getProperty("test.browser.headless");
+         boolean headless = (((headlessProperty == null) || (headlessProperty.length() ==
0) ||
+               Boolean.valueOf(headlessProperty)));
+         String maximizedProperty = System.getProperty("test.browser.maximized");
+         boolean maximized = Boolean.valueOf(maximizedProperty);
+
+         System.out.println("before class.");
+         System.out.println("   Debug        =" + debug);
+         System.out.println("   Dryrun       =" + dryrun);
+         System.out.println("   Timeout      =" + timeout);
+         System.out.println("   Login URL    =" + loginUrl);
+         System.out.println("   Host         =" + host);
+         System.out.println("   Port         =" + port);
+         System.out.println("   Context      =" + testContextBase);
+         System.out.println("   Generate URL =" + useGeneratedUrl);
+         System.out.println("   Username     =" + username);
+         System.out.println("   UsernameId   =" + usernameId);
+         System.out.println("   Password     =" + password);
+         System.out.println("   PasswordId   =" + passwordId);
+         System.out.println("   Browser      =" + browser);
+         System.out.println("   Driver       =" + wd);
+         System.out.println("   binary       =" + binary);
+         System.out.println("   headless     =" + headless);
+         System.out.println("   maximized    =" + maximized);
+
+         if (browser.equalsIgnoreCase("firefox")) {
+
+            System.setProperty("webdriver.gecko.driver", wd);
+            FirefoxOptions options = new FirefoxOptions();
+            options.setLegacy(true);
+            options.setAcceptInsecureCerts(true);
+
+            if ((binary != null) && (binary.length() != 0)) {
+               options.setBinary(binary);
+            }
+
+            if (headless) {
+               options.setHeadless(true);
+            }
+
+            driver = new FirefoxDriver(options);
+
+         } else if (browser.equalsIgnoreCase("internetExplorer")) {
+            System.setProperty("webdriver.ie.driver", wd);
+            driver = new InternetExplorerDriver();
+         } else if (browser.equalsIgnoreCase("chrome")) {
+
+            System.setProperty("webdriver.chrome.driver", wd);
+            ChromeOptions options = new ChromeOptions();
+
+            if ((binary != null) && (binary.length() > 0)) {
+               options.setBinary(binary);
+            }
+
+            if (headless) {
+               options.addArguments("--headless");
+            }
+
+            options.addArguments("--disable-infobars");
+            options.setAcceptInsecureCerts(true);
+
+            if (maximized) {
+               // The webDriver.manage().window().maximize() feature does not work correctly
in headless mode, so set the
+               // window size to 1920x1200 (resolution of a 15.4 inch screen).
+               options.addArguments("--window-size=1920,1200");
+            }
+
+            driver = new ChromeDriver(options);
+
+         } else if (browser.equalsIgnoreCase("phantomjs")) {
+            DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
+            capabilities.setJavascriptEnabled(true);
+            capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
binary);
+            driver = new PhantomJSDriver(capabilities);
+         } else if (browser.equalsIgnoreCase("htmlUnit")) {
+           driver = new HtmlUnitDriver();
+         } else if (browser.equalsIgnoreCase("safari")) {
+            driver = new SafariDriver();
+         } else {
+            throw new Exception("Unsupported browser: " + browser);
          }
 
-         options.addArguments("--disable-infobars");
-         options.setAcceptInsecureCerts(true);
+         Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
+            @Override
+            public void run() {
+               driver.quit();
+            }
+         }));
 
          if (maximized) {
-            // The webDriver.manage().window().maximize() feature does not work correctly
in headless mode, so set the
-            // window size to 1920x1200 (resolution of a 15.4 inch screen).
-            options.addArguments("--window-size=1920,1200");
+            driver.manage().window().maximize();
          }
 
-         driver = new ChromeDriver(options);
-
-      } else if (browser.equalsIgnoreCase("phantomjs")) {
-         DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
-         capabilities.setJavascriptEnabled(true);
-         capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
binary);
-         driver = new PhantomJSDriver(capabilities);
-      } else if (browser.equalsIgnoreCase("htmlUnit")) {
-        driver = new HtmlUnitDriver();
-      } else if (browser.equalsIgnoreCase("safari")) {
-         driver = new SafariDriver();
-      } else {
-         throw new Exception("Unsupported browser: " + browser);
-      }
-
-      if (maximized) {
-         driver.manage().window().maximize();
-      }
-
-      if (!dryrun) {
-         login();
+         if (!dryrun) {
+            login();
+         }
       }
-
    }
 
    /**
@@ -207,9 +215,6 @@ public class SimpleTestDriver {
     */
    @AfterClass
    public static void tearDownAfterClass() throws Exception {
-      if (driver != null) {
-         driver.quit();
-      }
       System.out.println("   after class.");
    }
 


Mime
View raw message