Search in sources :

Example 1 with ICondition

use of org.eclipse.swtbot.swt.finder.waits.ICondition in project eclipse-integration-commons by spring-projects.

the class SWTBotConditions method waitChildNodeToAppear.

public static SWTBotTreeItem waitChildNodeToAppear(SWTBot bot, final SWTBotTreeItem parentNode, final String nodeName) {
    final SWTBotTreeItem[] child = new SWTBotTreeItem[1];
    bot.waitUntil(new ICondition() {

        public boolean test() throws Exception {
            child[0] = parentNode.getNode(nodeName);
            return child[0] != null;
        }

        public void init(SWTBot bot) {
        // 
        }

        public String getFailureMessage() {
            return "Unable to find child node: " + nodeName + " for parent node: " + parentNode.getText();
        }
    }, CHILD_NODE_POPULATE_TIMEOUT);
    return child[0];
}
Also used : SWTBot(org.eclipse.swtbot.swt.finder.SWTBot) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) ICondition(org.eclipse.swtbot.swt.finder.waits.ICondition)

Example 2 with ICondition

use of org.eclipse.swtbot.swt.finder.waits.ICondition in project syncope by apache.

the class SyncopeViewTest method canOpenMailTemplateEditor.

public boolean canOpenMailTemplateEditor() {
    final int initBotEditors = BOT.editors().size();
    SWTBotTreeItem optin = syncopeView.bot().tree().expandNode("Mail Templates").getNode("optin");
    optin.setFocus();
    optin.select().contextMenu("View Template").click();
    // wait for template keys reload
    BOT.waitWhile(new ICondition() {

        @Override
        public boolean test() throws Exception {
            return BOT.editors().size() == initBotEditors;
        }

        @Override
        public void init(final SWTBot bot) {
        }

        @Override
        public String getFailureMessage() {
            return "Unable to Login";
        }
    });
    return !BOT.editors().isEmpty();
}
Also used : SWTBot(org.eclipse.swtbot.swt.finder.SWTBot) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) ICondition(org.eclipse.swtbot.swt.finder.waits.ICondition)

Example 3 with ICondition

use of org.eclipse.swtbot.swt.finder.waits.ICondition in project syncope by apache.

the class SyncopeViewTest method canDeleteReportTemplate.

private boolean canDeleteReportTemplate() {
    SWTBotTreeItem rTemplateHead = syncopeView.bot().tree().getTreeItem("Report Templates");
    if (!rTemplateHead.isExpanded()) {
        rTemplateHead.expand();
    }
    SWTBotTreeItem rNewTemplate = rTemplateHead.getNode("newReportTemplate");
    rNewTemplate.setFocus();
    rNewTemplate.select().contextMenu("Remove template").click();
    BOT.sleep(1000);
    // wait for template keys reload
    BOT.waitWhile(new ICondition() {

        @Override
        public boolean test() throws Exception {
            String title = BOT.activeShell().getText();
            return title.equals("Loading Templates");
        }

        @Override
        public void init(final SWTBot bot) {
        }

        @Override
        public String getFailureMessage() {
            return "Unable to Login";
        }
    });
    // recheck available templates
    rTemplateItem = syncopeView.bot().tree().expandNode("Report Templates");
    rtemplateList = rTemplateItem.getItems();
    return (rtemplateList.length == 2);
}
Also used : SWTBot(org.eclipse.swtbot.swt.finder.SWTBot) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) ICondition(org.eclipse.swtbot.swt.finder.waits.ICondition)

Example 4 with ICondition

use of org.eclipse.swtbot.swt.finder.waits.ICondition in project dsl-devkit by dsldevkit.

the class SwtWorkbenchBot method waitUntilWizardPageAppears.

/**
 * Waits until a wizard page with the given title is visible and active.
 *
 * @param wizardPageTitle
 *          the title of the wizard page
 */
public void waitUntilWizardPageAppears(final String wizardPageTitle) {
    waitUntil(new ICondition() {

        @Override
        @SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation")
        public boolean test() {
            return syncExec(new BoolResult() {

                @Override
                public Boolean run() {
                    SWTBotShell wizardShell = activeShell();
                    if (wizardShell.widget.getData() instanceof WizardDialog) {
                        return ((WizardDialog) wizardShell.widget.getData()).getCurrentPage().getTitle().equals(wizardPageTitle);
                    }
                    return false;
                }
            });
        }

        @Override
        public void init(final SWTBot paramSWTBot) {
        }

        @Override
        public String getFailureMessage() {
            return NLS.bind("Failed to find the wizard page with title ''{0}''.", wizardPageTitle);
        }
    });
    // additionally, we need to wait until the wizard page has finished loading (button cancel is enabled).
    waitUntil(new ICondition() {

        @Override
        @SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation")
        public boolean test() {
            return button("Cancel").isEnabled();
        }

        @Override
        public void init(final SWTBot bot) {
        }

        @Override
        public String getFailureMessage() {
            return NLS.bind("Failed while waiting for the wizard page with title ''{0}''.", wizardPageTitle);
        }
    });
    sleep(DELAY_WIZARD_PAGE);
}
Also used : AbstractSWTBot(org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot) SWTBot(org.eclipse.swtbot.swt.finder.SWTBot) BoolResult(org.eclipse.swtbot.swt.finder.results.BoolResult) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) WizardDialog(org.eclipse.jface.wizard.WizardDialog) ICondition(org.eclipse.swtbot.swt.finder.waits.ICondition)

Example 5 with ICondition

use of org.eclipse.swtbot.swt.finder.waits.ICondition in project epp.mpc by eclipse.

the class AbstractMarketplaceWizardBotTest method closeWizard.

protected void closeWizard() {
    String problem = null;
    List<Exception> exceptions = new ArrayList<Exception>();
    SWTBotShell mpcShell;
    try {
        // check if dialog is still open
        mpcShell = bot.shell("Eclipse Marketplace");
    } catch (TimeoutException e) {
        // no MPC wizard found - maybe a bit strange, but so be it...
        return;
    }
    // check if any message dialogs are open
    boolean dumpedThreads = false;
    try {
        WaitForObjectCondition<Shell> subShellResult = Conditions.waitForShell(Matchers.any(Shell.class), mpcShell.widget);
        bot.waitUntil(subShellResult, 100, 60);
        List<Shell> subShells = subShellResult.getAllMatches();
        for (Shell shell : subShells) {
            if (shell == mpcShell.widget) {
                continue;
            }
            try {
                SWTBotShell botShell = new SWTBotShell(shell);
                // children are unexpected, so let's cry foul...
                if (problem == null) {
                    problem = "MPC wizard has open child dialog:";
                }
                problem += "\n" + describeShell(botShell);
                logger.info(problem);
                problem += "\n" + captureShellScreenshot(botShell);
                // "Wizard can not be closed due to an active operation"
                if (!dumpedThreads) {
                    dumpedThreads = true;
                    dumpThreads();
                }
                // kill message dialog
                botShell.close();
            } catch (Exception ex) {
                exceptions.add(ex);
            }
        }
    } catch (Exception ex) {
        exceptions.add(ex);
    }
    // try killing it softly
    try {
        mpcShell.activate();
        waitForWizardProgress(SWTBotPreferences.TIMEOUT);
        // same as pressing "Cancel" actually
        mpcShell.close();
        ICondition shellCloses = Conditions.shellCloses(mpcShell);
        bot.waitUntil(shellCloses);
        return;
    } catch (Exception ex) {
        exceptions.add(ex);
    }
    // now kill it hard - this is a last resort, because it can cause spurious errors in MPC jobs
    // also dump threads, since this is often caused by the wizard not being cancellable due to a still running operation:
    // "Wizard can not be closed due to an active operation"
    problem += "\nFailed to close wizard regularly. Forcing close.";
    if (!dumpedThreads) {
        dumpedThreads = true;
        dumpThreads();
    }
    try {
        final Shell shell = mpcShell.widget;
        if (!shell.isDisposed()) {
            Display display = shell.getDisplay();
            display.syncExec(new Runnable() {

                @Override
                public void run() {
                    if (!shell.isDisposed()) {
                        shell.dispose();
                    }
                }
            });
        }
    } catch (Exception ex) {
        exceptions.add(ex);
    }
    if (problem != null || !exceptions.isEmpty()) {
        // something happened
        try {
            fail(problem);
        } catch (AssertionError e) {
            for (Exception exception : exceptions) {
                e.addSuppressed(exception);
            }
            throw e;
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WidgetNotFoundException(org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException) TimeoutException(org.eclipse.swtbot.swt.finder.widgets.TimeoutException) AssumptionViolatedException(org.junit.AssumptionViolatedException) ExecutionException(org.eclipse.core.commands.ExecutionException) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) Shell(org.eclipse.swt.widgets.Shell) UIThreadRunnable(org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) ICondition(org.eclipse.swtbot.swt.finder.waits.ICondition) TimeoutException(org.eclipse.swtbot.swt.finder.widgets.TimeoutException) Display(org.eclipse.swt.widgets.Display)

Aggregations

ICondition (org.eclipse.swtbot.swt.finder.waits.ICondition)11 SWTBot (org.eclipse.swtbot.swt.finder.SWTBot)10 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)8 SWTBotShell (org.eclipse.swtbot.swt.finder.widgets.SWTBotShell)6 ArrayList (java.util.ArrayList)2 TimeoutException (org.eclipse.swtbot.swt.finder.widgets.TimeoutException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 CommitOperation (org.eclipse.egit.core.op.CommitOperation)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 Image (org.eclipse.swt.graphics.Image)1 Display (org.eclipse.swt.widgets.Display)1 Shell (org.eclipse.swt.widgets.Shell)1