Example #1
0
  /**
   * A helper method to move the execution to another thread
   *
   * @throws ComponentNotFound
   */
  @Deprecated
  private void executeThread() throws ComponentNotFound {

    monitor.setUp();
    log.info("Connecting to application");
    monitor.connectToApplication();

    // Monitor before the test case
    for (GTestMonitor monitor : lTestMonitor) {
      monitor.init();
    }

    log.info("Executing test case");
    log.info("" + tc.getStep().size());

    List<StepType> lSteps = tc.getStep();
    int nStep = lSteps.size();

    for (int i = 0; i < nStep; i++) {
      log.info("---------------------");
      StepType step = lSteps.get(i);
      executeStep(step);
    }
    // Monitor after the test case
    for (GTestMonitor monitor : lTestMonitor) {
      monitor.term();
    }
    monitor.cleanUp();
  }
Example #2
0
  /**
   * Parse and run test case.
   *
   * @throws ComponentNotFound
   */
  public void execute() throws ComponentNotFound {
    //
    try {
      monitor.setUp();

      log.info("Connecting to application...");
      monitor.connectToApplication();

      log.info("Application is connected.");

      // Monitor before the test case
      for (GTestMonitor monitor : lTestMonitor) {
        monitor.init();
      }

      log.info("Executing test case");
      log.info("" + tc.getStep().size());

      List<StepType> lSteps = tc.getStep();
      int nStep = lSteps.size();

      for (int i = 0; i < nStep; i++) {
        log.info("---------------------");
        StepType step = lSteps.get(i);
        executeStep(step);
      }
      // Monitor after the test case
      for (GTestMonitor monitor : lTestMonitor) {
        monitor.term();
      }
      monitor.cleanUp();

    } catch (GException e) {
      // GUITARLog.log.error("GUITAR Exception", e);
      for (GTestMonitor monitor : lTestMonitor) {
        monitor.exceptionHandler(e);
      }
      throw e;
    }
  }
Example #3
0
 /**
  * Add a test monitor
  *
  * <p>
  *
  * @param aTestMonitor
  */
 public void addTestMonitor(GTestMonitor aTestMonitor) {
   aTestMonitor.setReplayer(this);
   this.lTestMonitor.add(aTestMonitor);
 }
Example #4
0
  /**
   * Execute a single step in the test case
   *
   * <p>
   *
   * @param step
   * @throws ComponentNotFound
   */
  private void executeStep(StepType step) throws ComponentNotFound {

    TestStepStartEventArgs stepStartArgs = new TestStepStartEventArgs(step);

    // -----------------------
    // Monitor before step
    for (GTestMonitor aTestMonitor : lTestMonitor) {
      aTestMonitor.beforeStep(stepStartArgs);
    }

    // Events
    String sEventID = step.getEventId();
    GUITARLog.log.info("EventID: " + sEventID);

    // Get widget ID and actions
    // String sWidgetID = getWidgetID("WidgetId", sEventID);
    String sWidgetID = null;
    String sAction = null;

    List<EventType> lEvents = efg.getEvents().getEvent();

    for (EventType event : lEvents) {
      String eventID = event.getEventId();
      if (sEventID.equals(eventID)) {
        sWidgetID = event.getWidgetId();
        sAction = event.getAction();
      }
    }

    if (sWidgetID == null) {
      GUITARLog.log.error("Component ID not found");
      throw new ComponentNotFound();
    } else if (sAction == null) {
      GUITARLog.log.error("Action not found");
      throw new ComponentNotFound();
    }

    String sWindowID = getWindowName(sWidgetID);

    if (sWindowID == null) {
      GUITARLog.log.error("Window Title not found");
      throw new ComponentNotFound();
    }

    GUITARLog.log.info("Window Title: *" + sWindowID + "*");
    GUITARLog.log.info("Widget ID: *" + sWidgetID + "*");
    GUITARLog.log.info("");

    GUITARLog.log.info("Finding window *" + sWindowID + "*....");

    // TODO: Change this method to a fuzzy matching
    GWindow gWindow = monitor.getWindow(sWindowID);
    GUITARLog.log.info("FOUND");
    GUITARLog.log.info("");

    ComponentTypeWrapper comp = guiStructureAdapter.getComponentFromID(sWidgetID);

    if (comp == null) throw new ComponentNotFound();

    List<PropertyType> ID = monitor.selectIDProperties(comp.getDComponentType());
    List<PropertyTypeWrapper> IDAdapter = new ArrayList<PropertyTypeWrapper>();

    for (PropertyType p : ID) IDAdapter.add(new PropertyTypeWrapper(p));

    GComponent containter = gWindow.getContainer();

    GUITARLog.log.info("Finding widget *" + sWidgetID + "*....");

    // GUITARLog.log.debug("Componnent signature: ");
    // for (PropertyTypeWrapper p : IDAdapter) {
    // GUITARLog.log.debug(p.toString());
    // }

    GComponent gComponent = containter.getFirstChild(IDAdapter);

    if (gComponent == null) throw new ComponentNotFound();

    GUITARLog.log.info("FOUND");
    GUITARLog.log.info("Widget Title: *" + gComponent.getTitle() + "*");
    GUITARLog.log.info("");
    if (!gComponent.isEnable()) throw new ComponentDisabled();

    // Actions
    GEvent gEvent = monitor.getAction(sAction);
    List<String> parameters = step.getParameter();

    GUITARLog.log.info("Action: *" + sAction);
    GUITARLog.log.info("");

    // Optional data
    AttributesType optional = comp.getDComponentType().getOptional();
    Hashtable<String, List<String>> optionalValues = null;

    if (optional != null) {

      optionalValues = new Hashtable<String, List<String>>();
      for (PropertyType property : optional.getProperty()) {
        optionalValues.put(property.getName(), property.getValue());
      }
    }

    if (parameters == null) gEvent.perform(gComponent, optionalValues);
    else if (parameters.size() == 0) {
      gEvent.perform(gComponent, optionalValues);
    } else gEvent.perform(gComponent, parameters, optionalValues);

    // -----------------------
    // Monitor after step
    if (!lTestMonitor.isEmpty()) {
      try {
        TestStepEndEventArgs stepEndArgs =
            new TestStepEndEventArgs(
                step, gComponent.extractProperties(), gWindow.extractGUIProperties());
        for (GTestMonitor aTestMonitor : lTestMonitor) {
          aTestMonitor.afterStep(stepEndArgs);
        }
      } catch (Exception e) {
        log.error("Failed to collect post-event state", e);
      }
    }
  }