Search in sources :

Example 1 with TimeoutException

use of org.eclipse.swtbot.swt.finder.widgets.TimeoutException in project linuxtools by eclipse.

the class DisabledPrepareChangelogSWTBotTest method cannotPrepareChangeLogOnNonCVSOrSVNProject.

/**
 * If the project is not shared by any CVS or SVN team provider, "Prepare ChangeLog"
 * should be disabled.
 *
 * @throws Exception
 */
@Test
@Ignore
public void cannotPrepareChangeLogOnNonCVSOrSVNProject() throws Exception {
    assertNull(project.getTestProject().findMember(new Path("/ChangeLog")));
    final String changeLogContent = "2010-12-08  Will Probe  <will@example.com>\n\n" + "\t* path/to/some/non-existing/file.c: New file.\n";
    project.addFileToProject("/", "ChangeLog", new ByteArrayInputStream(changeLogContent.getBytes()));
    assertNotNull(project.getTestProject().findMember(new Path("/ChangeLog")));
    // select ChangeLog file
    String teamProviderString = "n/a";
    SWTBotTreeItem projectItem = ProjectExplorer.expandProject(projectExplorerViewTree, projectName, teamProviderString);
    SWTBotTreeItem changeLogItem = ProjectExplorer.getProjectItem(projectItem, "ChangeLog");
    changeLogItem.select();
    long oldTimeout = SWTBotPreferences.TIMEOUT;
    SWTBotPreferences.TIMEOUT = 100;
    try {
        // Should be disabled (throws exception)
        bot.menu("Prepare ChangeLog").click();
        fail("'Prepare ChangeLog' should be disabled");
    } catch (TimeoutException e) {
        assertTrue(e.getMessage().contains("The widget with mnemonic 'Prepare ChangeLog' was not enabled."));
    }
    SWTBotPreferences.TIMEOUT = oldTimeout;
}
Also used : Path(org.eclipse.core.runtime.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) TimeoutException(org.eclipse.swtbot.swt.finder.widgets.TimeoutException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with TimeoutException

use of org.eclipse.swtbot.swt.finder.widgets.TimeoutException in project dsl-devkit by dsldevkit.

the class CoreSwtbotTools method safeBlockingCollapse.

/**
 * Waits until the node collapses.
 *
 * @param bot
 *          bot to work with, must not be {@code null}
 * @param node
 *          node to wait for, must not be {@code null}
 */
public static void safeBlockingCollapse(final SWTWorkbenchBot bot, final SWTBotTreeItem node) {
    Assert.isNotNull(bot, ARGUMENT_BOT);
    Assert.isNotNull(node, ARGUMENT_NODE);
    if (node.isExpanded()) {
        node.collapse();
        try {
            bot.waitUntil(new DefaultCondition() {

                @Override
                @SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation")
                public boolean test() {
                    return !node.isExpanded();
                }

                @Override
                public String getFailureMessage() {
                    return "Timeout for node to collapse";
                }
            }, TIMEOUT_FOR_NODE_TO_COLLAPSE_EXPAND);
        } catch (TimeoutException e) {
            // Try one last time and do not wait anymore
            node.collapse();
        }
    }
}
Also used : DefaultCondition(org.eclipse.swtbot.swt.finder.waits.DefaultCondition) TimeoutException(org.eclipse.swtbot.swt.finder.widgets.TimeoutException)

Example 3 with TimeoutException

use of org.eclipse.swtbot.swt.finder.widgets.TimeoutException 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)

Example 4 with TimeoutException

use of org.eclipse.swtbot.swt.finder.widgets.TimeoutException in project dsl-devkit by dsldevkit.

the class CoreSwtbotTools method safeBlockingExpand.

/**
 * Waits until the node expands.
 *
 * @param bot
 *          bot to work with, must not be {@code null}
 * @param node
 *          node to wait for, must not be {@code null}
 */
public static void safeBlockingExpand(final SWTWorkbenchBot bot, final SWTBotTreeItem node) {
    Assert.isNotNull(bot, ARGUMENT_BOT);
    Assert.isNotNull(node, ARGUMENT_NODE);
    if (!node.isExpanded()) {
        node.expand();
        try {
            bot.waitUntil(new DefaultCondition() {

                @Override
                @SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation")
                public boolean test() {
                    return node.isExpanded();
                }

                @Override
                public String getFailureMessage() {
                    return "Timeout for node to expand";
                }
            }, TIMEOUT_FOR_NODE_TO_COLLAPSE_EXPAND);
        } catch (TimeoutException e) {
            // Try one last time and do not wait anymore
            node.expand();
        }
    }
}
Also used : DefaultCondition(org.eclipse.swtbot.swt.finder.waits.DefaultCondition) TimeoutException(org.eclipse.swtbot.swt.finder.widgets.TimeoutException)

Example 5 with TimeoutException

use of org.eclipse.swtbot.swt.finder.widgets.TimeoutException in project egit by eclipse.

the class BranchAndResetActionTest method testCheckoutWithNonDeleted.

@Test
public void testCheckoutWithNonDeleted() throws Exception {
    // we need to check if this file system has problems to
    // delete a file with an open FileInputStrem
    IFile test = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1).getFolder(FOLDER).getFile("temp.txt");
    test.create(new ByteArrayInputStream(new byte[0]), false, null);
    File testFile = new File(test.getLocation().toString());
    assertTrue(testFile.exists());
    FileInputStream fis = new FileInputStream(testFile);
    try {
        FileUtils.delete(testFile);
        return;
    } catch (IOException e) {
    // the test makes sense only if deletion of
    // a file with open stream fails
    } finally {
        fis.close();
        if (testFile.exists())
            FileUtils.delete(testFile);
    }
    final Image folderImage = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
    final Image projectImage = PlatformUI.getWorkbench().getSharedImages().getImage(SharedImages.IMG_OBJ_PROJECT);
    // checkout stable
    checkoutAndVerify(new String[] { LOCAL_BRANCHES, "stable" });
    // add a file
    IFile toBeDeleted = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1).getFolder(FOLDER).getFile("ToBeDeleted");
    toBeDeleted.create(new ByteArrayInputStream(new byte[0]), false, null);
    ArrayList<IFile> untracked = new ArrayList<IFile>();
    untracked.add(toBeDeleted);
    // commit to stable
    CommitOperation op = new CommitOperation(new IFile[] { toBeDeleted }, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Add to stable");
    op.execute(null);
    InputStream is = toBeDeleted.getContents();
    try {
        checkout(new String[] { LOCAL_BRANCHES, "master" });
        final SWTBotShell showUndeleted = bot.shell(UIText.NonDeletedFilesDialog_NonDeletedFilesTitle);
        // repo relative path
        assertEquals("ToBeDeleted", showUndeleted.bot().tree().getAllItems()[0].getItems()[0].getItems()[0].getText());
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                assertSame(folderImage, showUndeleted.bot().tree().getAllItems()[0].widget.getImage());
            }
        });
        SWTBotToolbarDropDownButton pathButton = showUndeleted.bot().toolbarDropDownButton();
        pathButton.menuItem(UIText.NonDeletedFilesTree_FileSystemPathsButton).click();
        // see http://www.eclipse.org/forums/index.php/t/159133/ why we need this
        pathButton.pressShortcut(KeyStroke.getInstance("ESC"));
        // fs path
        IPath path = new Path(lookupRepository(repositoryFile).getWorkTree().getPath()).append(PROJ1).append(FOLDER).append("ToBeDeleted");
        SWTBotTreeItem[] items = showUndeleted.bot().tree().getAllItems();
        for (int i = 0; i < path.segmentCount(); i++) {
            boolean found = false;
            String segment = path.segment(i);
            for (SWTBotTreeItem item : items) if (item.getText().equals(segment)) {
                found = true;
                items = item.getItems();
            }
            assertTrue(found);
        }
        pathButton.menuItem(UIText.NonDeletedFilesTree_ResourcePathsButton).click();
        // see http://www.eclipse.org/forums/index.php/t/159133/ why we need this
        pathButton.pressShortcut(KeyStroke.getInstance("ESC"));
        // resource path
        assertEquals("ToBeDeleted", showUndeleted.bot().tree().getAllItems()[0].getItems()[0].getItems()[0].getText());
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                assertSame(projectImage, showUndeleted.bot().tree().getAllItems()[0].widget.getImage());
            }
        });
        ICondition treeEmpty = new ICondition() {

            @Override
            public boolean test() throws Exception {
                return showUndeleted.bot().tree().getAllItems().length == 0;
            }

            @Override
            public void init(SWTBot actBot) {
            // nothing
            }

            @Override
            public String getFailureMessage() {
                return "Not deleted";
            }
        };
        showUndeleted.bot().button(UIText.NonDeletedFilesDialog_RetryDeleteButton).click();
        try {
            showUndeleted.bot().waitUntil(treeEmpty, 1000, 100);
            fail("Should have failed");
        } catch (TimeoutException e) {
        // expected
        }
        is.close();
        showUndeleted.bot().button(UIText.NonDeletedFilesDialog_RetryDeleteButton).click();
        showUndeleted.bot().waitUntil(treeEmpty, 1000, 100);
        showUndeleted.close();
    } finally {
        is.close();
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SWTBot(org.eclipse.swtbot.swt.finder.SWTBot) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) SWTBotToolbarDropDownButton(org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarDropDownButton) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CommitOperation(org.eclipse.egit.core.op.CommitOperation) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) IFile(org.eclipse.core.resources.IFile) File(java.io.File) ICondition(org.eclipse.swtbot.swt.finder.waits.ICondition) TimeoutException(org.eclipse.swtbot.swt.finder.widgets.TimeoutException) Test(org.junit.Test)

Aggregations

TimeoutException (org.eclipse.swtbot.swt.finder.widgets.TimeoutException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 Path (org.eclipse.core.runtime.Path)2 DefaultCondition (org.eclipse.swtbot.swt.finder.waits.DefaultCondition)2 ICondition (org.eclipse.swtbot.swt.finder.waits.ICondition)2 SWTBotShell (org.eclipse.swtbot.swt.finder.widgets.SWTBotShell)2 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)2 Test (org.junit.Test)2 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 CommitOperation (org.eclipse.egit.core.op.CommitOperation)1 Image (org.eclipse.swt.graphics.Image)1 Display (org.eclipse.swt.widgets.Display)1 Shell (org.eclipse.swt.widgets.Shell)1