Forum Discussion

zildarius's avatar
zildarius
Occasional Contributor
14 years ago

SDK problem

Hello.



I have problem with TC SDK. I want to make my own panel, and do something when test engine execution failed.

I don' understand how to work with Notifications Subsystem.

I did following step, but it does not work:


  • Define an interface for your event and inherit it from
    IaqBaseEvent.

  • Create (define, interface and class) a notifier for the event. The notifier
    must implement the interface of the message that this notifier sends. To send
    data to the event manager, the notifier should call the RaiseEvent,
    RaiseEventEx or RaiseVariantEvent method of the
    IaqEventManager object.

  • Create a dispatcher object for the event. This object must implement the
    IaqEventDispatcher interface. This interface contains two
    properties - SyncNotifier and AsyncNotifier - that
    return references to the synchronous and asynchrounous notifier objects, and the
    DispatchEvent method that is used to notify subscribers about an
    event (see sample code below).

  • Register the notifier and dispatcher in the event manager using the
    IaqEventManager.




My code:



unit MyPanel;



interface





uses



  BaseWindowPlugin, PluginBaseExtRegistrator, {$I uses.inc}, {$I usesint.inc};



type



// Notifier

  TSampleEventNotifier = class(TInterfacedObject, IaqKeyItem, IaqBaseEvent, ItcTestEngineEvent)

  private

    FBaseManager: IaqBaseManager;

    FEventManager: IaqEventManager;

    FSynchronized: Boolean;

  protected

    { IaqKeyItem }

    procedure GetKey(out Value: TGUID); stdcall;





    { IaqBaseEvent }

    function  Get_EventInfo: WideString; safecall;





    {ItcTestEngineEvent}

    procedure OnTestEvent(Event: TC_TESTENGINE_EVENT; const Test: ItcTest); safecall;

    procedure OnEngineEvent(Event: TC_TESTENGINE_EVENT); safecall;





  protected

    property BaseManager: IaqBaseManager read FBaseManager;

    property EventManager: IaqEventManager read FEventManager;

    property Synchronized: Boolean read FSynchronized;

  public

    constructor Create(const ABaseManager: IaqBaseManager; ASynchronized: Boolean);

  end;





  // Dispatcher

  TSampleBaseEventDispatcher = class(TInterfacedObject, IaqEventDispatcher)

  private

    FBaseManager: IaqBaseManager;

    FMessenger: IaqMessenger;

  protected

    FSyncNotifier: IaqBaseEvent;

    FAsyncNotifier: IaqBaseEvent;





    { IaqEventDispatcher }

    procedure DispatchEvent(const EventID: TGUID; Data: UINT_PTR; Size: LongWord; const Event: IaqBaseEvent); virtual; safecall;

    function Get_SyncNotifier: IaqBaseEvent; safecall;

    function Get_AsyncNotifier: IaqBaseEvent; safecall;





    property BaseManager: IaqBaseManager read FBaseManager;

    property Messenger: IaqMessenger read FMessenger;

  public

    constructor Create(const ABaseManager: IaqBaseManager);

  end;



implementation





uses



  SysUtils,

  PanelForm, BasePlugin, ActionsConst, Dialogs, classes;



{$R SimplePanelBitmap.res}





{ TSampleEventNotifier }





constructor TSampleEventNotifier.Create(const ABaseManager: IaqBaseManager; ASynchronized: Boolean);



var

    GUID       : TGUID;

    Dispathcer : IaqEventDispatcher;

begin

  inherited Create;

  FBaseManager := ABaseManager;

  FEventManager := FBaseManager.Managers[IaqEventManager] as IaqEventManager;

  Dispathcer := FBaseManager.Managers[IaqEventDispatcher] as IaqEventDispatcher;

  GetKey(GUID);

  FEventManager.AddDispatcher(GUID, Dispathcer);

  FSynchronized := ASynchronized;

end;



function TSampleEventNotifier.Get_EventInfo: WideString;



begin

  Result := '';

end;



procedure TSampleEventNotifier.GetKey(out Value: TGUID);



const

  Key : TGUID = '{25CF0665-B50F-405C-B7F4-4979C7C99A80}';

begin

  Value := Key;

end;



procedure TSampleEventNotifier.OnEngineEvent(Event: TC_TESTENGINE_EVENT); safecall;



var

  Messenger: IaqMessenger;

  List : Tstringlist;

begin



// there I do something. Is it right?







   EventManager.RaiseEvent(ItcTestEngineEvent, Synchronized);

end;



procedure TSampleEventNotifier.OnTestEvent(Event: TC_TESTENGINE_EVENT; const Test: ItcTest);



begin

end;



{ TSampleBaseEventDispatcher }





constructor TSampleBaseEventDispatcher.Create(const ABaseManager: IaqBaseManager);



begin

  FBaseManager := ABaseManager;

  FMessenger := FBaseManager.Managers[IaqMessenger] as IaqMessenger;





  FSyncNotifier := TSampleEventNotifier.Create(ABaseManager, True);

  FAsyncNotifier := TSampleEventNotifier.Create(ABaseManager, False);

end;



procedure TSampleBaseEventDispatcher.DispatchEvent(const EventID: TGUID;



  Data: UINT_PTR; Size: LongWord; const Event: IaqBaseEvent);

begin

  (Event as ItcTestEngineEvent).OnEngineEvent(TC_PLAYING_BEFORE_START);

end;



function TSampleBaseEventDispatcher.Get_AsyncNotifier: IaqBaseEvent;



begin

  Assert(FASyncNotifier <> nil);

  Result := FASyncNotifier;

end;



function TSampleBaseEventDispatcher.Get_SyncNotifier: IaqBaseEvent;



begin

  Assert(FSyncNotifier <> nil);

  Result := FSyncNotifier;

end;

end.






And I have read SDK help.
  • Hi,



    What results do you get when you're using this code? What problems do you face with it on your side? This code is similar to the sample from the "Notifications Subsystem" topic in TC's SDK help, and it should work, so, we need to know what happens on your side.
  • zildarius's avatar
    zildarius
    Occasional Contributor
    Hi!



    It is nothing happens.

    Because when I install plugin in TestComplete, and run some tests - nothing happens.
  • zildarius's avatar
    zildarius
    Occasional Contributor


    procedure TSampleEventNotifier.OnEngineEvent(Event: TC_TESTENGINE_EVENT); safecall;


    var

      Messenger: IaqMessenger;

      List : Tstringlist;

    begin



    ShowMessage('It is work!');




       EventManager.RaiseEvent(ItcTestEngineEvent, Synchronized);

    end;





    When tests run message don't show.

  • Hi,



    OK, in this case, can you send us your plug-in along with the source code? We'll check what's wrong with it.