Is Conditional Serialization Possible for Properties inside Test Step?

Hi Team,

Whether a conditional Serialization possible for the properties inside Test Step?

Example:

For CleanUp Test Step I have Property “EnableLogging”, whether I can serialize this property based on a condition on run time.

Note : [XmlIgnore] not run time, so I cannot use that.

 public class CleanUp : TestStep
    {

        [Display(CommonVariableNames.EnableLogging_Main, Groups: new[] { CommonVariableNames.LoggingGroup_Main }, Order: 2)]
        public bool EnableLogging { get; set; }
       

        public bool ShouldSerializeEnableLogging()
        {
            return false;// Condition to be added.
        }

Hi @justin_c_i, something tells me this wouldn’t be a good design, but I could be wrong. And of course, I don’t have all the details.

It seems that even if EnableLogging gets serialized, you can still implement logic to ignore/override the deserialized value in specific cases.

For example, maybe you could serialize ShouldSerializeEnableLogging instead, then your logic can know whether or not it should use EnableLogging, or some other value instead.

1 Like

Hi @david-wsd ,

Actually my problem is, I have a list to serialize, I want to save it in TapPlan based on the selection of the user.
List may be very large and tap plan size is more than 10MB, So I don’t’ want to serialize every time.

Hi @justin_c_i sounds like a very large list… why save it in a TestPlan? That’s not really what they’re meant for. Why not save it in another file, that the TestPlan just references? Create a new step that interfaces into that data file. I doubt the feature you want is available. I agree with @david-wsd that maybe a different design would better suit the situation.

2 Likes

Hi @justin_c_i, ya I’d try to avoid serializing a 10MB list into the test plan if possible, as not to slow down test plan opening/saving. Something like @john.berlien’s file idea sounds good.

If you absolutely must conditionally serialize that list, how about something like this:

private List<string> _myHugeList;

public List<string> MyHugeList
{
    get
    {
        if (EnableListSerialization)
        {
            return _myHugeList;
        }
        else
        {
            return null;
        }
    }
    set
    {
        _myHugeList = value;
    }
}
1 Like

Hi, Thanks @david-wsd , @john.berlien ,
Me too don’t prefer serializing 10 MB data ,so we decide to make it an option leaving for customer decision,
@john.berlien another file is an good option , will check for the possibilities of Manual saving of HugeList.
@david-wsd I was planning to do something like this, But whenever we try to access HugeList (Non-Serilization) in any other parts of Test Steps then we get Null?.

Will try some of these methods Thanks.

@justin_c_i MyHugeList will conditionally be null, but _myHugeList will be filled (assuming you’ve filled it at some point). You can use _myHugeList elsewhere in the step.

1 Like

@david-wsd Thanks for the clarification.
I was expecting readily available methods like ShouldSerilalizeProp ,*Specified Method to work in OpenTap.

Thanks for this method, it is working .

1 Like