releng: Add SWTBot integration tests
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ctf / ui / swtbot / tests / SWTBotImportWizardUtils.java
CommitLineData
ab18f69a
MAL
1/******************************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
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
8 *******************************************************************************/
9
10package org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests;
11
12import java.io.File;
cdfe10e7 13import java.util.Arrays;
ab18f69a
MAL
14
15import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
16import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
17import org.eclipse.swtbot.swt.finder.SWTBot;
18import org.eclipse.swtbot.swt.finder.waits.Conditions;
19import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
20import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
21import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
22import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio;
23import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
24import org.eclipse.swtbot.swt.finder.widgets.SWTBotTableItem;
25import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
26import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
27import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
28import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizardPage;
29import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.Messages;
30import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
31import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
32import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
33
34/**
35 * Several SWTBot utility methods common to testing import test cases.
36 */
37public final class SWTBotImportWizardUtils {
38
39 /**
40 * While in the import wizard, select the specified directory as a source.
41 *
42 * @param bot
43 * the SWTBot
44 * @param directoryPath
45 * the directory path to set as a source
46 */
47 public static void selectImportFromDirectory(SWTBot bot, String directoryPath) {
48 SWTBotRadio button = bot.radio("Select roo&t directory:");
49 button.click();
50
51 SWTBotCombo sourceCombo = bot.comboBox();
52 File traceFolderParent = new File(directoryPath);
d2fbf6b6 53 sourceCombo.setFocus();
ab18f69a
MAL
54 sourceCombo.setText(traceFolderParent.getAbsolutePath());
55
d2fbf6b6 56 /* the resource tree gets updated when the combo loses focus */
ab18f69a
MAL
57 SWTBotText text = bot.text();
58 text.setFocus();
59 }
60
61 /**
62 * While in the import wizard, select the specified archive as a source.
63 *
64 * @param bot
65 * the SWTBot
66 * @param archivePath
67 * the archive path to set as a source
68 */
69 public static void selectImportFromArchive(SWTBot bot, String archivePath) {
70 SWTBotRadio button = bot.radio("Select &archive file:");
71 button.click();
72
73 SWTBotCombo sourceCombo = bot.comboBox(1);
74
d2fbf6b6 75 sourceCombo.setFocus();
ab18f69a
MAL
76 sourceCombo.setText(new File(archivePath).getAbsolutePath());
77
d2fbf6b6 78 /* the resource tree gets updated when the combo loses focus */
ab18f69a
MAL
79 SWTBotText text = bot.text();
80 text.setFocus();
81 }
82
cdfe10e7
PT
83 /**
84 * While in the import wizard, select an item in the file selection control.
85 * The item can be a folder in the left tree or a file in the right table.
86 * The item will be checked.
87 *
88 * @param bot
89 * the SWTBot
90 * @param treePath
91 * the path to the item, ending with a file or folder
92 */
93 public static void selectItem(SWTBot bot, String... treePath) {
94 SWTBotTree tree = bot.tree();
95 bot.waitUntil(Conditions.widgetIsEnabled(tree));
96 if (treePath.length == 0) {
97 return;
98 }
99 if (treePath.length == 1) {
100 SWTBotTreeItem rootNode = SWTBotUtils.getTreeItem(bot, tree, treePath);
101 rootNode.select();
102 rootNode.check();
103 return;
104 }
105 String[] parentPath = Arrays.copyOf(treePath, treePath.length - 1);
106 String itemName = treePath[treePath.length - 1];
107 SWTBotTreeItem folderNode = SWTBotUtils.getTreeItem(bot, tree, parentPath);
108 folderNode.expand();
109 if (folderNode.getNodes().contains(itemName)) {
110 folderNode = folderNode.getNode(itemName);
111 folderNode.select();
112 folderNode.check();
113 } else {
114 folderNode.select();
115 SWTBotTable fileTable = bot.table();
116 bot.waitUntil(Conditions.widgetIsEnabled(fileTable));
117 bot.waitUntil(ConditionHelpers.isTableItemAvailable(itemName, fileTable));
118 SWTBotTableItem tableItem = fileTable.getTableItem(itemName);
119 tableItem.check();
120 }
121 }
122
ab18f69a
MAL
123 /**
124 * While in the import wizard, select a folder in the file selection tree.
125 *
126 * @param bot
127 * the SWTBot
128 * @param check
129 * whether or not to check the folder item
130 * @param treePath
131 * the path to the folder in the tree
132 */
133 public static void selectFolder(SWTBot bot, boolean check, String... treePath) {
134 SWTBotTree tree = bot.tree();
135 bot.waitUntil(Conditions.widgetIsEnabled(tree));
136 SWTBotTreeItem folderNode = SWTBotUtils.getTreeItem(bot, tree, treePath);
137 folderNode.select();
138 if (check) {
139 folderNode.check();
140 }
141 }
142
143 /**
144 * While in the import wizard, select a file in the file selection tree.
145 *
146 * @param bot
147 * the SWTBot
148 * @param fileName
149 * the name of the file to select
150 * @param folderTreePath
151 * the path to the parent folder in the tree
152 */
153 public static void selectFile(SWTBot bot, String fileName, String... folderTreePath) {
154 selectFolder(bot, false, folderTreePath);
155
156 SWTBotTable fileTable = bot.table();
157 bot.waitUntil(Conditions.widgetIsEnabled(fileTable));
158 bot.waitUntil(ConditionHelpers.isTableItemAvailable(fileName, fileTable));
159 SWTBotTableItem tableItem = fileTable.getTableItem(fileName);
160 tableItem.check();
161 }
162
163 /**
164 * While in the import wizard, set the various options (checkboxes, trace
165 * type combo).
166 *
167 * @param bot
168 * the SWTBot
169 * @param optionFlags
170 * options that affects mostly checkboxes, see
171 * {@link ImportTraceWizardPage#OPTION_CREATE_LINKS_IN_WORKSPACE}
172 * for example.
173 * @param traceTypeName
174 * the trace type to select in the combobox, or null for
175 * auto-detect.
176 */
177 public static void setOptions(SWTBot bot, int optionFlags, String traceTypeName) {
178 SWTBotCombo comboBox = bot.comboBoxWithLabel(Messages.ImportTraceWizard_TraceType);
179 if (traceTypeName != null && !traceTypeName.isEmpty()) {
180 comboBox.setSelection(traceTypeName);
181 } else {
182 comboBox.setSelection(ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
183 }
184
185 SWTBotCheckBox checkBox = bot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace);
186 if (checkBox.isEnabled()) {
187 if ((optionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0) {
188 checkBox.select();
189 } else {
190 checkBox.deselect();
191 }
192 }
193
194 checkBox = bot.checkBox(Messages.ImportTraceWizard_PreserveFolderStructure);
195 if ((optionFlags & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) {
196 checkBox.select();
197 } else {
198 checkBox.deselect();
199 }
200
201 checkBox = bot.checkBox(Messages.ImportTraceWizard_ImportUnrecognized);
202 if (checkBox.isEnabled()) {
203 if ((optionFlags & ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES) != 0) {
204 checkBox.select();
205 } else {
206 checkBox.deselect();
207 }
208 }
209
210 checkBox = bot.checkBox(Messages.ImportTraceWizard_OverwriteExistingTrace);
211 if ((optionFlags & ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES) != 0) {
212 checkBox.select();
213 } else {
214 checkBox.deselect();
215 }
216
217 checkBox = bot.checkBox(Messages.ImportTraceWizard_CreateExperiment);
218 if ((optionFlags & ImportTraceWizardPage.OPTION_CREATE_EXPERIMENT) != 0) {
219 checkBox.select();
220 } else {
221 checkBox.deselect();
222 }
223 }
224
225 /**
226 * Test that the events editor gets activated and that the first event is
227 * selectable.
228 *
229 * @param bot
230 * the SWTBot
231 * @param editorName
232 * the expected name of the editor
233 * @param nbEvents
234 * the expected number of events
235 * @param firstEventStr
236 * the first event timestamp in string form. This is used to see
237 * if the cell contains this text (String.contains()). Since
238 * there can be timezone issues with hours and days, this value
239 * should only specify minutes and more precise digits. For
240 * example: 04:32.650 993 664
241 */
242 public static void testEventsTable(SWTWorkbenchBot bot, String editorName, long nbEvents, String firstEventStr) {
243 SWTBotEditor editor = SWTBotUtils.activeEventsEditor(bot, editorName);
244 bot.waitUntil(ConditionHelpers.numberOfEventsInTrace(TmfTraceManager.getInstance().getActiveTrace(), nbEvents));
245
246 if (nbEvents == 0 || firstEventStr == null || firstEventStr.isEmpty()) {
247 return;
248 }
249
250 SWTBotTable table = editor.bot().table();
251 bot.waitUntil(new DefaultCondition() {
252 @Override
253 public boolean test() throws Exception {
254 return table.rowCount() > 1;
255 }
256
257 @Override
258 public String getFailureMessage() {
259 return "No items in table";
260 }
261 });
262 // Select first event (skip filter/search row)
263 table.getTableItem(1).select();
264
265 editor.bot().waitUntil(new DefaultCondition() {
266 @Override
267 public boolean test() throws Exception {
268 boolean ret = table.selection().rowCount() == 1 && table.selection().get(0).toString().contains(firstEventStr);
269 if (!ret) {
270 // FIXME: Not sure why, sometimes the first select() ends up
271 // selecting an empty item. Retry selecting here.
272 table.getTableItem(1).select();
273 }
274 return ret;
275 }
276
277 @Override
278 public String getFailureMessage() {
279 return "First event not selected.";
280 }
281 });
282 }
283}
This page took 0.034135 seconds and 5 git commands to generate.