@Test
 // (Test Cases for 1.8) test case 4
 public void testInvalidCacheSizeOKPressed() throws Exception {
   Utility.createProject(Messages.projCache);
   SWTBotShell propShell = Utility.selCacheUsingCnxtMenu(Messages.projCache, Messages.role1);
   wabot.checkBox().select();
   // Cache size = 0
   // typeText and setting focus on OK is IMP.
   wabot.textWithLabel(Messages.cachScaleLbl).setText("");
   wabot.textWithLabel(Messages.cachScaleLbl).typeText("0");
   wabot.button("OK").setFocus();
   wabot.button("OK").click();
   SWTBotShell errorShell = wabot.shell(Messages.cachPerErrTtl).activate();
   Boolean zeroErr = errorShell.getText().equals(Messages.cachPerErrTtl);
   wabot.button("OK").click();
   // Cache size < 0 i.e. Negative
   wabot.textWithLabel(Messages.cachScaleLbl).setText("");
   wabot.textWithLabel(Messages.cachScaleLbl).typeText("-2");
   wabot.button("OK").setFocus();
   wabot.button("OK").click();
   errorShell = wabot.shell(Messages.cachPerErrTtl).activate();
   Boolean negErr = errorShell.getText().equals(Messages.cachPerErrTtl);
   wabot.button("OK").click();
   // Cache size > 100
   wabot.textWithLabel(Messages.cachScaleLbl).setText("");
   wabot.textWithLabel(Messages.cachScaleLbl).typeText("105%");
   wabot.button("OK").setFocus();
   wabot.button("OK").click();
   errorShell = wabot.shell(Messages.cachPerErrTtl).activate();
   Boolean grtErr = errorShell.getText().equals(Messages.cachPerErrTtl);
   wabot.button("OK").click();
   assertTrue("testInvalidCacheSizeOKPressed", zeroErr && negErr && grtErr);
   propShell.close();
 }
 @Test
 // (Test Cases for 1.8) test case 6
 public void testNtNumericCacheSizeOKPressed() throws Exception {
   Utility.createProject(Messages.projCache);
   SWTBotShell propShell = Utility.selCacheUsingCnxtMenu(Messages.projCache, Messages.role1);
   wabot.checkBox().select();
   // Cache size = alphabet
   // typeText and setting focus on OK is IMP.
   wabot.textWithLabel(Messages.cachScaleLbl).setText("");
   wabot.textWithLabel(Messages.cachScaleLbl).typeText("ab");
   wabot.button("OK").setFocus();
   wabot.button("OK").click();
   SWTBotShell errorShell = wabot.shell(Messages.cachPerErrTtl).activate();
   Boolean alphabtErr = errorShell.getText().equals(Messages.cachPerErrTtl);
   wabot.button("OK").click();
   // Cache size = special character
   wabot.textWithLabel(Messages.cachScaleLbl).setText("");
   wabot.textWithLabel(Messages.cachScaleLbl).typeText("#*");
   wabot.button("OK").setFocus();
   wabot.button("OK").click();
   errorShell = wabot.shell(Messages.cachPerErrTtl).activate();
   Boolean splCharErr = errorShell.getText().equals(Messages.cachPerErrTtl);
   wabot.button("OK").click();
   assertTrue("testNtNumericCacheSizeOKPressed", alphabtErr && splCharErr);
   propShell.close();
 }
  /**
   * Returns string representing version of defined Server Runtime on rowIndex position in Defined
   * Server Runtime table
   *
   * @param bot
   * @param rowIndex
   * @return null when no server runtime is specified, "unknown when not possible to determine
   *     server runtime version" or server runtime version
   */
  public static String getDefinedServerRuntimeVersion(SWTWorkbenchBot bot, int rowIndex) {

    String result = null;

    bot.menu(IDELabel.Menu.WINDOW).menu(IDELabel.Menu.PREFERENCES).click();
    bot.shell(IDELabel.Shell.PREFERENCES).activate();
    bot.tree()
        .expandNode(IDELabel.PreferencesDialog.SERVER_GROUP)
        .select(PreferencesDialog.RUNTIME_ENVIRONMENTS);

    SWTBotTable serverRuntimesTable = bot.table();
    if (serverRuntimesTable.rowCount() > rowIndex) {
      String[] splitServerRuntimeType = serverRuntimesTable.cell(rowIndex, 1).split(" ");
      int index = 0;
      while (index < splitServerRuntimeType.length && result == null) {
        if (splitServerRuntimeType[index].length() > 0
            && splitServerRuntimeType[index].charAt(0) >= '0'
            && splitServerRuntimeType[index].charAt(0) <= '9') {
          result = splitServerRuntimeType[index].trim();
        } else {
          index++;
        }
      }
    }

    bot.button(IDELabel.Button.OK).click();

    return result;
  }
  /**
   * Returns true if runtimeName Server Runtime is defined
   *
   * @param bot
   * @param runtimeName
   * @return
   */
  public static boolean isServerRuntimeDefined(SWTWorkbenchBot bot, String runtimeName) {

    boolean serverRuntimeNotDefined = true;

    bot.menu(IDELabel.Menu.WINDOW).menu(IDELabel.Menu.PREFERENCES).click();
    bot.shell(IDELabel.Shell.PREFERENCES).activate();
    bot.tree()
        .expandNode(IDELabel.PreferencesDialog.SERVER_GROUP)
        .select(PreferencesDialog.RUNTIME_ENVIRONMENTS);

    SWTBotTable tbRuntimeEnvironments = bot.table();
    int numRows = tbRuntimeEnvironments.rowCount();
    if (numRows > 0) {
      int currentRow = 0;
      while (serverRuntimeNotDefined && currentRow < numRows) {
        if (tbRuntimeEnvironments.cell(currentRow, 0).equalsIgnoreCase(runtimeName)) {
          serverRuntimeNotDefined = false;
        } else {
          currentRow++;
        }
      }
    }

    bot.button(IDELabel.Button.OK).click();

    return !serverRuntimeNotDefined;
  }
Пример #5
0
 protected static void waitForShellToDisappear(final String title) {
   try {
     while (bot.shell(title).isActive()) {
       // wait
     }
   } catch (final WidgetNotFoundException e) {
     // Ignore
   }
 }
 @Test
 // (Test Cases for 1.8) test case 5
 public void testInvalidCacheSizeOKToLeave() throws Exception {
   Utility.createProject(Messages.projCache);
   SWTBotShell propShell = Utility.selCacheUsingCnxtMenu(Messages.projCache, Messages.role1);
   wabot.checkBox().select();
   /*
    * To avoid missing storage account error,
    * type some value. Requires typeText only.
    */
   wabot.textWithLabel(Messages.keyLbl).typeText("a");
   wabot.textWithLabel(Messages.nameLbl).typeText("a");
   // Cache size = 0
   wabot.textWithLabel(Messages.cachScaleLbl).setText("");
   wabot.textWithLabel(Messages.cachScaleLbl).typeText("0");
   SWTBotTree properties = propShell.bot().tree();
   properties.getTreeItem(Messages.roleTreeRoot).getNode(Messages.endptPage).select();
   SWTBotShell errorShell =
       wabot.shell(String.format("%s%s", Messages.okToLeaveTtl, " ")).activate();
   Boolean zeroErr =
       errorShell.getText().equals(String.format("%s%s", Messages.okToLeaveTtl, " "));
   wabot.button("OK").click();
   // Cache size < 0 i.e. Negative
   wabot.textWithLabel(Messages.cachScaleLbl).setText("");
   wabot.textWithLabel(Messages.cachScaleLbl).typeText("-2");
   properties = propShell.bot().tree();
   properties.getTreeItem(Messages.roleTreeRoot).getNode(Messages.endptPage).select();
   errorShell = wabot.shell(String.format("%s%s", Messages.okToLeaveTtl, " ")).activate();
   Boolean negErr = errorShell.getText().equals(String.format("%s%s", Messages.okToLeaveTtl, " "));
   wabot.button("OK").click();
   // Cache size > 100
   wabot.textWithLabel(Messages.cachScaleLbl).setText("");
   wabot.textWithLabel(Messages.cachScaleLbl).typeText("105%");
   properties = propShell.bot().tree();
   properties.getTreeItem(Messages.roleTreeRoot).getNode(Messages.endptPage).select();
   errorShell = wabot.shell(String.format("%s%s", Messages.okToLeaveTtl, " ")).activate();
   Boolean grtErr = errorShell.getText().equals(String.format("%s%s", Messages.okToLeaveTtl, " "));
   wabot.button("OK").click();
   assertTrue("testInvalidCacheSizeOKToLeave", zeroErr && negErr && grtErr);
   propShell.close();
 }
 /**
  * Creates new Server within Server View when Wizard for new Project is called
  *
  * @param bot
  * @param serverGroup
  * @param serverType
  */
 public static void addServerToServerViewOnWizardPage(
     SWTWorkbenchBot bot, String serverGroup, String serverType) {
   // Check if there is defined Application Server if not create one
   if (!SWTJBTExt.isServerDefinedInWebWizardPage(bot)) {
     // Specify Application Server for Deployment
     bot.button(IDELabel.Button.NEW, 1).click();
     bot.shell(IDELabel.Shell.NEW_SERVER).activate();
     bot.tree().select(serverGroup);
     bot.tree().expandNode(serverGroup).select(serverType);
     bot.button(IDELabel.Button.FINISH).click();
   }
 }
  /**
   * Returns true if any Server Runtime is defined
   *
   * @param bot
   * @return
   */
  public static boolean isServerRuntimeDefined(SWTWorkbenchBot bot) {

    bot.menu(IDELabel.Menu.WINDOW).menu(IDELabel.Menu.PREFERENCES).click();
    bot.shell(IDELabel.Shell.PREFERENCES).activate();
    bot.tree()
        .expandNode(IDELabel.PreferencesDialog.SERVER_GROUP)
        .select(PreferencesDialog.RUNTIME_ENVIRONMENTS);
    boolean isServerRuntimeDefined = bot.table().rowCount() > 0;

    bot.button(IDELabel.Button.OK).click();

    return isServerRuntimeDefined;
  }
Пример #9
0
  public void create(String projectId) {
    bot.menu().menu("File").menu("New").menu("Project...").click();
    SWTBotShell shell = bot.shell("New Project");
    shell.activate();

    bot.tree().expandNode("SWTBot", "SWTBot Test Plug-in").select();
    bot.button("Next >").click();

    bot.textWithLabel("Plug-in Name:").setText(projectId);
    bot.textWithLabel("Plug-in id:").setText(projectId);
    bot.textWithLabel("Provider:").setText("ACME Corp.");
    bot.button("Finish").click();
    bot.waitUntil(shellCloses(shell));
  }
  /**
   * Delete Project from workspace
   *
   * @param projectName
   */
  public void deleteProject(String projectName) {

    removeProjectFromServers(projectName);

    SWTBot packageExplorer = eclipse.showView(ViewType.PACKAGE_EXPLORER);
    delay();
    SWTBotTree tree = packageExplorer.tree();
    delay();

    ContextMenuHelper.prepareTreeItemForContextMenu(tree, tree.getTreeItem(projectName));
    new SWTBotMenu(ContextMenuHelper.getContextMenu(tree, IDELabel.Menu.DELETE, false)).click();
    bot.shell(IDELabel.Shell.DELETE_RESOURCES).activate();
    bot.button(IDELabel.Button.OK).click();

    new SWTUtilExt(bot).waitForNonIgnoredJobs();
  }
  /**
   * Remove Project from all Servers
   *
   * @param projectName
   * @param stringToContain
   */
  public void removeProjectFromServers(String projectName, String stringToContain) {

    eclipse.showView(ViewType.SERVERS);

    delay();

    try {
      SWTBotTree serverTree = bot.viewByTitle(IDELabel.View.SERVERS).bot().tree();

      delay();

      // Expand All
      for (SWTBotTreeItem serverTreeItem : serverTree.getAllItems()) {
        serverTreeItem.expand();
        // if JSF Test Project is deployed to server remove it
        SWTBotTreeItem[] serverTreeItemChildren = serverTreeItem.getItems();
        if (serverTreeItemChildren != null && serverTreeItemChildren.length > 0) {
          int itemIndex = 0;
          boolean found = false;
          String treeItemlabel = null;
          do {
            treeItemlabel = serverTreeItemChildren[itemIndex].getText();
            found =
                treeItemlabel.startsWith(projectName)
                    && (stringToContain == null || treeItemlabel.indexOf(stringToContain) >= 0);
          } while (!found && ++itemIndex < serverTreeItemChildren.length);
          // Server Tree Item has Child with Text equal to JSF TEst Project
          if (found) {
            log.info("Found project to be removed from server: " + treeItemlabel);
            ContextMenuHelper.prepareTreeItemForContextMenu(
                serverTree, serverTreeItemChildren[itemIndex]);
            new SWTBotMenu(
                    ContextMenuHelper.getContextMenu(serverTree, IDELabel.Menu.REMOVE, false))
                .click();
            bot.shell("Server").activate();
            bot.button(IDELabel.Button.OK).click();
            log.info("Removed project from server: " + treeItemlabel);
            bot.sleep(10 * 1000L);
          }
        }
      }
      delay();

    } catch (WidgetNotFoundException wnfe) {
      // do nothing it means there is no server defined
    }
  }
Пример #12
0
  @Test
  public void createProject() throws Exception {
    String projectName = "prjBot-001";

    bot.menu("File").menu("New").click();
    SWTBotShell shell = bot.shell("New");
    shell.activate();
    // From menu open File > New dialog, verify whether the dialog has been opened.

    bot.tree().select("Project");
    SWTBotAssert.assertEnabled(bot.button("Next >"));
    // After selecting Project, the Next button should be enabled.

    bot.button("Next >").click();
    bot.textWithLabel("Project name:").setText(projectName);
    SWTBotAssert.assertEnabled(bot.button("Finish"));
    // Enter the Project Name, then Finish button should be enabled.

    bot.button("Finish").click();
    SWTBotAssert.assertVisible(bot.tree().select(projectName));
    // Click Finish button and verify whether the project's been successfully created.
  }
  /**
   * Choose Run On Server menu for specified project
   *
   * @param bot
   * @param projectName
   */
  public static void runProjectOnServer(SWTWorkbenchBot bot, String projectName) {

    SWTBotTree packageExplorerTree = eclipse.showView(ViewType.PACKAGE_EXPLORER).tree();

    packageExplorerTree.setFocus();
    SWTBotTreeItem packageExplorerTreeItem = packageExplorerTree.getTreeItem(projectName);

    packageExplorerTreeItem.select();
    packageExplorerTreeItem.click();
    // Search for Menu Item with Run on Server substring within label
    final SWTBotMenu menuRunAs = bot.menu(IDELabel.Menu.RUN).menu(IDELabel.Menu.RUN_AS);
    final MenuItem menuItem =
        UIThreadRunnable.syncExec(
            new WidgetResult<MenuItem>() {
              public MenuItem run() {
                int menuItemIndex = 0;
                MenuItem menuItem = null;
                final MenuItem[] menuItems = menuRunAs.widget.getMenu().getItems();
                while (menuItem == null && menuItemIndex < menuItems.length) {
                  if (menuItems[menuItemIndex].getText().indexOf("Run on Server") > -1) {
                    menuItem = menuItems[menuItemIndex];
                  } else {
                    menuItemIndex++;
                  }
                }
                return menuItem;
              }
            });
    if (menuItem != null) {
      new SWTBotMenu(menuItem).click();
      bot.shell(IDELabel.Shell.RUN_ON_SERVER).activate();
      bot.button(IDELabel.Button.FINISH).click();
      SWTUtilExt swtUtil = new SWTUtilExt(bot);
      swtUtil.waitForAll(10 * 1000L);
    } else {
      throw new WidgetNotFoundException("Unable to find Menu Item with Label 'Run on Server'");
    }
  }
  public static void continueInstall(final SWTWorkbenchBot bot, final String shellTitle)
      throws InstallFailureException {
    try {
      bot.radio(0).click();
      bot.button("Finish").click();
      // wait for Security pop-up, or install finished.
      final SWTBotShell shell = bot.shell(shellTitle);
      bot.waitWhile(
          new ICondition() {

            @Override
            public boolean test() throws Exception {
              return shell.isActive();
            }

            @Override
            public void init(SWTBot bot) {}

            @Override
            public String getFailureMessage() {
              return null;
            }
          },
          installationTimeout);
      if (bot.activeShell().getText().equals("Security Warning")) {
        bot.button("OK").click();
        System.err.println("OK clicked");
        bot.waitUntil(
            new ICondition() {
              @Override
              public boolean test() throws Exception {
                try {
                  boolean stillOpen = bot.shell(shellTitle).isOpen();
                  System.err.println("still open? " + stillOpen);
                  return !stillOpen;
                } catch (WidgetNotFoundException ex) {
                  System.err.println("no shell");
                  // Shell already closed
                  return true;
                }
              }

              @Override
              public void init(SWTBot bot) {}

              @Override
              public String getFailureMessage() {
                return null;
              }
            },
            installationTimeout); // 15 more minutes
      }
      SWTBot restartShellBot = bot.shell("Software Updates").bot();
      // Don't restart in test, test executor will do it.
      try {
        // Eclipse 4.2 => "No"
        restartShellBot.button("No").click();
      } catch (WidgetNotFoundException ex) {
        // Eclipse 3.7.x => "Not now"
        restartShellBot.button("Not Now").click();
      }
    } catch (Exception ex) {

      String installDesc = bot.text().getText();
      if (installDesc == null || installDesc.isEmpty()) {
        throw new RuntimeException("Internal error", ex);
      }
      throw new InstallFailureException(installDesc);
    }
  }
 /**
  * Deletes Application Server in Server View on position specified by index
  *
  * @param bot
  * @param index - zero based Position of Server within Server Tree
  */
 public static void deleteApplicationServer(SWTWorkbenchBot bot, int index) {
   SWTJBTExt.chooseServerPopupMenu(bot, index, IDELabel.Menu.DELETE, 10 * 1000L);
   bot.shell(IDELabel.Shell.DELETE_SERVER).activate();
   bot.button(IDELabel.Button.OK).click();
 }