Extending Resource Class

Helllo,

As I’m going through the documentation of OpenTAP, I understand that the best practice is to let the engine handle open/close resources ( Intruments/Duts/etc). I have a new class which inherits from Resource ( so is not DUT or Instrument), how can I add this to the current session or Testplan resources to be opened closed automatically. The new class overrides Open/Close, and if im calling the methods from a test step it works ok. Thanks

Hi @t_marius,

I believe the resources will get discovered automatically if they are being used in a public property of the test plan.

So if you have a test step setting like:

      public NotDutNotInstrumentResource MyResource {get;set;}

it should be managed by the resource manager and then Open should be called before the test step depending on it is executed (usually when the test plan starts).

1 Like

Tanks @rolf_madsen, that triggers the resource opening.

I just noticed that Im not able to create the new resource object in TestAutomation UI. @rolf_madsen Is there away to create a new tab under bench settings? which would eneble me to add a new resource similar to instrument/DUT? ChatGPT failed to help me create one. Thank you

Hi @t_marius,

You can, it looks like this:

 public interface IMyResource : IResource 
{
}

public class MyResource : Resource, IMyResource
{
}

// this will cause there to be a new list of resources under the "Bench" group of settings.
[SettingsGroup("Bench", Profile: true)]
public class MyResourceListSettings : ComponentSettingsList<MyResourceListSettings, IMyResource>
{
}

I recommend using an interface as the second generic type argument to ComponentSettingsList and let that implement from IResource. Then in your implementation you can inherit from Resource

1 Like

Works perfectly, thank you!

Hello,
I am struggling to replicate the same in Python; anybody has a ready example?

Thanks!

Btw, as a workaround I resorted to define my ComponentSettingsList in a C# file and then use it in Python, but I would still be curious to know if there is an all-python solution for this.