Hi,
I created a sample plugin to describe the issue.
AddNumbersStep has the embedded properties which is used as Input property in IFConditionStep.
The saved plan when opened does not have the input property selected in the IFConditionStep.
I investigated the tapplan in notepad and it seems to have the propertyname set correctly.
I appreciate your guidance in this. Did I miss any initialization or is this a bug with Embedded Properties?
AddNumberStep.cs
public class AddNumberStep : TestStep
{
#region Settings
// ToDo: Add property here for each parameter the end user should be able to change.
[EmbedProperties]
[Display(Name: “Add Numbers”, Order: 1)]
public MyNumbers Numbers { get; set; }
#endregion
public AddNumberStep()
{
// ToDo: Set default values for properties / settings.
Numbers = new MyNumbers();
}
public override void Run()
{
// ToDo: Add test case code.
Numbers.ResultValue = Numbers.Number1 + Numbers.Number2;
RunChildSteps(); //If the step supports child steps.
// If no verdict is used, the verdict will default to NotSet.
// You can change the verdict using UpgradeVerdict() as shown below.
// UpgradeVerdict(Verdict.Pass);
}
}
IFConditionStep.cs
public class IfCondition : TestStep
{
public enum CompareOperator
{
[Display(“!=”)]
NotEqual = 1,
[Display(“>=”)]
GreaterThanOrEqual = 2,
[Display(“<=”)]
LessThanOrEqual = 3,
[Display(“=”)]
Equal = 4
}
public enum LogicalOperator
{
[Display(“AND”)]
ANDOPER = 1,
[Display(“OR”)]
OROPER = 2
}
#region Settings
// ToDo: Add property here for each parameter the end user should be able to change
[Display(“Parameter Value”, Order: 1)]
// Properties defined using the Input generic class will accept value from other
// test steps with properties that have been marked with the Output attribute.
public Input ParameterValue { get; set; }
[Display("Condition", Group: "Condition 1", Order: 2)]
public CompareOperator SelectedCondition { get; set; }
[Display("User Value", Group: "Condition 1", Order: 3)]
public double UserValue { get; set; }
[Display("Add Condition", Order: 4)]
public bool IsConditionAdded { get; set; }
[Display("AND / OR", Order: 5)]
[EnabledIf("IsConditionAdded", true, HideIfDisabled = true)]
public LogicalOperator AndOrCondition { get; set; }
[Display("Condition", Group: "Condition 2", Order: 6)]
[EnabledIf("IsConditionAdded", true, HideIfDisabled = true)]
public CompareOperator SecondCondition { get; set; }
[Display("User Value", Group: "Condition 2", Order: 7)]
[EnabledIf("IsConditionAdded", true, HideIfDisabled = true)]
public double UserValue2 { get; set; }
[Display("Set Verdict", Group: "Verdict", Order: 8)]
public Verdict SetVerdict { get; set; }
[Display("Verdict if condition not met", Group: "Verdict", Order: 9)]
public Verdict DefaultVerdict { get; set; }
#endregion
public IfCondition()
{
// ToDo: Set default values for properties / settings.
ParameterValue = new Input<double>();
UserValue = 0;
DefaultVerdict = Verdict.NotSet;
Rules.Add(() => ParameterValue.Step != null, "Parameter Value must be selected.", nameof(ParameterValue));
}
public override void Run()
{
ThrowOnValidationError(true);
Log.Info($"Parameter Value: {this.ParameterValue}");
bool conditionResult = GetConditionResult(ParameterValue.Value, SelectedCondition, UserValue);
Log.Debug($"conditionResult: {conditionResult}");
bool finalVerdictResult = conditionResult;
if (IsConditionAdded)
{
bool condition2Result = GetConditionResult(ParameterValue.Value, SecondCondition, UserValue2);
Log.Debug($"Second condition: {condition2Result}");
if (AndOrCondition == LogicalOperator.ANDOPER && (conditionResult && condition2Result))
finalVerdictResult = true;
else if (AndOrCondition == LogicalOperator.OROPER && (conditionResult || condition2Result))
finalVerdictResult = true;
else
finalVerdictResult = false;
}
Log.Debug($"finalVerdictResult: {finalVerdictResult}");
if (finalVerdictResult)
UpgradeVerdict(this.SetVerdict);
else
UpgradeVerdict(DefaultVerdict);
RunChildSteps(); //If the step supports child steps.
}
private bool GetConditionResult(double value, CompareOperator conditionSelected, double userValue)
{
bool result = false;
if (conditionSelected == CompareOperator.Equal && value == userValue)
result = true;
else if (conditionSelected == CompareOperator.NotEqual && value != userValue)
result = true;
else if (conditionSelected == CompareOperator.GreaterThanOrEqual && value >= userValue)
result = true;
else if (conditionSelected == CompareOperator.LessThanOrEqual && value <= userValue)
result = true;
return result;
}
}
MyNumbers.cs
public class MyNumbers
{
[Display(“Number 1”, Order: 1)]
[Output(OutputAvailability.BeforeRun)]
public double Number1 { get; set; }
[Display("Number 2", Order: 2)]
[Output(OutputAvailability.BeforeRun)]
public double Number2 { get; set; }
[Display("Result", Order: 3)]
[Output(OutputAvailability.BeforeRun)]
public double ResultValue { get; set; }
}