I’m implementing a plugin in Python. I have a base test step class (not available to UI) where I defined some properties. I created a few test steps that inherit from the base test step thus get all the declared properties of the parent one. That works fine.
Now I’d like to make some adjustments to these properties in the __init__()
of child steps, namely add attributes to them, e.g. set some of them to outputs.
Is there a way to access all declared properties of the parent class? I tried using self.GetType().GetProperties()
but it seems it only shows built-in properties. I also checked various other methods and properties of the step but without luck.
1 Like
As an additional note, if I do something like self.prop = self.AddProperty("my_property", True, Boolean)
in the parent step and then do something like self.prop.AddAttribute(OutputAttribute)
it works fine, so my only issue is to extract all the properties from the step in a proper way rather than save them in the class data.
Hi @tatiana.boye,
unfortunately, the current version does not have that possibility. This is because the ‘self’ object is not exactly the same object as what you see in the test plan. The object in the test plan is a kind of a wrapper around your python test step object.
In the next version (Python 3.0), this will be a possibility as the object in the test plan is the same as the python object.
2 Likes
Thanks for the explanation @rolf_madsen. Will stick to the workaround while looking forward to the version 3.0
.
1 Like
@rolf_madsen We’re currently migrating to Python 3 plugin. We’ve been trying to modify properties declared in parent classes but we cannot make it work. Could you give me an example on how it should be done?
Here’s a small excerpt to clarify:
class MyStep(TestStep):
my_prop = property(Double, 0).add_attribute(OpenTap.Display("My Property", "My property description.")
class MyChildStep(MyStep):
# Here I'd like to add another attribute to `my_prop`, e.g. to make to not visible
We still haven’t managed to resolve this issue. Could anyone advise?
Hi @tatiana.boye,
It is not currently possible to change already declared properties, but you could configure it using the EnabledIf attribute to just hide it from view:
@attribute(OpenTap.Display("Hide Example", "...", "Python Example"))
@attribute(OpenTap.AllowAnyChild())
class BaseStep(TestStep):
# Frequency is only shwon if FrequencyShown is True
Frequency = property(Double, 1e9)\
.add_attribute(OpenTap.Unit("Hz"))\
.add_attribute(OpenTap.EnabledIf("FrequencyShown", True, HideIfDisabled=True))\
.add_attribute(OpenTap.Display("Frequency", "The frequency"))
FrequencyShown = property(Boolean, True)#\
#.add_attribute(Browsable(False)) <-- todoÆ make it unbrowsable
def __init__(self):
super().__init__()
@attribute(OpenTap.Display("Hide Derived Example", "...", "Python Example"))
@attribute(OpenTap.AllowAnyChild())
class DerivedStep(BaseStep):
def __init__(self):
super().__init__()
# In the derived step the frequency setting is not shown.
self.FrequencyShown = False
I think that could be worked around relatively easily:
@property(Boolean)
@attribute(Browsable(False))
def FrequencyShown(self):
return self.MyEnumValue == MyEnum.ValueA
Did you try something like that?