diff options
| author | Florian Barbin | 2017-06-09 13:27:20 +0000 |
|---|---|---|
| committer | Laurent Redor | 2017-06-17 17:42:43 +0000 |
| commit | a3746657f489fc257a9f614b41ff84c15adca44c (patch) | |
| tree | 8c0c2de0d94f07e0841820ff8dc35e3d1ee6e1aa | |
| parent | 3e5dc691fb3c42e4eaa40b0d24928bb7864d4634 (diff) | |
| download | org.eclipse.sirius-a3746657f489fc257a9f614b41ff84c15adca44c.tar.gz org.eclipse.sirius-a3746657f489fc257a9f614b41ff84c15adca44c.tar.xz org.eclipse.sirius-a3746657f489fc257a9f614b41ff84c15adca44c.zip | |
[479049] Fix ResizeKindEditorTest
Since the commit [1], the FeatureAssistTest has been added before the
ResizeKindEditorTest in the AllTestSuite [2]. Since this time, the
ResizeKindEditorTest fails on Sirius CI server.
After analysis, the ResizeKindEditorTest is not the cause. It is the
code calls to display completion in FeatureAssistTest.
Class SiriusSWTBotTable and SiriusSWTBotTableItem have been copied from
SWTBot repository [3] master branch, on commit [4], to benefit of all
fixes for these classes. These classes must be deleted when the bugzilla
457804 [5] will be OK. They are now used instead of the ones from
current version of SWTBot.
We also use the workaround described in [6] to be sure to have an active
shell during ResizeKindEditorTest.
This commit also improves ContentAssistTest that fails on some PC.
[1]
http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=02f266cd9d0d5b83346755a8edc72f66a5ff8514
[2]
http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/diff/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java?id=02f266cd9d0d5b83346755a8edc72f66a5ff8514
[3] http://git.eclipse.org/c/swtbot/org.eclipse.swtbot.git/
[4]
http://git.eclipse.org/c/swtbot/org.eclipse.swtbot.git/commit/?id=5d7ffcc5be09ba79a3ab78063b33550d655b6a9a
[5] https://bugs.eclipse.org/bugs/show_bug.cgi?id=457804
[6]
https://wiki.eclipse.org/SWTBot/Troubleshooting#No_active_Shell_when_running_SWTBot_tests_in_Xvfb
Bug: 479049
Change-Id: I5baff86f47fec68f4507521c8290b890d1ed26fb
Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
7 files changed, 1205 insertions, 27 deletions
diff --git a/plugins/org.eclipse.sirius.tests.swtbot.support/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.tests.swtbot.support/META-INF/MANIFEST.MF index 137581e839..42e4c390f8 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot.support/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.sirius.tests.swtbot.support/META-INF/MANIFEST.MF @@ -62,7 +62,8 @@ Export-Package: org.eclipse.sirius.tests.swtbot.support.api; org.eclipse.sirius.tests.swtbot.support.utils.business;version="3.0.0", org.eclipse.sirius.tests.swtbot.support.utils.dnd;version="3.0.0", org.eclipse.sirius.tests.swtbot.support.utils.menu;version="3.0.0", - org.eclipse.sirius.tests.swtbot.support.utils.tree;version="3.1.0" + org.eclipse.sirius.tests.swtbot.support.utils.tree;version="3.1.0", + org.eclipse.swtbot.swt.finder.widgets;version="5.0.1" Bundle-Vendor: %providerName Import-Package: org.eclipse.gmf.runtime.diagram.ui.actions.internal.l10n, org.eclipse.sirius.ext.base;version="2.0.0", diff --git a/plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/swtbot/swt/finder/widgets/SiriusSWTBotTable.java b/plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/swtbot/swt/finder/widgets/SiriusSWTBotTable.java new file mode 100644 index 0000000000..adce779aca --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/swtbot/swt/finder/widgets/SiriusSWTBotTable.java @@ -0,0 +1,710 @@ +/******************************************************************************* + * Copyright (c) 2008, 2017 Ketan Padegaonkar and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ketan Padegaonkar - initial API and implementation + * Cédric Chabanois - http://swtbot.org/bugzilla/show_bug.cgi?id=16 + * Hans Schwaebli - http://swtbot.org/bugzilla/show_bug.cgi?id=100 + * http://www.inria.fr/ - http://swtbot.org/bugzilla/show_bug.cgi?id=114 + * Hans Schwaebli - http://swtbot.org/bugzilla/show_bug.cgi?id=122 + * Kristine Jetzke - Bug 259908 + * Aparna Argade - Bug 508710 + * Kunal Tayal - Bug 516098 + *******************************************************************************/ +package org.eclipse.swtbot.swt.finder.widgets; + +//CHECKSTYLE:OFF +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swtbot.swt.finder.ReferenceBy; +import org.eclipse.swtbot.swt.finder.SWTBot; +import org.eclipse.swtbot.swt.finder.SWTBotWidget; +import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; +import org.eclipse.swtbot.swt.finder.results.ArrayResult; +import org.eclipse.swtbot.swt.finder.results.IntResult; +import org.eclipse.swtbot.swt.finder.results.ListResult; +import org.eclipse.swtbot.swt.finder.results.Result; +import org.eclipse.swtbot.swt.finder.results.StringResult; +import org.eclipse.swtbot.swt.finder.results.VoidResult; +import org.eclipse.swtbot.swt.finder.results.WidgetResult; +import org.eclipse.swtbot.swt.finder.utils.MessageFormat; +import org.eclipse.swtbot.swt.finder.utils.TableCollection; +import org.eclipse.swtbot.swt.finder.utils.TableRow; +import org.eclipse.swtbot.swt.finder.utils.internal.Assert; +import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; +import org.hamcrest.SelfDescribing; + +/** + * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> + * @version $Id$ + */ +@SWTBotWidget(clasz = Table.class, preferredName = "table", referenceBy = { ReferenceBy.LABEL }) +public class SiriusSWTBotTable extends AbstractSWTBotControl<Table> { + + /** The last selected item */ + private TableItem lastSelectionItem; + + /** + * Constructs a new instance of this object. + * + * @param table the widget. + * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed. + */ + public SiriusSWTBotTable(Table table) throws WidgetNotFoundException { + this(table, null); + } + + /** + * Constructs a new instance of this object. + * + * @param table the widget. + * @param description the description of the widget, this will be reported by {@link #toString()} + * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed. + */ + public SiriusSWTBotTable(Table table, SelfDescribing description) throws WidgetNotFoundException { + super(table, description); + } + + /** + * Gets the row count. + * + * @return the number of rows in the table + */ + public int rowCount() { + return syncExec(new IntResult() { + @Override + public Integer run() { + return widget.getItemCount(); + } + }); + } + + /** + * Gets the column count. + * + * @return the number of columns in the table + */ + public int columnCount() { + return syncExec(new IntResult() { + @Override + public Integer run() { + return widget.getColumnCount(); + } + }); + } + + /** + * Gets the columns in this table. + * + * @return the list of columns in the table. + */ + public List<String> columns() { + return syncExec(new ListResult<String>() { + @Override + public List<String> run() { + ArrayList<String> result = new ArrayList<String>(); + + TableColumn[] columns = widget.getColumns(); + + for (int i : widget.getColumnOrder()) { + result.add(columns[i].getText()); + } + + return result; + } + }); + } + + /** + * @param column the text on the column. + * @return the index of the specified column. + * @since 1.3 + */ + public int indexOfColumn(String column) { + return columns().indexOf(column); + } + + /** + * Gets the column matching the given label. + * + * @param label the header text. + * @return the header of the table. + * @throws WidgetNotFoundException if the header is not found. + */ + public SWTBotTableColumn header(final String label) throws WidgetNotFoundException { + TableColumn column = syncExec(new Result<TableColumn>() { + @Override + public TableColumn run() { + TableColumn[] columns = widget.getColumns(); + for (TableColumn column : columns) { + if (column.getText().equals(label)) + return column; + } + return null; + } + }); + return new SWTBotTableColumn(column, widget); + } + + /** + * Gets the cell data for the given row/column index. + * + * @param row the row in the table. + * @param column the column in the table. + * @return the cell at the location specified by the row and column + */ + public String cell(final int row, final int column) { + assertIsLegalCell(row, column); + + return syncExec(new StringResult() { + @Override + public String run() { + TableItem item = widget.getItem(row); + return item.getText(column); + } + }); + } + + /** + * Gets the cell data for the given row and column label. + * + * @param row the row in the table + * @param columnName the column title. + * @return the cell in the table at the specified row and columnheader + */ + public String cell(int row, String columnName) { + Assert.isLegal(columns().contains(columnName), "The column `" + columnName + "' is not found."); //$NON-NLS-1$ //$NON-NLS-2$ + List<String> columns = columns(); + int columnIndex = columns.indexOf(columnName); + if (columnIndex == -1) + return ""; //$NON-NLS-1$ + return cell(row, columnIndex); + } + + /** + * Gets the selected item count. + * + * @return the number of selected items. + */ + public int selectionCount() { + return syncExec(new IntResult() { + @Override + public Integer run() { + return widget.getSelectionCount(); + } + }); + } + + /** + * Gets the selected items. + * + * @return the selection in the table + */ + public TableCollection selection() { + final int columnCount = columnCount(); + return syncExec(new Result<TableCollection>() { + @Override + public TableCollection run() { + final TableCollection selection = new TableCollection(); + TableItem[] items = widget.getSelection(); + for (TableItem item : items) { + TableRow tableRow = new TableRow(); + for (int j = 0; j < columnCount; j++) + tableRow.add(item.getText(j)); + selection.add(tableRow); + } + return selection; + } + }); + } + + private void assertIsLegalRowIndex(final int rowIndex) { + Assert.isLegal(rowIndex < rowCount(), "The row number: " + rowIndex + " does not exist in the table"); //$NON-NLS-1$ //$NON-NLS-2$ + } + + /** + * Sets the selection to the given items. Replaces the current selection. If + * there is more than one item to select, the table must have the SWT.MULTI + * style. + * + * @param items + * the items to select in the table. + * @since 1.0 + */ + public void select(final String... items) { + waitForEnabled(); + setFocus(); + int[] itemIndicies = new int[items.length]; + for(int i = 0; i < items.length; i++) { + itemIndicies[i] = indexOf(items[i]); + Assert.isLegal(itemIndicies[i] >= 0, "Could not find item:" + items[i] + " in table"); //$NON-NLS-1$ //$NON-NLS-2$ + } + select(itemIndicies); + } + + /** + * Gets the index of the item matching the given item. Only the first column is searched. + * + * @param item the item in the table. + * @return the index of the specified item in the table, or -1 if the item does not exist in the table. + * @since 1.0 + */ + public int indexOf(final String item) { + return syncExec(new IntResult() { + @Override + public Integer run() { + TableItem[] items = widget.getItems(); + for (int i = 0; i < items.length; i++) { + TableItem tableItem = items[i]; + if (tableItem.getText().equals(item)) + return i; + } + return -1; + } + }); + } + + /** + * Returns true if the table contains the given item. Only the first column + * is searched. + * + * @param item + * the item in the table. + * @return <code>true</code> if the table contains the specified item, + * <code>false</code> otherwise. Only the first column is searched. + */ + public boolean containsItem(final String item) { + return indexOf(item) != -1; + } + + /** + * Gets the row index of the item matching the first occurrence of given + * text in any column of the table. + * + * @param text + * the text in the table. + * @return the row index of the item in the table, or -1 if the text does + * not exist in the table. + * @since 2.6 + */ + public int searchText(final String text) { + final int columnCount = columnCount(); + return syncExec(new IntResult() { + @Override + public Integer run() { + TableItem[] items = widget.getItems(); + for (int i = 0; i < items.length; i++) { + TableItem tableItem = items[i]; + for (int column = 0; column < columnCount; column++) { + if (tableItem.getText(column).equals(text)) + return i; + } + } + return -1; + } + }); + } + + /** + * Returns true if the table contains an item with the given text in any column. + * + * @param text + * the text to be searched in the table. + * @return <code>true</code> if the table contains an item with the given + * text in any column, <code>false</code> otherwise. + * @since 2.6 + */ + public boolean containsText(final String text) { + return searchText(text) != -1; + } + + /** + * Gets the index of the item matching the given text in the given column. + * + * @param text the text in the table. + * @param column the column for which to get the index of. + * @return the index of the item matching the given text in the given column. + * @since 1.3 + */ + public int indexOf(final String text, final int column) { + return syncExec(new IntResult() { + @Override + public Integer run() { + TableItem[] items = widget.getItems(); + for (int i = 0; i < items.length; i++) { + TableItem tableItem = items[i]; + if (tableItem.getText(column).equals(text)) + return i; + } + return -1; + } + }); + } + + /** + * Gets the index of the item matching the given text in the given column. + * + * @param item the index of the item in the table, or -1 if the item does not exist in the table. + * @param column the column for which to get the index of. + * @return the index of the specified item and of the specified column in the table. + * @since 1.3 + */ + public int indexOf(final String text, final String column) { + return indexOf(text, indexOfColumn(column)); + } + + /** + * Unselect all selections. + */ + public void unselect() { + waitForEnabled(); + setFocus(); + log.debug(MessageFormat.format("Unselecting all in {0}", this)); //$NON-NLS-1$ + TableItem[] selection = syncExec(new ArrayResult<TableItem>() { + @Override + public TableItem[] run() { + return widget.getSelection(); + } + }); + for (TableItem item : selection) { + unselect(item); + notifySelect(true); + } + } + + /** + * Unselects the given table item. + * + * @param item + * table item to unselect + */ + private void unselect(final TableItem item) { + syncExec(new VoidResult() { + @Override + public void run() { + widget.deselect(widget.indexOf(item)); + lastSelectionItem = item; + } + }); + } + + /** + * Selects the given index items. Replaces the current selection. If there + * is more than one item to select, the table must have the SWT.MULTI style. + * + * @param indices + * the row indices to select in the table. + */ + public void select(final int... indices) { + waitForEnabled(); + if (indices.length > 1) { + assertMultiSelect(); + } else if (indices.length == 0) { + unselect(); + return; + } + setFocus(); + log.debug(MessageFormat.format("Selecting rows {0} in {1}", Arrays.toString(indices), this)); //$NON-NLS-1$ //$NON-NLS-2$ + for (int i = 0; i < indices.length; i++) { + assertIsLegalRowIndex(indices[i]); + } + final List<TableItem> selection = new ArrayList<TableItem>(); + for (int index : indices) { + selection.add(getItem(index)); + } + for (int i = 0; i < selection.size(); i++) { + boolean add = (i != 0); + processSelection(selection.get(i), add); + notifySelect(add); + } + } + + private void assertMultiSelect() { + Assert.isLegal(hasStyle(widget, SWT.MULTI), "Table does not support multi selection."); //$NON-NLS-1$ + } + + /** + * Selects a table item + * + * @param item + * the table item to select + * @param add + * true to add to current selection + */ + private void processSelection(final TableItem item, final boolean add) { + syncExec(new VoidResult() { + @Override + public void run() { + if (add) { + widget.select(widget.indexOf(item)); + } else { + // removes earlier selection + widget.setSelection(item); + } + lastSelectionItem = item; + } + }); + } + + /** + * Notifies the selection. + */ + protected void notifySelect() { + notifySelect(false); + } + + /** + * Notifies the selection. + * + * @param ctrl + * true if CTRL key should be pressed while sending the event, + * false otherwise. + * @since 2.6 + */ + private void notifySelect(boolean ctrl) { + int stateMask1 = (ctrl) ? (SWT.NONE | SWT.CTRL) : SWT.NONE; + int stateMask2 = (ctrl) ? (SWT.BUTTON1 | SWT.CTRL) : SWT.BUTTON1; + SiriusSWTBotTableItem item = new SiriusSWTBotTableItem(lastSelectionItem); + notify(SWT.MouseEnter); + notify(SWT.MouseMove); + notify(SWT.Activate); + notify(SWT.FocusIn); + notify(SWT.MouseDown, item.createMouseEvent(1, stateMask1, 1)); + notify(SWT.Selection, item.createSelectionEvent(stateMask2)); + notify(SWT.MouseUp, item.createMouseEvent(1, stateMask2, 1)); + } + + @Override + protected Event createSelectionEvent(int stateMask) { + Event event = super.createSelectionEvent(stateMask); + event.item = lastSelectionItem; + return event; + } + + /** + * Click on the table on given cell. This can be used to activate a cellEditor on a cell. + * + * @param row the row in the table. + * @param column the column in the table. + * @since 1.2 + */ + public void click(final int row, final int column) { + assertIsLegalCell(row, column); + // for some reason, it does not work without setting selection first + setFocus(); + Rectangle cellBounds = syncExec(new Result<Rectangle>() { + @Override + public Rectangle run() { + TableItem item = widget.getItem(row); + Rectangle cellBounds = item.getBounds(column); + widget.setSelection(row); + lastSelectionItem = item; + return cellBounds; + } + }); + clickXY(cellBounds.x + (cellBounds.width / 2), cellBounds.y + (cellBounds.height / 2)); + } + + /** + * Click on the table on given cell. This can be used to activate a cellEditor on a cell. + * + * @param row the row in the table. + * @param column the column in the table. + * @since 1.2 + */ + public void doubleClick(final int row, final int column) { + assertIsLegalCell(row, column); + setFocus(); + Rectangle cellBounds = syncExec(new Result<Rectangle>() { + @Override + public Rectangle run() { + TableItem item = widget.getItem(row); + Rectangle cellBounds = item.getBounds(column); + widget.setSelection(row); + lastSelectionItem = item; + return cellBounds; + } + }); + doubleClickXY(cellBounds.x + (cellBounds.width / 2), cellBounds.y + (cellBounds.height / 2)); + } + + /** + * Asserts that the row and column are legal for this instance of the table. + * + * @param row the row number + * @param column the column number + * @since 1.2 + */ + protected void assertIsLegalCell(final int row, final int column) { + int rowCount = rowCount(); + int columnCount = columnCount(); // 0 if no TableColumn has been created by user + + Assert.isLegal(row < rowCount, "The row number (" + row + ") is more than the number of rows(" + rowCount + ") in the table."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Assert.isLegal((column < columnCount) || ((columnCount == 0) && (column == 0)), "The column number (" + column //$NON-NLS-1$ + + ") is more than the number of column(" + columnCount + ") in the table."); //$NON-NLS-1$ //$NON-NLS-2$ + } + + /** + * Gets the table item matching the given name. + * + * @param itemText the text on the node. + * @return the table item with the specified text. + * @throws WidgetNotFoundException if the node was not found. + * @since 1.3 + */ + public SiriusSWTBotTableItem getTableItem(final String itemText) throws WidgetNotFoundException { + try { + new SWTBot().waitUntil(new DefaultCondition() { + @Override + public String getFailureMessage() { + return "Could not find node with text " + itemText; //$NON-NLS-1$ + } + + @Override + public boolean test() throws Exception { + return getItem(itemText) != null; + } + }); + } catch (TimeoutException e) { + throw new WidgetNotFoundException("Timed out waiting for table item " + itemText, e); //$NON-NLS-1$ + } + return new SiriusSWTBotTableItem(getItem(itemText)); + } + + /** + * Gets the item matching the given name. + * + * @param itemText the text on the node. + * @return the table item with the specified text. + */ + private TableItem getItem(final String itemText) { + return syncExec(new WidgetResult<TableItem>() { + @Override + public TableItem run() { + TableItem[] items = widget.getItems(); + for (int i = 0; i < items.length; i++) { + TableItem item = items[i]; + if (item.getText().equals(itemText)) + return item; + } + return null; + } + }); + } + + /** + * Gets the table item matching the given row number. + * + * @param row the row number. + * @return the table item with the specified row. + * @throws WidgetNotFoundException if the node was not found. + * @since 2.0 + */ + public SiriusSWTBotTableItem getTableItem(final int row) throws WidgetNotFoundException { + try { + new SWTBot().waitUntil(new DefaultCondition() { + @Override + public String getFailureMessage() { + return "Could not find table item for row " + row; //$NON-NLS-1$ + } + + @Override + public boolean test() throws Exception { + return getItem(row) != null; + } + }); + } catch (TimeoutException e) { + throw new WidgetNotFoundException("Timed out waiting for table item in row " + row, e); //$NON-NLS-1$ + } + return new SiriusSWTBotTableItem(getItem(row)); + } + + /** + * Gets the item matching the given row number. + * + * @param row the row number. + * @return the table item with the specified row. + */ + private TableItem getItem(final int row) { + return syncExec(new WidgetResult<TableItem>() { + @Override + public TableItem run() { + return widget.getItem(row); + } + + }); + } + + /** + * Create a mouse event at the center of this widget + * + * @param button + * the mouse button that was clicked. + * @param stateMask + * the state of the keyboard modifier keys. + * @param count + * the number of times the mouse was clicked. + * @return an event that encapsulates {@link #widget} and {@link #display} + * @since 2.6 + */ + protected Event createMouseEvent(int button, int stateMask, int count) { + Rectangle bounds = getBounds(); + int x = bounds.x + (bounds.width / 2); + int y = bounds.y + (bounds.height / 2); + return createMouseEvent(x, y, button, stateMask, count); + } + + protected Rectangle getBounds() { + return syncExec(new Result<Rectangle>() { + @Override + public Rectangle run() { + return widget.getBounds(); + } + }); + } + + /** + * Double-click on the widget at given coordinates + * + * @param x + * the x co-ordinate of the click + * @param y + * the y co-ordinate of the click + * @since 2.0 + */ + @Override + protected void doubleClickXY(int x, int y) { + log.debug(MessageFormat.format("Double-clicking on {0}", widget)); //$NON-NLS-1$ + notify(SWT.MouseEnter); + notify(SWT.MouseMove); + notify(SWT.Activate); + notify(SWT.FocusIn); + notify(SWT.MouseDown, createMouseEvent(x, y, 1, SWT.NONE, 1)); + notify(SWT.Selection, createSelectionEvent(SWT.NONE)); + notify(SWT.MouseUp, createMouseEvent(x, y, 1, SWT.BUTTON1, 1)); + notify(SWT.MouseDown, createMouseEvent(x, y, 1, SWT.NONE, 2)); + notify(SWT.Selection, createSelectionEvent(SWT.NONE)); + notify(SWT.MouseDoubleClick, createMouseEvent(x, y, 1, SWT.NONE, 2)); + notify(SWT.DefaultSelection); + notify(SWT.MouseUp, createMouseEvent(x, y, 1, SWT.BUTTON1, 2)); + notify(SWT.MouseHover); + notify(SWT.MouseMove); + notify(SWT.MouseExit); + notify(SWT.Deactivate); + notify(SWT.FocusOut); + log.debug(MessageFormat.format("Double-clicked on {0}", widget)); //$NON-NLS-1$ + } +} +// CHECKSTYLE:ON diff --git a/plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/swtbot/swt/finder/widgets/SiriusSWTBotTableItem.java b/plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/swtbot/swt/finder/widgets/SiriusSWTBotTableItem.java new file mode 100644 index 0000000000..85187aea36 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/swtbot/swt/finder/widgets/SiriusSWTBotTableItem.java @@ -0,0 +1,432 @@ +/******************************************************************************* + * Copyright (c) 2008, 2017 http://www.inria.fr/ and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * http://www.inria.fr/ - initial API and implementation + * Cédric Chabanois - bug 269164 + * Patrick Tasse - Improve SWTBot menu API and implementation (Bug 479091) + * - Add support for click(int) and doubleClick() + * Aparna Argade(Cadence Design Systems, Inc.) - Bug 496519 + *******************************************************************************/ +package org.eclipse.swtbot.swt.finder.widgets; + +//CHECKSTYLE:OFF +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; +import org.eclipse.swtbot.swt.finder.results.BoolResult; +import org.eclipse.swtbot.swt.finder.results.Result; +import org.eclipse.swtbot.swt.finder.results.StringResult; +import org.eclipse.swtbot.swt.finder.results.VoidResult; +import org.eclipse.swtbot.swt.finder.results.WidgetResult; +import org.eclipse.swtbot.swt.finder.utils.MessageFormat; +import org.eclipse.swtbot.swt.finder.utils.internal.Assert; +import org.hamcrest.SelfDescribing; + +/** + * @author Vincent MAHE <vmahe [at] free [dot]fr> + * @author Cédric Chabanois + * @version $Id$ + * @since 1.3 + */ +public class SiriusSWTBotTableItem extends AbstractSWTBot<TableItem> { + + private Table table; + + /** + * @param tableItem the widget. + * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed. + */ + public SiriusSWTBotTableItem(final TableItem tableItem) throws WidgetNotFoundException { + this(tableItem, null); + } + + /** + * @param tableItem the widget. + * @param description the description of the widget, this will be reported by {@link #toString()} + * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed. + */ + public SiriusSWTBotTableItem(final TableItem tableItem, SelfDescribing description) throws WidgetNotFoundException { + super(tableItem, description); + this.table = syncExec(new WidgetResult<Table>() { + @Override + public Table run() { + return tableItem.getParent(); + } + }); + } + + /** + * Selects the current table item. Replaces the current selection. + * + * @return the current node. + */ + public SiriusSWTBotTableItem select() { + waitForEnabled(); + syncExec(new VoidResult() { + @Override + public void run() { + table.setFocus(); + table.setSelection(widget); + } + }); + notifySelect(); + return this; + } + + /** + * Click on the table at given coordinates + * + * @param x the x co-ordinate of the click + * @param y the y co-ordinate of the click + */ + @Override + protected void clickXY(int x, int y) { + log.debug(MessageFormat.format("Clicking on {0}", this)); //$NON-NLS-1$ + notifyTable(SWT.MouseEnter, createMouseEvent(x, y, 0, SWT.NONE, 0)); + notifyTable(SWT.Activate, super.createEvent()); + syncExec(new VoidResult() { + @Override + public void run() { + if (table.getSelectionCount() != 1 || !table.getSelection()[0].equals(widget)) { + table.setSelection(widget); + } + if (!table.isFocusControl()) { + table.setFocus(); + } + } + }); + notifyTable(SWT.FocusIn, super.createEvent()); + notifyTable(SWT.MouseDown, createMouseEvent(x, y, 1, SWT.NONE, 1)); + notifyTable(SWT.Selection); + notifyTable(SWT.MouseUp, createMouseEvent(x, y, 1, SWT.BUTTON1, 1)); + notifyTable(SWT.MouseExit, createMouseEvent(x, y, 0, SWT.NONE, 0)); + notifyTable(SWT.Deactivate, super.createEvent()); + notifyTable(SWT.FocusOut, super.createEvent()); + log.debug(MessageFormat.format("Clicked on {0}", this)); //$NON-NLS-1$ + } + + private void notifyTable(int eventType, Event event) { + notify(eventType, event, table); + } + + private void notifyTable(int event) { + notifyTable(event, createEvent()); + } + + /** + * Clicks on this node. + * + * @return the current node. + */ + @Override + public SiriusSWTBotTableItem click() { + waitForEnabled(); + Point center = getCenter(getBounds()); + clickXY(center.x, center.y); + return this; + } + + /** + * Clicks on this node at the given column index. + * + * @return the current node. + * @since 2.5 + */ + public SiriusSWTBotTableItem click(final int column) { + waitForEnabled(); + Point center = getCenter(getCellBounds(column)); + clickXY(center.x, center.y); + return this; + } + + /** + * Double clicks on this node. + * + * @return the current node. + * @since 2.5 + */ + public SiriusSWTBotTableItem doubleClick() { + waitForEnabled(); + + log.debug(MessageFormat.format("Double-clicking on {0}", this)); //$NON-NLS-1$ + notifyTable(SWT.MouseEnter, createMouseEvent(0, SWT.NONE, 0)); + notifyTable(SWT.Activate, super.createEvent()); + syncExec(new VoidResult() { + @Override + public void run() { + if (table.getSelectionCount() != 1 || !table.getSelection()[0].equals(widget)) { + table.setSelection(widget); + } + if (!table.isFocusControl()) { + table.setFocus(); + } + } + }); + notifyTable(SWT.FocusIn, super.createEvent()); + notifyTable(SWT.MouseDown, createMouseEvent(1, SWT.NONE, 1)); + notifyTable(SWT.Selection); + notifyTable(SWT.MouseUp, createMouseEvent(1, SWT.BUTTON1, 1)); + notifyTable(SWT.MouseDown, createMouseEvent(1, SWT.NONE, 2)); + notifyTable(SWT.Selection); + notifyTable(SWT.MouseDoubleClick, createMouseEvent(1, SWT.NONE, 2)); + notifyTable(SWT.DefaultSelection); + notifyTable(SWT.MouseUp, createMouseEvent(1, SWT.BUTTON1, 2)); + notifyTable(SWT.MouseExit, createMouseEvent(0, SWT.NONE, 0)); + notifyTable(SWT.Deactivate, super.createEvent()); + notifyTable(SWT.FocusOut, super.createEvent()); + log.debug(MessageFormat.format("Double-clicked on {0}", this)); //$NON-NLS-1$ + return this; + } + + protected Control getDNDControl() { + return table; + } + + protected void dragStart() { + syncExec(new VoidResult() { + @Override + public void run() { + table.setFocus(); + table.setSelection(widget); + } + }); + notifyTable(SWT.Activate); + notifyTable(SWT.FocusIn); + notifyTable(SWT.MouseDown, createMouseEvent(1, SWT.NONE, 1)); + notifyTable(SWT.Selection, createSelectionEvent(SWT.BUTTON1)); + } + + protected Rectangle getBounds() { + return syncExec(new Result<Rectangle>() { + @Override + public Rectangle run() { + return widget.getBounds(); + } + }); + } + + /** + * Get the cell bounds. widget should be enabled before calling this method. + * + * @param column the table column index + * @return the cell bounds + */ + private Rectangle getCellBounds(final int column) { + return syncExec(new Result<Rectangle>() { + @Override + public Rectangle run() { + return widget.getBounds(column); + } + }); + } + + /** + * Get the center of the given rectangle. + * + * @param bounds the rectangle + * @return the center. + */ + private Point getCenter(Rectangle bounds) { + return new Point(bounds.x + (bounds.width / 2), bounds.y + (bounds.height / 2)); + } + + @Override + public String getText() { + return syncExec(new StringResult() { + @Override + public String run() { + return widget.getText(); + } + }); + } + + public String getText(final int index) { + return syncExec(new StringResult() { + @Override + public String run() { + return widget.getText(index); + } + }); + } + + // public SWTBotRootMenu contextMenu() throws WidgetNotFoundException { + // waitForEnabled(); + // select(); + // return contextMenu(table); + // } + + /** + * Toggle the table item. + */ + public void toggleCheck() { + setChecked(!isChecked()); + } + + /** + * Check the table item. + */ + public void check() { + setChecked(true); + } + + /** + * Uncheck the table item. + */ + public void uncheck() { + setChecked(false); + } + + /** + * Gets if the checkbox button is checked. + * + * @return <code>true</code> if the checkbox is checked. Otherwise <code>false</code>. + */ + public boolean isChecked() { + assertIsCheck(); + return syncExec(new BoolResult() { + @Override + public Boolean run() { + return widget.getChecked(); + } + }); + } + + /** + * Gets if the checkbox button is grayed. + * + * @return <code>true</code> if the checkbox is grayed, <code>false</code> otherwise. + */ + public boolean isGrayed() { + assertIsCheck(); + return syncExec(new BoolResult() { + @Override + public Boolean run() { + return widget.getGrayed(); + } + }); + } + + /** + * Creates an event for CheckboxTableItem case. + * + * @return an event that encapsulates {@link #widget} and {@link #display}. + */ + private Event createCheckEvent() { + Event event = createEvent(); + event.detail = SWT.CHECK; + return event; + } + + @Override + protected Event createEvent() { + Event event = super.createEvent(); + event.widget = table; + event.item = widget; + return event; + } + + private void setChecked(final boolean checked) { + waitForEnabled(); + assertIsCheck(); + syncExec(new VoidResult() { + @Override + public void run() { + TableItem item = widget; + log.debug(MessageFormat.format("Setting state to {0} on: {1}", (checked ? "checked" : "unchecked"), item.getText())); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + item.setChecked(checked); + } + }); + notifyCheck(); + } + + private void assertIsCheck() { + Assert.isLegal(hasStyle(table, SWT.CHECK), "The table does not have the style SWT.CHECK"); //$NON-NLS-1$ + } + + /** + * notify listeners about checkbox state change. + * + * @since 1.3 + */ + private void notifyCheck() { + syncExec(new VoidResult() { + @Override + public void run() { + table.notifyListeners(SWT.Selection, createCheckEvent()); + } + }); + } + + private void notifySelect() { + notifyTable(SWT.MouseEnter); + notifyTable(SWT.MouseMove); + notifyTable(SWT.Activate); + notifyTable(SWT.FocusIn); + notifyTable(SWT.MouseDown, createMouseEvent(1, SWT.NONE, 1)); + notifyTable(SWT.Selection, createSelectionEvent(SWT.BUTTON1)); + notifyTable(SWT.MouseUp, createMouseEvent(1, SWT.BUTTON1, 1)); + } + + @Override + protected void waitForEnabled() { + new SiriusSWTBotTable(table).waitForEnabled(); + } + + @Override + protected Event createSelectionEvent(int stateMask) { + Event event = super.createSelectionEvent(stateMask); + event.item = widget; + return event; + } + + @Override + public boolean isEnabled() { + return syncExec(new BoolResult() { + @Override + public Boolean run() { + return table.isEnabled(); + } + }); + } + + @Override + protected Rectangle absoluteLocation() { + return syncExec(new Result<Rectangle>() { + @Override + public Rectangle run() { + return display.map(widget.getParent(), null, widget.getBounds()); + } + }); + } + + /** + * Create a mouse event at the center of this widget + * + * @param button + * the mouse button that was clicked. + * @param stateMask + * the state of the keyboard modifier keys. + * @param count + * the number of times the mouse was clicked. + * @return an event that encapsulates {@link #widget} and {@link #display} + * @since 2.6 + */ + protected Event createMouseEvent(int button, int stateMask, int count) { + Rectangle bounds = getBounds(); + int x = bounds.x + (bounds.width / 2); + int y = bounds.y + (bounds.height / 2); + return createMouseEvent(x, y, button, stateMask, count); + } + +} +// CHECKSTYLE:ON diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/AbstractContentAssistTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/AbstractContentAssistTest.java index d74169cb7e..23e3b5d4da 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/AbstractContentAssistTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/AbstractContentAssistTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2017 THALES GLOBAL SERVICES. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.sirius.tests.swtbot.editor.vsm; +import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.allOf; +import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType; + import java.util.Collection; import java.util.List; @@ -18,6 +21,7 @@ import org.eclipse.jface.bindings.keys.ParseException; import org.eclipse.sirius.tests.swtbot.support.api.AbstractSiriusSwtBotGefTestCase; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableItem; import org.eclipse.swtbot.swt.finder.SWTBot; import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; @@ -27,8 +31,10 @@ import org.eclipse.swtbot.swt.finder.waits.ICondition; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; import org.eclipse.swtbot.swt.finder.widgets.SWTBotText; +import org.eclipse.swtbot.swt.finder.widgets.SiriusSWTBotTable; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.keys.IBindingService; +import org.hamcrest.Matcher; import com.google.common.collect.Lists; @@ -40,8 +46,7 @@ import com.google.common.collect.Lists; public abstract class AbstractContentAssistTest extends AbstractSiriusSwtBotGefTestCase { /** - * Add the content assist proposal on index indexOfContentAssistProposal to - * SWTBotText textToActivateContentAssit. + * Add the content assist proposal on index indexOfContentAssistProposal to SWTBotText textToActivateContentAssit. * * @param text * text of a property section @@ -56,24 +61,18 @@ public abstract class AbstractContentAssistTest extends AbstractSiriusSwtBotGefT setCursorPosition(text, cursorPosition); return UIThreadRunnable.syncExec(new Result<String>() { + @Override public String run() { SWTBotShell contentAssistShell = openContentAssist(text); - SWTBotTable contentAssistTable = contentAssistShell.bot().table(); + + SWTBot swtBot = contentAssistShell.bot(); + Matcher matcher = allOf(widgetOfType(Table.class)); + SiriusSWTBotTable contentAssistTable = new SiriusSWTBotTable((Table) swtBot.widget(matcher, 0), matcher); String contentAssistProposalText = contentAssistTable.getTableItem(indexOfContentAssistProposal).getText(); - // Simulate user selection - // 1. double click + // Simulate user selection by double click contentAssistTable.doubleClick(indexOfContentAssistProposal, 0); - contentAssistTable.select(indexOfContentAssistProposal); - - // 2. event - Event event = new Event(); - event.type = SWT.DefaultSelection; - event.display = contentAssistTable.getTableItem(indexOfContentAssistProposal).display; - event.widget = contentAssistTable.widget; - event.item = contentAssistTable.getTableItem(indexOfContentAssistProposal).widget; - contentAssistTable.widget.notifyListeners(SWT.DefaultSelection, event); return contentAssistProposalText; } @@ -94,6 +93,7 @@ public abstract class AbstractContentAssistTest extends AbstractSiriusSwtBotGefT setCursorPosition(text, cursorPosition); return UIThreadRunnable.syncExec(new Result<Collection<String>>() { + @Override public Collection<String> run() { SWTBotShell contentAssistShell = openContentAssist(text); @@ -117,6 +117,7 @@ public abstract class AbstractContentAssistTest extends AbstractSiriusSwtBotGefT */ private void setCursorPosition(final SWTBotText text, final int cursorPosition) { UIThreadRunnable.syncExec(new VoidResult() { + @Override public void run() { text.widget.setSelection(cursorPosition); } @@ -129,7 +130,7 @@ public abstract class AbstractContentAssistTest extends AbstractSiriusSwtBotGefT private SWTBotShell openContentAssist(final SWTBotText text) { final int shellsNumberBeforeContentAssist = bot.shells().length; - IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class); + IBindingService bindingService = PlatformUI.getWorkbench().getService(IBindingService.class); String binding = bindingService.getActiveBindingsFor("org.eclipse.ui.edit.text.contentAssist.proposals")[0].format(); KeyStroke keyStroke = null; try { @@ -148,14 +149,17 @@ public abstract class AbstractContentAssistTest extends AbstractSiriusSwtBotGefT // Wait the display of the content proposal shell. bot.waitUntil(new ICondition() { + @Override public boolean test() throws Exception { return bot.shells().length == shellsNumberBeforeContentAssist + 1; } + @Override public void init(SWTBot bot) { // Nothing } + @Override public String getFailureMessage() { return "There is not the expected number of shells"; } @@ -163,6 +167,7 @@ public abstract class AbstractContentAssistTest extends AbstractSiriusSwtBotGefT bot.waitUntil(new ICondition() { + @Override public boolean test() throws Exception { int openShells = 0; int visibleShells = 0; @@ -177,10 +182,12 @@ public abstract class AbstractContentAssistTest extends AbstractSiriusSwtBotGefT return openShells >= 2 && visibleShells >= 2; } + @Override public void init(SWTBot bot) { // Nothing } + @Override public String getFailureMessage() { return "There is not the expected number of shells"; } diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/ContentAssistTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/ContentAssistTest.java index 73300d0a2d..f03b60026b 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/ContentAssistTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/ContentAssistTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2017 THALES GLOBAL SERVICES. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,6 +15,7 @@ import org.eclipse.sirius.tests.swtbot.support.api.business.UIDiagramRepresentat import org.eclipse.sirius.tests.swtbot.support.api.editor.SWTBotSiriusDiagramEditor; import org.eclipse.sirius.tests.swtbot.support.api.editor.SWTBotVSMEditor; import org.eclipse.sirius.tests.swtbot.support.api.editor.SWTBotVSMHelper; +import org.eclipse.sirius.tests.swtbot.support.utils.SWTBotUtils; import org.eclipse.sirius.ui.tools.api.views.modelexplorerview.IModelExplorerView; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.swt.finder.SWTBot; @@ -85,18 +86,32 @@ public class ContentAssistTest extends AbstractContentAssistTest { final SWTBotText semanticCandidateExpressionText = propertiesBot.bot().text("feature:eContents"); semanticCandidateExpressionText.setFocus(); semanticCandidateExpressionText.setText("aql:self.aa"); - - // Unfocus the semantic candidate expression and add text to another - // text area + // Ensure that + // org.eclipse.sirius.editor.editorPlugin.SiriusEditor.SiriusEditor().new + // CommandStackListener() {...}.commandStackChanged(EventObject) is + // called before continue + SWTBotUtils.waitAllUiEvents(); + // Unfocus the semantic candidate expression (to validate it) final SWTBotText semanticElementText = propertiesBot.bot().text("EPackage"); semanticElementText.setFocus(); - semanticElementText.setText("EPackage"); + // Ensure that + // org.eclipse.sirius.editor.editorPlugin.SiriusEditor.SiriusEditor().new + // CommandStackListener() {...}.commandStackChanged(EventObject) is + // called before continue + SWTBotUtils.waitAllUiEvents(); // Focus back on the semantic candidate expression and modify its // content semanticCandidateExpressionText.setFocus(); semanticCandidateExpressionText.setText("aql:"); + // Ensure that + // org.eclipse.sirius.editor.editorPlugin.SiriusEditor.SiriusEditor().new + // CommandStackListener() {...}.commandStackChanged(EventObject) is + // called before continue + semanticElementText.setFocus(); + SWTBotUtils.waitAllUiEvents(); + semanticCandidateExpressionText.setFocus(); String initialText = semanticCandidateExpressionText.getText(); // Use of content assist diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/FeatureAssistTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/FeatureAssistTest.java index ac282763c9..e4d622efee 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/FeatureAssistTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/FeatureAssistTest.java @@ -37,8 +37,6 @@ public class FeatureAssistTest extends AbstractContentAssistTest { private static final String COLUMN_MAPPING_NODE = "stubLooseFocus"; - private static final String NODE_NAME = "EPackage"; - private static final String GROUP_NAME = "featureTest"; private static final String TABLE_REPRESENTATION_NAME = "featureTestTable"; @@ -138,8 +136,8 @@ public class FeatureAssistTest extends AbstractContentAssistTest { semanticCandidateExpressionText.setFocus(); semanticCandidateExpressionText.setText(""); - // Unfocus the semantic candidate expression and add text to another - // text area + // Unfocus the semantic candidate expression (to validate it) and + // add text to another text area final SWTBotText semanticElementText = propertiesBot.bot().text("stubLooseFocus"); semanticElementText.setFocus(); semanticElementText.setText(firstTextToSet); @@ -148,6 +146,10 @@ public class FeatureAssistTest extends AbstractContentAssistTest { // content semanticCandidateExpressionText.setFocus(); semanticCandidateExpressionText.setText(""); + // Unfocus the semantic candidate expression (to validate it) and + // focus it again + semanticElementText.setFocus(); + semanticCandidateExpressionText.setFocus(); // Use of content assist selectContentAssistProposal(semanticCandidateExpressionText, 0, 0); diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/ResizeKindEditorTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/ResizeKindEditorTest.java index 84f26055eb..3239ef3522 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/ResizeKindEditorTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/editor/vsm/ResizeKindEditorTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2017 THALES GLOBAL SERVICES. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,8 +15,11 @@ import org.eclipse.sirius.tests.swtbot.support.api.AbstractSiriusSwtBotGefTestCa import org.eclipse.sirius.tests.swtbot.support.api.editor.SWTBotSiriusHelper; import org.eclipse.sirius.tests.swtbot.support.api.editor.SWTBotVSMEditor; import org.eclipse.sirius.tests.swtbot.support.utils.SWTBotUtils; +import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; +import org.eclipse.swtbot.swt.finder.results.VoidResult; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; +import org.eclipse.ui.PlatformUI; /** * Test that the editor contains checkBox for editor and that the semantic model @@ -70,6 +73,14 @@ public class ResizeKindEditorTest extends AbstractSiriusSwtBotGefTestCase { * Horizontally. And that the check modify the model value. */ public void testCheckBoxResizeKind() { + // Use the workaround as described here: + // https://wiki.eclipse.org/SWTBot/Troubleshooting#No_active_Shell_when_running_SWTBot_tests_in_Xvfb + UIThreadRunnable.syncExec(new VoidResult() { + @Override + public void run() { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceActive(); + } + }); // Opened VSM SWTBotVSMEditor odesignEditor = openViewpointSpecificationModel(VSM); // Modify VSM, change resizeKind value. |
