private void executeTestStep(TestStep testStep) { // logger.debug("Executing test step, testStep=" + testStep); WidgetHierarchy widgetHierarchy = new WidgetHierarchy(); widgetHierarchy.getWidgetHierarchy(true); if (!(testStep instanceof MessageBoxTestStep)) { WidgetInfo widgetInfo = testStep.getWidgetInfo(); Object proxy = widgetHierarchy.getWidgetProxy(widgetInfo.getWidgetID()); if (proxy == null) { throw new GenerateTestCasesException("Widget doesn't exist, widgetInfo=" + widgetInfo); } WidgetProxy widgetProxy = (WidgetProxy) proxy; WidgetTester widgetTester = WidgetTesterFactory.getDefault().getTester(widgetProxy); widgetTester.mouseMove(widgetProxy); switch (testStep.getAction()) { case LEFT_MOUSE_CLICK: { widgetTester.actionClick(widgetProxy, SWTProxy.BUTTON1); break; } case RIGHT_MOUSE_CLICK: { widgetTester.actionClick(widgetProxy, SWTProxy.BUTTON3); break; } case ENTER_TEXT: { if (testStep instanceof EnterTextTestStep && widgetProxy instanceof TextProxy) { final TextProxy textProxy = (TextProxy) widgetProxy; widgetTester.actionClick(textProxy); textProxy .getDisplay() .syncExec( new Runnable() { public void run() { textProxy.setText( ""); // Clear the textfield to prevent generation of new strings. } }); EnterTextTestStep enterTextTestStep = (EnterTextTestStep) testStep; widgetTester.actionKeyString(enterTextTestStep.getTextToEnter()); } break; } case SELECT_ITEM: { if (testStep instanceof ComboTestStep && widgetProxy instanceof ComboProxy && widgetTester instanceof ComboTester) { ComboTestStep comboTestStep = (ComboTestStep) testStep; int itemIndex = comboTestStep.getItemIndex(); ComboProxy comboProxy = (ComboProxy) widgetProxy; ComboTester comboTester = (ComboTester) widgetTester; comboTester.actionSelectIndex(comboProxy, itemIndex); } break; } } } else { MessageBoxHelper messageBoxHelper = widgetHierarchy.getMessageBoxHelper(); if (messageBoxHelper == null) { throw new GenerateTestCasesException("MessageBox doesn't exist."); } MessageBoxTestStep messageBoxTestStep = (MessageBoxTestStep) testStep; messageBoxHelper.clickButton(messageBoxTestStep.getButton()); } }
private List<TestStep> generateNextSteps() { List<TestStep> testSteps = new ArrayList<TestStep>(); final WidgetHierarchy widgetHierarchy = new WidgetHierarchy(); widgetHierarchy.getWidgetHierarchy(true); MessageBoxHelper messageBoxHelper = widgetHierarchy.getMessageBoxHelper(); if (messageBoxHelper == null) { WidgetFilterVisitor visitor = new WidgetFilterVisitor(widgetFilterStrategy, widgetHierarchy); widgetHierarchy.accept(visitor); Set<WidgetInfo> filteredSet = visitor.getFilteredSet(); for (WidgetInfo widgetInfo : filteredSet) { Object proxy = widgetHierarchy.getWidgetProxy(widgetInfo.getWidgetID()); if (proxy instanceof MenuItemProxy || proxy instanceof ButtonProxy) { TestStep testStep = new TestStep(TestCaseAction.LEFT_MOUSE_CLICK, widgetInfo); testSteps.add(testStep); } else if (proxy instanceof TextProxy) { TestStep testStep = new EnterTextTestStep(TestCaseAction.ENTER_TEXT, widgetInfo, "Test"); testSteps.add(testStep); } else if (proxy instanceof ComboProxy) { final ComboProxy comboProxy = (ComboProxy) proxy; int itemCount = Displays.syncExec( comboProxy.getDisplay(), new Displays.IntResult() { public int result() { return comboProxy.getItemCount(); } }); for (int i = 0; i < itemCount; ++i) { TestStep testStep = new ComboTestStep(TestCaseAction.SELECT_ITEM, widgetInfo, i); testSteps.add(testStep); } } } } else { if (messageBoxHelper.hasOKButton()) { testSteps.add( new MessageBoxTestStep(TestCaseAction.LEFT_MOUSE_CLICK, MessageBoxHelper.Button.OK)); } if (messageBoxHelper.hasCancelButton()) { testSteps.add( new MessageBoxTestStep( TestCaseAction.LEFT_MOUSE_CLICK, MessageBoxHelper.Button.CANCEL)); } if (messageBoxHelper.hasYesButton()) { testSteps.add( new MessageBoxTestStep(TestCaseAction.LEFT_MOUSE_CLICK, MessageBoxHelper.Button.YES)); } if (messageBoxHelper.hasNoButton()) { testSteps.add( new MessageBoxTestStep(TestCaseAction.LEFT_MOUSE_CLICK, MessageBoxHelper.Button.NO)); } if (messageBoxHelper.hasAbortButton()) { testSteps.add( new MessageBoxTestStep(TestCaseAction.LEFT_MOUSE_CLICK, MessageBoxHelper.Button.ABORT)); } if (messageBoxHelper.hasRetryButton()) { testSteps.add( new MessageBoxTestStep(TestCaseAction.LEFT_MOUSE_CLICK, MessageBoxHelper.Button.RETRY)); } if (messageBoxHelper.hasIgnoreButton()) { testSteps.add( new MessageBoxTestStep( TestCaseAction.LEFT_MOUSE_CLICK, MessageBoxHelper.Button.IGNORE)); } } return testSteps; }