19 package org.sleuthkit.autopsy.testing;
21 import java.awt.AWTException;
22 import java.awt.Rectangle;
23 import java.awt.Robot;
24 import java.awt.Toolkit;
25 import java.awt.image.BufferedImage;
27 import java.io.IOException;
28 import java.text.DateFormat;
29 import java.text.SimpleDateFormat;
30 import java.util.ArrayList;
31 import java.util.Date;
32 import java.util.List;
33 import java.util.Random;
34 import java.util.logging.Logger;
35 import java.util.logging.Level;
36 import javax.imageio.ImageIO;
37 import javax.swing.JDialog;
38 import javax.swing.text.JTextComponent;
39 import javax.swing.tree.TreePath;
40 import org.netbeans.jellytools.MainWindowOperator;
41 import org.netbeans.jellytools.NbDialogOperator;
42 import org.netbeans.jellytools.WizardOperator;
43 import org.netbeans.jemmy.JemmyProperties;
44 import org.netbeans.jemmy.Timeout;
45 import org.netbeans.jemmy.TimeoutExpiredException;
46 import org.netbeans.jemmy.Timeouts;
47 import org.netbeans.jemmy.operators.JButtonOperator;
48 import org.netbeans.jemmy.operators.JCheckBoxOperator;
49 import org.netbeans.jemmy.operators.JComboBoxOperator;
50 import org.netbeans.jemmy.operators.JDialogOperator;
51 import org.netbeans.jemmy.operators.JFileChooserOperator;
52 import org.netbeans.jemmy.operators.JLabelOperator;
53 import org.netbeans.jemmy.operators.JListOperator;
54 import org.netbeans.jemmy.operators.JTabbedPaneOperator;
55 import org.netbeans.jemmy.operators.JTableOperator;
56 import org.netbeans.jemmy.operators.JTextFieldOperator;
57 import org.netbeans.jemmy.operators.JToggleButtonOperator;
58 import org.netbeans.jemmy.operators.JTreeOperator;
59 import org.netbeans.jemmy.operators.JTreeOperator.NoSuchPathException;
80 if (path.startsWith(
"\\\\")) {
83 if (path.startsWith(
"\\")) {
101 logger.info(
"New Case");
102 setTimeout(
"WindowWaiter.WaitWindowTimeout", 240000);
103 NbDialogOperator nbdo =
new NbDialogOperator(title);
104 JButtonOperator jbo =
new JButtonOperator(nbdo, 0);
106 }
catch (TimeoutExpiredException ex) {
108 logger.log(Level.SEVERE,
"AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
114 logger.info(
"New Case Wizard");
115 WizardOperator wo =
new WizardOperator(
"New Case Information");
116 JTextFieldOperator jtfo0 =
new JTextFieldOperator(wo, 1);
117 jtfo0.typeText(
"AutopsyTestCase");
118 JTextFieldOperator jtfo1 =
new JTextFieldOperator(wo, 2);
120 wo.btNext().clickMouse();
121 JTextFieldOperator jtfo2 =
new JTextFieldOperator(wo, 0);
122 jtfo2.typeText(
"000");
123 JTextFieldOperator jtfo3 =
new JTextFieldOperator(wo, 1);
124 jtfo3.typeText(
"Examiner 1");
125 start = System.currentTimeMillis();
126 wo.btFinish().clickMouse();
127 }
catch (TimeoutExpiredException ex) {
129 logger.log(Level.SEVERE,
"AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
139 new Timeout(
"pausing", 120000).sleep();
140 logger.info(
"Starting Add Image process");
141 setTimeout(
"WindowWaiter.WaitWindowTimeOut", 240000);
142 WizardOperator wo =
new WizardOperator(
"Add Data Source");
143 while (!wo.btNext().isEnabled()) {
144 new Timeout(
"pausing", 1000).sleep();
147 JToggleButtonOperator jtbo =
new JToggleButtonOperator(wo, 0);
149 wo.btNext().clickMouse();
150 JTextFieldOperator jtfo0 =
new JTextFieldOperator(wo, 0);
152 String imageDir = img_path;
153 ((JTextComponent) jtfo0.getSource()).setText(imageDir);
154 JComboBoxOperator comboBoxOperator =
new JComboBoxOperator(wo, 0);
155 comboBoxOperator.setSelectedItem(
"(GMT-5:00) America/New_York");
156 wo.btNext().clickMouse();
157 }
catch (TimeoutExpiredException ex) {
159 logger.log(Level.SEVERE,
"AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
169 new Timeout(
"pausing", 120000).sleep();
170 logger.info(
"Starting Add Logical Files process");
171 WizardOperator wo =
new WizardOperator(
"Add Data Source");
172 wo.setTimeouts(
setTimeout(
"WindowWaiter.WaitWindowTimeOut", 240000));
173 while (!wo.btNext().isEnabled()) {
174 new Timeout(
"pausing", 1000).sleep();
177 JToggleButtonOperator jtbo =
new JToggleButtonOperator(wo, 2);
179 wo.btNext().clickMouse();
180 JButtonOperator addButtonOperator =
new JButtonOperator(wo,
"Add");
181 addButtonOperator.pushNoBlock();
182 JFileChooserOperator fileChooserOperator =
new JFileChooserOperator();
183 fileChooserOperator.setCurrentDirectory(
new File(
getEscapedPath(System.getProperty(
"img_path"))));
185 fileChooserOperator.goUpLevel();
186 fileChooserOperator.chooseFile(
new File(
getEscapedPath(System.getProperty(
"img_path"))).getName());
187 wo.btNext().clickMouse();
188 }
catch (TimeoutExpiredException ex) {
190 logger.log(Level.SEVERE,
"AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
196 WizardOperator wo =
new WizardOperator(
"Add Data Source");
197 while (!wo.btFinish().isEnabled()) {
198 new Timeout(
"pausing", 1000).sleep();
200 logger.log(Level.INFO,
"Add image took {0}ms", (System.currentTimeMillis() -
start));
201 wo.btFinish().clickMouse();
202 }
catch (TimeoutExpiredException ex) {
204 logger.log(Level.SEVERE,
"AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
214 new Timeout(
"pausing", 10000).sleep();
216 logger.info(
"Looking for hash lookup module in ingest job settings panel");
217 WizardOperator wo =
new WizardOperator(
"Add Data Source");
218 while (!wo.btNext().isEnabled()) {
219 new Timeout(
"pausing", 1000).sleep();
221 JTableOperator jto =
new JTableOperator(wo, 0);
222 int row = jto.findCellRow(
"Hash Lookup", 2, 0);
223 jto.clickOnCell(row, 1);
224 logger.info(
"Selected hash lookup module in ingest job settings panel");
225 JButtonOperator jbo1 =
new JButtonOperator(wo,
"Global Settings");
227 logger.info(
"Pushed Global Settings button for hash lookup module in ingest job settings panel");
228 }
catch (TimeoutExpiredException ex) {
230 logger.log(Level.SEVERE,
"AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
236 logger.info(
"Hash Configure");
237 JDialog hashMainDialog = JDialogOperator.waitJDialog(
"Global Hash Lookup Settings",
false,
false);
238 JDialogOperator hashMainDialogOperator =
new JDialogOperator(hashMainDialog);
239 List<String> databases =
new ArrayList<>();
241 databases.add(
getEscapedPath(System.getProperty(
"known_bad_path")));
242 databases.stream().map((database) -> {
243 JButtonOperator importButtonOperator =
new JButtonOperator(hashMainDialogOperator,
"Import");
244 importButtonOperator.pushNoBlock();
245 JDialog addDatabaseDialog = JDialogOperator.waitJDialog(
"Import Hash Set",
false,
false);
246 JDialogOperator addDatabaseDialogOperator =
new JDialogOperator(addDatabaseDialog);
247 JButtonOperator browseButtonOperator =
new JButtonOperator(addDatabaseDialogOperator,
"Open...", 0);
248 browseButtonOperator.pushNoBlock();
249 JFileChooserOperator fileChooserOperator =
new JFileChooserOperator();
250 fileChooserOperator.chooseFile(database);
251 JButtonOperator okButtonOperator =
new JButtonOperator(addDatabaseDialogOperator,
"OK", 0);
252 return okButtonOperator;
253 }).map((okButtonOperator) -> {
254 okButtonOperator.pushNoBlock();
255 return okButtonOperator;
256 }).forEach((_item) -> {
257 new Timeout(
"pausing", 1000).sleep();
263 new Timeout(
"pausing", 1000).sleep();
265 JButtonOperator jbo4 =
new JButtonOperator(hashMainDialogOperator,
"OK", 0);
267 }
catch (TimeoutExpiredException ex) {
269 logger.log(Level.SEVERE,
"AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
275 logger.info(
"Looking for keyword search module in ingest job settings panel");
276 WizardOperator wo =
new WizardOperator(
"Add Data Source");
277 while (!wo.btNext().isEnabled()) {
278 new Timeout(
"pausing", 1000).sleep();
280 JTableOperator jto =
new JTableOperator(wo, 0);
281 int row = jto.findCellRow(
"Keyword Search", 2, 0);
282 jto.clickOnCell(row, 1);
283 logger.info(
"Selected keyword search module in ingest job settings panel");
284 JButtonOperator jbo1 =
new JButtonOperator(wo,
"Global Settings");
286 logger.info(
"Pushed Global Settings button for keyword search module in ingest job settings panel");
287 }
catch (TimeoutExpiredException ex) {
289 logger.log(Level.SEVERE,
"AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
295 logger.info(
"Search Configure");
296 JDialog jd = JDialogOperator.waitJDialog(
"Global Keyword Search Settings",
false,
false);
297 JDialogOperator jdo =
new JDialogOperator(jd);
298 String words =
getEscapedPath(System.getProperty(
"keyword_path"));
299 JButtonOperator jbo0 =
new JButtonOperator(jdo,
"Import List", 0);
301 JFileChooserOperator jfco0 =
new JFileChooserOperator();
302 jfco0.chooseFile(words);
303 JTableOperator jto =
new JTableOperator(jdo, 0);
304 jto.clickOnCell(0, 0);
305 new Timeout(
"pausing", 1000).sleep();
306 if (Boolean.parseBoolean(System.getProperty(
"mugen_mode"))) {
307 JTabbedPaneOperator jtpo =
new JTabbedPaneOperator(jdo);
308 jtpo.selectPage(
"String Extraction");
309 JCheckBoxOperator jcbo0 =
new JCheckBoxOperator(jtpo,
"Arabic (Arabic)");
311 JCheckBoxOperator jcbo1 =
new JCheckBoxOperator(jtpo,
"Han (Chinese, Japanese, Korean)");
313 new Timeout(
"pausing", 1000).sleep();
315 JButtonOperator jbo2 =
new JButtonOperator(jdo,
"OK", 0);
317 WizardOperator wo =
new WizardOperator(
"Add Data Source");
318 new Timeout(
"pausing", 10000).sleep();
319 wo.btNext().clickMouse();
320 }
catch (TimeoutExpiredException ex) {
322 logger.log(Level.SEVERE,
"AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
328 logger.info(
"Ingest 3");
329 new Timeout(
"pausing", 10000).sleep();
330 long startIngest = System.currentTimeMillis();
333 new Timeout(
"pausing", 1000).sleep();
335 logger.log(Level.INFO,
"Ingest (including enqueue) took {0}ms", (System.currentTimeMillis() - startIngest));
339 Random rand =
new Random();
340 new Timeout(
"pausing", 10000 + (rand.nextInt(15000) + 5000)).sleep();
341 }
catch (TimeoutExpiredException ex) {
343 logger.log(Level.SEVERE,
"AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
350 logger.info(
"Data Sources Node");
351 MainWindowOperator mwo = MainWindowOperator.getDefault();
352 JTreeOperator jto =
new JTreeOperator(mwo,
"Data Sources");
353 String[] nodeNames = {
"Data Sources"};
354 TreePath tp = jto.findPath(nodeNames);
356 }
catch (TimeoutExpiredException ex) {
358 logger.log(Level.SEVERE,
"AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
364 logger.info(
"Generate Report Toolbars");
365 MainWindowOperator mwo = MainWindowOperator.getDefault();
366 JButtonOperator jbo =
new JButtonOperator(mwo,
"Generate Report");
368 }
catch (TimeoutExpiredException ex) {
370 logger.log(Level.SEVERE,
"AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
376 logger.info(
"Generate Report Button");
377 setTimeout(
"ComponentOperator.WaitComponentTimeout", 240000);
378 JDialog reportDialog = JDialogOperator.waitJDialog(
"Generate Report",
false,
false);
379 JDialogOperator reportDialogOperator =
new JDialogOperator(reportDialog);
380 JListOperator listOperator =
new JListOperator(reportDialogOperator);
381 JButtonOperator jbo0 =
new JButtonOperator(reportDialogOperator,
"Next");
382 DateFormat dateFormat =
new SimpleDateFormat(
"MM-dd-yyyy-HH-mm-ss");
383 Date date =
new Date();
384 String datenotime = dateFormat.format(date);
385 listOperator.clickOnItem(0, 1);
387 new Timeout(
"pausing", 2000).sleep();
388 JButtonOperator jbo1 =
new JButtonOperator(reportDialogOperator,
"Finish");
390 JDialog previewDialog = JDialogOperator.waitJDialog(
"Progress",
false,
false);
391 JDialogOperator previewDialogOperator =
new JDialogOperator(previewDialog);
392 JLabelOperator.waitJLabel(previewDialog,
"Complete",
false,
false);
393 JButtonOperator jbo2 =
new JButtonOperator(previewDialogOperator,
"Close");
395 new Timeout(
"pausing", 10000).sleep();
396 System.setProperty(
"ReportStr", datenotime);
397 }
catch (TimeoutExpiredException ex) {
399 logger.log(Level.SEVERE,
"AutopsyTestCases.testNewCaseWizard encountered timed out", ex);
405 File screenShotFile =
new File(outPath +
"\\" + name +
".png");
406 if (!screenShotFile.exists()) {
407 logger.info(
"Taking screenshot.");
409 Rectangle screenRect =
new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
410 BufferedImage capture =
new Robot().createScreenCapture(screenRect);
411 ImageIO.write(capture,
"png", screenShotFile);
412 new Timeout(
"pausing", 1000).sleep();
413 }
catch (IOException ex) {
414 logger.log(Level.WARNING,
"IOException taking screenshot.", ex);
415 }
catch (AWTException ex) {
416 logger.log(Level.WARNING,
"AWTException taking screenshot.", ex);
427 Timeouts timeouts = JemmyProperties.getCurrentTimeouts();
428 timeouts.setTimeout(name, value);
435 CaseDbConnectionInfo connectionInfo =
new CaseDbConnectionInfo(
436 System.getProperty(
"dbHost"),
437 System.getProperty(
"dbPort"),
438 System.getProperty(
"dbUserName"),
439 System.getProperty(
"dbPassword"),
440 TskData.DbType.POSTGRESQL);
444 logger.log(Level.SEVERE,
"Error saving case database connection info", ex);
451 System.getProperty(
"messageServiceHost"),
452 Integer.parseInt(System.getProperty(
"messageServicePort")),
458 logger.log(Level.SEVERE,
"Error saving messaging service connection info", ex);
465 for (TreePath t : jto.getChildPaths(tp)) {
468 }
catch (NoSuchPathException ne) {
469 logger.log(Level.SEVERE,
"Error expanding tree path", ne);
void screenshot(String name)
void testConfigureSearch()
static synchronized IngestManager getInstance()
void testGenerateReportToolbar()
void testStartAddLogicalFilesDataSource()
void testConfigureIngest1()
void testAddSourceWizard1()
boolean isIngestRunning()
static String getEscapedPath(String path)
Timeouts setTimeout(String name, int value)
static void setIsMultiUserModeEnabled(boolean enabled)
static void setMessageServiceConnectionInfo(MessageServiceConnectionInfo info)
void testExpandDataSourcesTree()
void expandNodes(JTreeOperator jto, TreePath tp)
void setMultiUserPerferences()
static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo)
static void setIndexingServerHost(String hostName)
static void setIndexingServerPort(int port)
void testGenerateReportButton()
void testNewCaseWizardOpen(String title)
AutopsyTestCases(boolean isMultiUser)
static final Logger logger
void testStartAddImageFileDataSource()
void testConfigureIngest2()