private void recordTestOutcomeAsSteps(TestOutcome testOutcome, TestOutcome scenarioOutcome) {
    final String name = alternativeMethodName(testOutcome);
    TestStep nestedStep = TestStep.forStepCalled(name).withResult(testOutcome.getResult());
    List<TestStep> testSteps = testOutcome.getTestSteps();

    if (testOutcome.getTestFailureCause() != null) {
      nestedStep.failedWith(testOutcome.getTestFailureCause().toException());
    }

    if (!testSteps.isEmpty()) {
      for (TestStep nextStep : testSteps) {
        nextStep.setDescription(
            normalizeTestStepDescription(
                nextStep.getDescription(), scenarioOutcome.getTestSteps().size() + 1));
        nestedStep.addChildStep(nextStep);
        nestedStep.setDuration(nextStep.getDuration() + nestedStep.getDuration());
      }
    }

    if (nestedStep.getDuration() == 0) {
      nestedStep.setDuration(testOutcome.getDuration());
    }
    scenarioOutcome.recordStep(nestedStep);
  }
Esempio n. 2
0
  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());
    }
  }