1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Matthew Khouzam - Initial API and implementation
11 * Alexandre Montplaisir - Replaced separate Condition objects by anonymous classes
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
;
17 import org
.eclipse
.jface
.wizard
.IWizardContainer
;
18 import org
.eclipse
.jface
.wizard
.IWizardPage
;
19 import org
.eclipse
.jface
.wizard
.Wizard
;
20 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
21 import org
.eclipse
.swtbot
.swt
.finder
.SWTBot
;
22 import org
.eclipse
.swtbot
.swt
.finder
.waits
.ICondition
;
23 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTable
;
24 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTree
;
25 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTreeItem
;
28 * Is a tree node available
30 * @author Matthew Khouzam
32 public final class ConditionHelpers
{
34 private ConditionHelpers() {}
37 * Provide default implementations for some {@link ICondition} methods.
39 private abstract static class SWTBotTestCondition
implements ICondition
{
42 public abstract boolean test() throws Exception
;
45 public final void init(SWTBot bot
) {
49 public final String
getFailureMessage() {
55 * Is a tree node available
58 * the name of the node
61 * @return true or false, it should swallow all exceptions
63 public static ICondition
IsTreeNodeAvailable(final String name
, final SWTBotTree tree
) {
64 return new SWTBotTestCondition() {
66 public boolean test() throws Exception
{
68 final SWTBotTreeItem
[] treeItems
= tree
.getAllItems();
69 for (SWTBotTreeItem ti
: treeItems
) {
70 final String text
= ti
.getText();
71 if (text
.equals(name
)) {
75 } catch (Exception e
) {
83 * Is the treeItem's node available
86 * the name of the node
89 * @return true or false, it should swallow all exceptions
91 public static ICondition
IsTreeChildNodeAvailable(final String name
, final SWTBotTreeItem treeItem
) {
92 return new SWTBotTestCondition() {
94 public boolean test() throws Exception
{
96 return treeItem
.getNode(name
) != null;
97 } catch (Exception e
) {
105 * Checks if the wizard's shell is null
109 * @return false if either are null
111 public static ICondition
isWizardReady(final Wizard wizard
) {
112 return new SWTBotTestCondition() {
114 public boolean test() throws Exception
{
115 if (wizard
.getShell() == null) {
124 * Is the wizard on the page you want?
130 * @return true or false
132 public static ICondition
isWizardOnPage(final Wizard wizard
, final IWizardPage page
) {
133 return new SWTBotTestCondition() {
135 public boolean test() throws Exception
{
136 if (wizard
== null || page
== null) {
139 final IWizardContainer container
= wizard
.getContainer();
140 if (container
== null) {
143 IWizardPage currentPage
= container
.getCurrentPage();
144 return page
.equals(currentPage
);
150 * Wait for a view to close
153 * bot view for the view
154 * @return true if the view is closed, false if it's active.
156 public static ICondition
ViewIsClosed(final SWTBotView view
) {
157 return new SWTBotTestCondition() {
159 public boolean test() throws Exception
{
160 return (view
!= null) && (!view
.isActive());
166 * Wait till table cell has a given content.
169 * the table bot reference
171 * the content to check
173 * the row of the cell
175 * the column of the cell
176 * @return ICondition for verification
178 public static ICondition
isTableCellFilled(final SWTBotTable table
,
179 final String content
, final int row
, final int column
) {
180 return new SWTBotTestCondition() {
182 public boolean test() throws Exception
{
184 String cell
= table
.cell(row
, column
);
188 return cell
.endsWith(content
);
189 } catch (Exception e
) {