public static void setWebDriverFactory(String factoryName, DriverOptions driverOptions) {
   try {
     manager.setWebDriverFactory(factoryName);
     manager.setDriverOptions(driverOptions);
     TestBase.factoryName = factoryName;
   } catch (UnsupportedOperationException e) {
     Assume.assumeNoException(e);
   }
 }
 @AfterClass
 public static void baseTeardown() {
   manager.quitDriver();
   manager = null;
   factoryName = null;
 }
Esempio n. 3
0
 protected void exit(int exitCode) {
   this.exitCode = exitCode;
   log.info("Exit code: {}", exitCode);
   WebDriverManager.quitDriversOnAllManagers();
   if (!noExit) System.exit(exitCode);
 }
 @BeforeClass
 public static void baseSetup() {
   manager = WebDriverManager.newInstance();
 }
Esempio n. 5
0
 /**
  * Setup Runner by configuration.
  *
  * @param runner Runner object.
  * @param config configuration.
  * @param filenames filenames of test-suites/test-cases.
  */
 public void setupRunner(Runner runner, IConfig config, String... filenames) {
   if (config.getMaxTime() != null) {
     long maxTime = NumberUtils.toLong(config.getMaxTime(), 0);
     if (maxTime <= 0)
       throw new IllegalArgumentException("Invalid max time value. (" + config.getMaxTime() + ")");
     runner.setupMaxTimeTimer(maxTime * 1000);
   }
   String driverName = config.getDriver();
   DriverOptions driverOptions = new DriverOptions(config);
   if (driverName == null) {
     if (driverOptions.has(DriverOption.FIREFOX)) driverName = WebDriverManager.FIREFOX;
     else if (driverOptions.has(DriverOption.CHROMEDRIVER)) driverName = WebDriverManager.CHROME;
     else if (driverOptions.has(DriverOption.IEDRIVER)) driverName = WebDriverManager.IE;
     else if (driverOptions.has(DriverOption.PHANTOMJS)) driverName = WebDriverManager.PHANTOMJS;
   }
   WebDriverManager manager = WebDriverManager.newInstance();
   manager.setWebDriverFactory(driverName);
   manager.setDriverOptions(driverOptions);
   if (config.getCommandFactory() != null) {
     String factoryName = config.getCommandFactory();
     ICommandFactory factory;
     try {
       Class<?> factoryClass = Class.forName(factoryName);
       factory = (ICommandFactory) factoryClass.newInstance();
     } catch (Exception e) {
       e.printStackTrace();
       throw new IllegalArgumentException("invalid user defined command factory: " + factoryName);
     }
     runner.getCommandFactory().registerCommandFactory(factory);
     log.info("Registered: {}", factoryName);
   }
   runner.setDriver(manager.get());
   runner.setWebDriverPreparator(manager);
   if (config.isHighlight()) runner.setHighlight(true);
   if (config.isInteractive()) runner.setInteractive(true);
   if (config.getScreenshotDir() != null) runner.setScreenshotDir(config.getScreenshotDir());
   if (config.getScreenshotAll() != null) runner.setScreenshotAllDir(config.getScreenshotAll());
   if (config.getScreenshotOnFail() != null)
     runner.setScreenshotOnFailDir(config.getScreenshotOnFail());
   if (config.getBaseurl() != null) runner.setOverridingBaseURL(config.getBaseurl());
   if (config.isIgnoreScreenshotCommand()) runner.setIgnoredScreenshotCommand(true);
   if (config.getRollup() != null) {
     String[] rollups = config.getRollup();
     for (String rollup : rollups) runner.getRollupRules().load(rollup);
   }
   if (config.getCookieFilter() != null) {
     String cookieFilter = config.getCookieFilter();
     if (cookieFilter.length() < 2)
       throw new IllegalArgumentException("invalid cookie filter format: " + cookieFilter);
     FilterType filterType;
     switch (cookieFilter.charAt(0)) {
       case '+':
         filterType = FilterType.PASS;
         break;
       case '-':
         filterType = FilterType.SKIP;
         break;
       default:
         throw new IllegalArgumentException("invalid cookie filter format: " + cookieFilter);
     }
     String pattern = cookieFilter.substring(1);
     runner.setCookieFilter(new CookieFilter(filterType, pattern));
   }
   if (config.getXmlResult() != null) runner.setJUnitResultDir(config.getXmlResult());
   if (config.getHtmlResult() != null) runner.setHtmlResultDir(config.getHtmlResult());
   int timeout = NumberUtils.toInt(config.getTimeout(), DEFAULT_TIMEOUT_MILLISEC_N);
   if (timeout <= 0)
     throw new IllegalArgumentException("Invalid timeout value. (" + config.getTimeout() + ")");
   runner.setTimeout(timeout);
   int speed = NumberUtils.toInt(config.getSetSpeed(), 0);
   if (speed < 0)
     throw new IllegalArgumentException("Invalid speed value. (" + config.getSetSpeed() + ")");
   runner.setInitialSpeed(speed);
   if (config.isNoExit()) noExit = true;
   if (config.isStrictExitCode()) exitStrictly = true;
   runner.setPrintStream(System.out);
 }