Esempio n. 1
0
  protected void startSession() throws Exception {
    /*startSeleniumSession("localhost", 4444, "*chrome",
    	"http://www.abc.com", LoggingResultsFormatter);
    selenium = session();*/

    selenium.setTimeout(TIMEOUT);
    selenium.open("/");
    selenium.windowFocus();
    selenium.windowMaximize();
  }
Esempio n. 2
0
  /**
   * This method returns a LoggingSelenium instance. Launches the browser with a new Selenium
   * session. Use this only if you want to have one selenium instance.
   *
   * @return Selenium session
   */
  public LoggingSelenium createDefaultSeleniumInstance(String browser, String url) {

    boolean quit = false;
    // if (selenium == null) {
    try {
      final String RESULT_FILE_ENCODING = "UTF-8";
      final String SCREENSHOT_PATH = "screenshots";

      String resultsPath = new File(RESULTS_BASE_PATH).getAbsolutePath();
      String screenshotsResultsPath =
          new File(RESULTS_BASE_PATH + File.separator + SCREENSHOT_PATH).getAbsolutePath();

      if (!new File(resultsPath).exists()) {
        new File(resultsPath).mkdirs();
      }
      if (!new File(screenshotsResultsPath).exists()) {
        new File(screenshotsResultsPath).mkdirs();
      }

      currentScreenShotPath = screenshotsResultsPath;

      String partialFileName =
          File.separator + testName + "report_" + timeStampForFileName() + ".html";

      resultHtmlFileName = resultsPath + partialFileName;
      relativeResultHtmlFileName = RESULTS_BASE_PATH + partialFileName;

      System.err.println("resultHtmlFileName=" + resultHtmlFileName);
      loggingWriter = LoggingUtils.createWriter(resultHtmlFileName, RESULT_FILE_ENCODING, true);

      LoggingResultsFormatter htmlFormatter =
          new HtmlResultFormatter(loggingWriter, RESULT_FILE_ENCODING);

      htmlFormatter.setScreenShotBaseUri(SCREENSHOT_PATH + "/");
      htmlFormatter.setAutomaticScreenshotPath(screenshotsResultsPath);
      LoggingCommandProcessor myProcessor =
          new LoggingCommandProcessor(
              ConfigFileReader.getConfigItemValue("selenium.server.host"),
              4444,
              browser,
              url,
              htmlFormatter);
      myProcessor.setExcludedCommands(
          new String[] {"captureEntirePageScreenshotToString", "captureScreenshot"});
      selenium = new LoggingDefaultSelenium(myProcessor);

      /*			RemoteControlConfiguration rcc = server.getConfiguration();
      File profileLocation = new File(ConfigFileReader.getConfigItemValue("selenium.firefox.profile"));
      rcc.setProfilesLocation(profileLocation);
      rcc.setFirefoxProfileTemplate(profileLocation);
      rcc.setReuseBrowserSessions(true);
      selenium.start(rcc);

      BrowserConfigurationOptions bb = new BrowserConfigurationOptions();
      bb.setProfile(profile)*/
      selenium.start();

      selenium.setSpeed(ConfigFileReader.getConfigItemValue("selenium.speed"));
      selenium.setTimeout("120000");
      // selenium.deleteAllVisibleCookies();

      try {
        selenium.open(url);
      } catch (Exception e) {
        // selenium.refresh();
        selenium.waitForElementPresent("css=a:contains('Sign In')");
      }

      // selenium.waitForPageToLoad(TestConsts.PAGE_LOAD_TIMEOUT);
      selenium.waitForElementPresent("css=a:contains('Sign In')");
      selenium.windowMaximize();
      selenium.windowFocus();

    } catch (SeleniumException ex) {
      logger.error(ex.getMessage());
      quit = true;
      // }
    }
    if (quit) {
      stopSeleniumInstance();
      System.exit(0);
    }

    return selenium;
  }