private void importFinish() {
   SWTBotShell shell = fBot.activeShell();
   final SWTBotButton finishButton = fBot.button("Finish");
   finishButton.click();
   fBot.waitUntil(Conditions.shellCloses(shell));
   SWTBotUtils.waitForJobs();
 }
  /**
   * 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;
  }
  /**
   * 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;
  }
  /**
   * Clicks a button asynchronously and waits till the given condition is fulfilled.
   *
   * @param bot the SWT bot
   * @param button the button to click
   * @param waitCondition the condition to wait for, may be null
   * @throws TimeoutException
   */
  public static void asyncClick(
      final SWTWorkbenchBot bot, final SWTBotButton button, final ICondition waitCondition)
      throws TimeoutException {
    bot.waitUntil(
        new DefaultCondition() {
          public boolean test() throws Exception {
            return button.isEnabled();
          }

          public String getFailureMessage() {
            return "Button isn't enabled.";
          }
        });

    UIThreadRunnable.asyncExec(
        bot.getDisplay(),
        new VoidResult() {
          public void run() {
            button.click();
          }
        });

    if (waitCondition != null) {
      bot.waitUntil(waitCondition);
    }
  }
  /**
   * Expands the entry. Takes care that all attributes and child entries are initialized so that
   * there are no pending background actions and event notifications. This is necessary to avoid
   * race conditions.
   *
   * @param bot the bot
   * @param entry the entry to expand
   * @param nextName the name of the entry that must become visible, may be null
   * @throws Exception the exception
   */
  public static void expandEntry(
      final SWTWorkbenchBot bot, final SWTBotTreeItem entry, final String nextName) {
    UIThreadRunnable.asyncExec(
        bot.getDisplay(),
        new VoidResult() {
          public void run() {
            entry.expand();
          }
        });

    bot.waitUntil(
        new DefaultCondition() {
          public boolean test() throws Exception {
            if (nextName != null) {
              String adjustedNodeName = nextName != null ? adjustNodeName(entry, nextName) : null;
              SWTBotTreeItem node = entry.getNode(adjustedNodeName);
              if (node == null) {
                return false;
              }
            }
            return !entry.getNodes().contains("Fetching Entries...");
          }

          public String getFailureMessage() {
            return "Could not find entry " + entry.getText() + " -> " + nextName;
          }
        });
  }
  // "Operations and Monitoring Explorer"
  public static SWTBotTree getTree(String ViewTitle) throws Exception {
    SWTBotView view = bot.viewByTitle(ViewTitle);
    view.show();

    Tree tree = (Tree) bot.widget(widgetOfType(Tree.class), view.getWidget());
    return new SWTBotTree(tree);
  }
  private void expand(final SWTBotTreeItem entry, boolean wait, final String nextNode) {
    UIThreadRunnable.asyncExec(
        bot.getDisplay(),
        new VoidResult() {
          public void run() {
            entry.expand();
          }
        });

    if (wait) {
      bot.waitUntil(
          new DefaultCondition() {
            public boolean test() throws Exception {
              //                    if ( nextNode != null )
              //                    {
              //                        String adjustedNodeName = nextNode != null ? adjustNodeName(
              // entry, nextNode ) : null;
              //                        SWTBotTreeItem node = entry.getNode( adjustedNodeName );
              //                        if ( node == null )
              //                        {
              //                            return false;
              //                        }
              //                    }
              return !entry.getNodes().contains("Fetching Entries...")
                  && !entry.getNodes().contains("Opening Connection...");
            }

            public String getFailureMessage() {
              return "Could not find entry " + entry.getText() + " -> " + nextNode;
            }
          });
    }
  }
 @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();
 }
  private void selectImportFromArchive(String archivePath) {
    SWTBotRadio button = fBot.radio("Select &archive file:");
    button.click();

    SWTBotCombo sourceCombo = fBot.comboBox(1);

    sourceCombo.setText(new File(archivePath).getAbsolutePath());

    SWTBotText text = fBot.text();
    text.setFocus();
  }
 /**
  * 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();
   }
 }
 @Test
 // (Test Cases for 1.8) test case 1
 public void testCachingPagePresent() throws Exception {
   Utility.createProject(Messages.projCache);
   SWTBotShell propShell = Utility.selCacheUsingCnxtMenu(Messages.projCache, Messages.role1);
   assertTrue(
       "testCachingPagePresent",
       wabot.checkBox().isEnabled()
           && !wabot.checkBox().isChecked()
           && wabot.button("OK").isEnabled()
           && wabot.button("Cancel").isEnabled());
   propShell.close();
 }
  /**
   * 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;
  }
  /**
   * Clicks a tree item asynchronously and waits till the given condition is fulfilled.
   *
   * @param bot the SWT bot
   * @param item the tree item to click
   * @param waitCondition the condition to wait for, may be null
   * @throws TimeoutException the timeout exception
   */
  public static void asyncClick(
      final SWTWorkbenchBot bot, final SWTBotTreeItem item, final ICondition waitCondition)
      throws TimeoutException {
    UIThreadRunnable.asyncExec(
        bot.getDisplay(),
        new VoidResult() {
          public void run() {
            item.click();
          }
        });

    if (waitCondition != null) {
      bot.waitUntil(waitCondition);
    }
  }
 @BeforeClass
 public static void setUp() throws Exception {
   menu.createNewModelProject(DS_PROJECT);
   IPath path = new Path(DS_PROJECT + "/" + TRANSLATIONS);
   on.selectNode(path).doubleClick();
   editor = bot.editorByTitle(DS_PROJECT + " Translation Overview");
 }
  /**
   * 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
    }
  }
 @BeforeClass
 public static void beforeClass() throws Exception {
   wabot = new SWTWorkbenchBot();
   try {
     wabot.viewByTitle("Welcome").close();
   } catch (Exception e) {
   }
 }
Beispiel #18
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));
  }
 /**
  * Returns true when in Web Page of Wizard is defined at least one Server Runtime Instance
  *
  * @param bot
  * @return
  */
 public static boolean isServerDefinedInWebWizardPage(SWTWorkbenchBot bot) {
   boolean isServerDefined = false;
   try {
     bot.label(IDELabel.ImportJSFProjectDialog.CHOICE_LIST_IS_EMPTY);
   } catch (WidgetNotFoundException wnfe) {
     isServerDefined = true;
   }
   return isServerDefined;
 }
 public static StagingViewTester openStagingView() throws Exception {
   SWTWorkbenchBot workbenchBot = new SWTWorkbenchBot();
   UIThreadRunnable.syncExec(
       new VoidResult() {
         public void run() {
           try {
             PlatformUI.getWorkbench()
                 .getActiveWorkbenchWindow()
                 .getActivePage()
                 .showView(StagingView.VIEW_ID);
           } catch (Exception e) {
             throw new WidgetNotFoundException(e.getMessage(), e);
           }
         }
       });
   SWTBotView view = workbenchBot.viewById(StagingView.VIEW_ID);
   return new StagingViewTester(view);
 }
 @Before
 public void setUp() throws Exception {
   wabot.closeAllShells();
   if (Utility.isProjExist(Messages.projCache)) {
     // delete existing project
     Utility.selProjFromExplorer(Messages.projCache).select();
     Utility.deleteSelectedProject();
   }
 }
Beispiel #22
0
 protected static void waitForShellToDisappear(final String title) {
   try {
     while (bot.shell(title).isActive()) {
       // wait
     }
   } catch (final WidgetNotFoundException e) {
     // Ignore
   }
 }
  private void select(final SWTBotTreeItem entry) {
    if (!bot.tree().isEnabled()) {
      bot.waitUntil(
          new DefaultCondition() {

            public boolean test() throws Exception {
              return bot.tree().isEnabled();
            }

            public String getFailureMessage() {
              return "Entry " + entry + " is not enabled!";
            }
          });
    }
    // JobWatcher watcher = new JobWatcher( BrowserCoreMessages.jobs__init_entries_title_attonly );
    entry.click();
    entry.select();
    // watcher.waitUntilDone();
  }
  /**
   * 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'");
    }
  }
  /**
   * Test refreshing a trace after new content was added.
   *
   * @throws IOException on error
   */
  @Test
  public void testRefresh() throws IOException {
    ITmfTrace activeTrace = TmfTraceManager.getInstance().getActiveTrace();

    fBot.waitUntil(new NumberOfEventsCondition(activeTrace, INITIAL_NB_EVENTS));

    for (int i = 0; i < NB_REFRESH; i++) {
      appendToTrace(NEW_EVENTS_PER_REFRESH);

      // Refresh
      SWTBotTreeItem tracesFolder = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
      SWTBotTreeItem traceItem =
          SWTBotUtils.getTraceProjectItem(fBot, tracesFolder, activeTrace.getName());
      traceItem.contextMenu("Refresh").click();

      // Make sure the refresh is completed
      fBot.waitUntil(new NumberOfEventsCondition(activeTrace, getNbWrittenEvents()));
    }

    // Make sure the end of the table matches what we expect
    goToTableEnd();
    fBot.waitUntil(ConditionHelpers.selectionInEventsTable(fBot, getExpectedEndTimeStamp()));
  }
  /** Import a gzip trace */
  @Test
  public void testGzipImport() {
    final String traceType = "Test trace : TMF Tests";
    final String tracesNode = "Traces [1]";

    /*
     * Actual importing
     */
    openImportWizard();
    selectImportFromArchive(fGzipTrace.getAbsolutePath());
    selectFolder(ROOT_FOLDER);
    SWTBotCheckBox checkBox = fBot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace);
    assertFalse(checkBox.isEnabled());
    SWTBotCombo comboBox = fBot.comboBoxWithLabel(Messages.ImportTraceWizard_TraceType);
    comboBox.setSelection(traceType);
    importFinish();
    /*
     * Remove .gz extension
     */
    assertNotNull(fGzipTrace);
    String name = fGzipTrace.getName();
    assertNotNull(name);
    assertTrue(name.length() > 3);
    String traceName = name.substring(0, name.length() - 3);
    assertNotNull(traceName);
    assertFalse(traceName.isEmpty());

    /*
     * Open trace
     */
    SWTBotView projectExplorer = fBot.viewById(IPageLayout.ID_PROJECT_EXPLORER);
    projectExplorer.setFocus();
    final SWTBotTree tree = projectExplorer.bot().tree();
    /*
     * This appears to be problematic due to the length of the file name and
     * the resolution in our CI.
     */
    tree.expandNode(PROJECT_NAME, true);
    SWTBotTreeItem treeItem = tree.getTreeItem(PROJECT_NAME);
    fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(tracesNode, treeItem));
    treeItem = treeItem.getNode(tracesNode);
    fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(traceName, treeItem));
    treeItem = treeItem.getNode(traceName);
    treeItem.doubleClick();
    SWTBotUtils.waitForJobs();
    /*
     * Check results
     */
    SWTBotTable editor = fBot.activeEditor().bot().table();
    String c22 = editor.cell(2, 2);
    String c10 = editor.cell(1, 0);
    assertEquals("Type-1", c22);
    assertEquals("", c10);
  }
  @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.
  }
  private void openImportWizard() {
    fWizard = new ImportTraceWizard();

    UIThreadRunnable.asyncExec(
        new VoidResult() {
          @Override
          public void run() {
            final IWorkbench workbench = PlatformUI.getWorkbench();
            // Fire the Import Trace Wizard
            if (workbench != null) {
              final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
              Shell shell = activeWorkbenchWindow.getShell();
              assertNotNull(shell);
              ((ImportTraceWizard) fWizard)
                  .init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
              WizardDialog dialog = new WizardDialog(shell, fWizard);
              dialog.open();
            }
          }
        });

    fBot.waitUntil(ConditionHelpers.isWizardReady(fWizard));
  }
Beispiel #29
0
 @AfterClass
 public static void sleep() {
   bot.sleep(2000);
 }
Beispiel #30
0
 protected static SWTBotView getNavigator() {
   final SWTBotView view = bot.viewByTitle("Erlang Navigator");
   return view;
 }