// Copyright Keysight Technologies 2012-2019
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at http://mozilla.org/MPL/2.0/.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Xml.Serialization;
namespace OpenTap
{
public class StepResult
{
public bool PassFail;
public string StringValue;
}
///
/// or . Specifies that a class can be inserted into the test plan hierarchy.
///
public interface ITestStepParent
{
///
/// Parent TestStep for this TestStep. Null if this TestStep is not a child of any other TestSteps.
/// Only guaranteed to be set during .
///
[XmlIgnore]
ITestStepParent Parent { get; set; }
///
/// Gets a list of child TestSteps.
///
[Browsable(false)]
TestStepList ChildTestSteps { get; }
void InsertStep(string name, int index, ITestStep testStep);
void AddStep(string name, ITestStep testStep);
}
///
/// An interface for a . All TestSteps are instances of the ITestStep interface.
///
/// ---------------------------------------------------------------------------------------------------
///
/// The following attributes are mandatory
/// [XmlIgnore]
///
/// ---------------------------------------------------------------------------------------------------
///
/// The following attributes are recommended:
/// [XmlIgnore]
/// [Browsable(false)] [ColumnDisplayName("", Order = -101)]
/// [XmlAttribute("Id")] [Browsable(false)]
/// [Browsable(false)]
/// [Browsable(false)]
/// [XmlIgnore] attribute.
/// [ColumnDisplayName("Step Type", Order = 1)] [Browsable(false)]
/// [Browsable(false)] [ColumnDisplayName(Order = -99)] [XmlIgnore] [Output]
///
[Display("Test Step")]
public interface ITestStep : ITestStepParent, IValidatingObject, ITapPlugin
{
// TODO (breaking): Split ITestStep so the base implementation does not have PrePlanRun and PostPlanRun.
// That way we can quickly see if someone implements those methods without having to do it with reflection.
///
/// Gets or sets the verdict. Only available during run.
/// This property value is propagated to the when the step run completes.
///
[Browsable(false)]
[ColumnDisplayName(Order: -99, IsReadOnly: true)]
[XmlIgnore]
[Output]
Verdict Verdict { get; set; }
///
/// ¸ùPlan,Çø±ðÓÚÔËÐÐʱGetParent(TestPlan)
///
public TestPlan Root { get; set; }
///
/// Name of the step. Should be set by the user if using multiple instances of the same type.
///
[ColumnDisplayName(nameof(Name), Order: -100)]
[Browsable(false)]
string Name { get; set; }
///
/// Gets or sets boolean value that indicates whether this step is enabled in the .
///
[Browsable(false)]
[ColumnDisplayName("", Order: -101)]
bool Enabled { get; set; }
///
/// Gets or sets the current .
///
[Browsable(false)]
TestPlanRun PlanRun { get; set; }
///
/// Gets or sets the currently running and most recently started .
///
[Browsable(false)]
TestStepRun StepRun { get; set; }
///
/// Gets or sets boolean value that indicates whether this step is read only in the .
///
[Browsable(false)]
[XmlIgnore]
bool IsReadOnly { get; set; }
///
/// Name of this type.
///
[ColumnDisplayName("Type", Order: 1)]
[Browsable(false)]
string TypeName { get; }
StepResult Result { get; set; }
///
/// Called by TestPlan.Run() for each step in the test plan prior to calling the TestStepBase.Run() methods of each step.
///
void PrePlanRun();
///
/// Called by TestPlan.Run() to run each TestStep.
/// If this step has children (ChildTestSteps.Count > 0), then these are executed instead.
///
void Run();
///
/// Called by TestPlan.Run() after completing all TestStepBase.Run() methods in the TestPlan
/// Note that TestStep.PostPlan run is run in reverse order
/// For example, if you had three Tests (T1, T2, and T3), and T2 was disabled, then
/// PrePlanRun would run for T1 and T3 (in that order)
/// PostPlanRun would run for T3 and T1 (in that order)
///
void PostPlanRun();
///
/// Unique ID used for storing references to test steps.
///
[XmlAttribute("Id")]
[Browsable(false)]
Guid Id { get; set; }
}
///
/// Search pattern to use while getting child steps.
///
public enum TestStepSearch
{
///
/// All steps are wanted.
///
All,
///
/// Only enabled steps are wanted.
///
EnabledOnly,
///
/// Only disabled steps are wanted.
///
NotEnabledOnly
}
internal static class ITestStepParentExtensions
{
/// Gets the step hierarchy starting from child to parent.
/// Includes the test plan as the last item.
public static IEnumerable GetStepHierarchy(this ITestStepParent step)
{
for (ITestStepParent it = step; it != null; it = it.Parent)
yield return it;
}
public static IEnumerable GetParents(this ITestStepParent step)
=> GetStepHierarchy(step.Parent);
}
}