1 /******************************************************************************
2 * Copyright (c) 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
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.tmf
.ctf
.ui
.swtbot
.tests
;
14 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
15 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotEditor
;
16 import org
.eclipse
.swtbot
.swt
.finder
.SWTBot
;
17 import org
.eclipse
.swtbot
.swt
.finder
.waits
.Conditions
;
18 import org
.eclipse
.swtbot
.swt
.finder
.waits
.DefaultCondition
;
19 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotCheckBox
;
20 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotCombo
;
21 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotRadio
;
22 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTable
;
23 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTableItem
;
24 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotText
;
25 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTree
;
26 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTreeItem
;
27 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
.ImportTraceWizardPage
;
28 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
.Messages
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
30 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
31 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
34 * Several SWTBot utility methods common to testing import test cases.
36 public final class SWTBotImportWizardUtils
{
39 * While in the import wizard, select the specified directory as a source.
43 * @param directoryPath
44 * the directory path to set as a source
46 public static void selectImportFromDirectory(SWTBot bot
, String directoryPath
) {
47 SWTBotRadio button
= bot
.radio("Select roo&t directory:");
50 SWTBotCombo sourceCombo
= bot
.comboBox();
51 File traceFolderParent
= new File(directoryPath
);
52 sourceCombo
.setText(traceFolderParent
.getAbsolutePath());
54 SWTBotText text
= bot
.text();
59 * While in the import wizard, select the specified archive as a source.
64 * the archive path to set as a source
66 public static void selectImportFromArchive(SWTBot bot
, String archivePath
) {
67 SWTBotRadio button
= bot
.radio("Select &archive file:");
70 SWTBotCombo sourceCombo
= bot
.comboBox(1);
72 sourceCombo
.setText(new File(archivePath
).getAbsolutePath());
74 SWTBotText text
= bot
.text();
79 * While in the import wizard, select a folder in the file selection tree.
84 * whether or not to check the folder item
86 * the path to the folder in the tree
88 public static void selectFolder(SWTBot bot
, boolean check
, String
... treePath
) {
89 SWTBotTree tree
= bot
.tree();
90 bot
.waitUntil(Conditions
.widgetIsEnabled(tree
));
91 SWTBotTreeItem folderNode
= SWTBotUtils
.getTreeItem(bot
, tree
, treePath
);
99 * While in the import wizard, select a file in the file selection tree.
104 * the name of the file to select
105 * @param folderTreePath
106 * the path to the parent folder in the tree
108 public static void selectFile(SWTBot bot
, String fileName
, String
... folderTreePath
) {
109 selectFolder(bot
, false, folderTreePath
);
111 SWTBotTable fileTable
= bot
.table();
112 bot
.waitUntil(Conditions
.widgetIsEnabled(fileTable
));
113 bot
.waitUntil(ConditionHelpers
.isTableItemAvailable(fileName
, fileTable
));
114 SWTBotTableItem tableItem
= fileTable
.getTableItem(fileName
);
119 * While in the import wizard, set the various options (checkboxes, trace
125 * options that affects mostly checkboxes, see
126 * {@link ImportTraceWizardPage#OPTION_CREATE_LINKS_IN_WORKSPACE}
128 * @param traceTypeName
129 * the trace type to select in the combobox, or null for
132 public static void setOptions(SWTBot bot
, int optionFlags
, String traceTypeName
) {
133 SWTBotCombo comboBox
= bot
.comboBoxWithLabel(Messages
.ImportTraceWizard_TraceType
);
134 if (traceTypeName
!= null && !traceTypeName
.isEmpty()) {
135 comboBox
.setSelection(traceTypeName
);
137 comboBox
.setSelection(ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
140 SWTBotCheckBox checkBox
= bot
.checkBox(Messages
.ImportTraceWizard_CreateLinksInWorkspace
);
141 if (checkBox
.isEnabled()) {
142 if ((optionFlags
& ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
) != 0) {
149 checkBox
= bot
.checkBox(Messages
.ImportTraceWizard_PreserveFolderStructure
);
150 if ((optionFlags
& ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
) != 0) {
156 checkBox
= bot
.checkBox(Messages
.ImportTraceWizard_ImportUnrecognized
);
157 if (checkBox
.isEnabled()) {
158 if ((optionFlags
& ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
) != 0) {
165 checkBox
= bot
.checkBox(Messages
.ImportTraceWizard_OverwriteExistingTrace
);
166 if ((optionFlags
& ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
) != 0) {
172 checkBox
= bot
.checkBox(Messages
.ImportTraceWizard_CreateExperiment
);
173 if ((optionFlags
& ImportTraceWizardPage
.OPTION_CREATE_EXPERIMENT
) != 0) {
181 * Test that the events editor gets activated and that the first event is
187 * the expected name of the editor
189 * the expected number of events
190 * @param firstEventStr
191 * the first event timestamp in string form. This is used to see
192 * if the cell contains this text (String.contains()). Since
193 * there can be timezone issues with hours and days, this value
194 * should only specify minutes and more precise digits. For
195 * example: 04:32.650 993 664
197 public static void testEventsTable(SWTWorkbenchBot bot
, String editorName
, long nbEvents
, String firstEventStr
) {
198 SWTBotEditor editor
= SWTBotUtils
.activeEventsEditor(bot
, editorName
);
199 bot
.waitUntil(ConditionHelpers
.numberOfEventsInTrace(TmfTraceManager
.getInstance().getActiveTrace(), nbEvents
));
201 if (nbEvents
== 0 || firstEventStr
== null || firstEventStr
.isEmpty()) {
205 SWTBotTable table
= editor
.bot().table();
206 bot
.waitUntil(new DefaultCondition() {
208 public boolean test() throws Exception
{
209 return table
.rowCount() > 1;
213 public String
getFailureMessage() {
214 return "No items in table";
217 // Select first event (skip filter/search row)
218 table
.getTableItem(1).select();
220 editor
.bot().waitUntil(new DefaultCondition() {
222 public boolean test() throws Exception
{
223 boolean ret
= table
.selection().rowCount() == 1 && table
.selection().get(0).toString().contains(firstEventStr
);
225 // FIXME: Not sure why, sometimes the first select() ends up
226 // selecting an empty item. Retry selecting here.
227 table
.getTableItem(1).select();
233 public String
getFailureMessage() {
234 return "First event not selected.";