From 53e656200368a983e563550e2cc1acbc6d86b729 Mon Sep 17 00:00:00 2001
From: chr <chrry550@outlook.com>
Date: 星期三, 08 四月 2026 19:57:14 +0800
Subject: [PATCH] 完善代码
---
OpenTap/Engine/SerializerPlugins/TestStepListSerializer.cs | 69 ++++++++++++++++++++++++++--------
1 files changed, 53 insertions(+), 16 deletions(-)
diff --git a/OpenTap/Engine/SerializerPlugins/TestStepListSerializer.cs b/OpenTap/Engine/SerializerPlugins/TestStepListSerializer.cs
index b7d886d..d28bef9 100644
--- a/OpenTap/Engine/SerializerPlugins/TestStepListSerializer.cs
+++ b/OpenTap/Engine/SerializerPlugins/TestStepListSerializer.cs
@@ -2,6 +2,7 @@
// 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 OpenTap.Addin;
using System;
using System.Xml.Linq;
@@ -10,7 +11,7 @@
/// <summary> Serializer implementation for TestStepList. </summary>
internal class TestStepListSerializer : TapSerializerPlugin
{
-
+
/// <summary> The order of this serializer. </summary>
public override double Order
@@ -26,33 +27,57 @@
steps.SequenceName = sequenceNameAttr?.Value ?? string.Empty;
foreach (var subnode in elem.Elements())
{
- ITestStep result = null;
- try
+ if (subnode.Name == varName)
{
- if (!Serializer.Deserialize(subnode, x => result = (ITestStep)x))
+ TestVariable v = null;
+ try
{
- Serializer.PushError(subnode, "Unable to deserialize test step.");
- continue; // skip to next step.
+ if (!Serializer.Deserialize(subnode, x => v = (TestVariable)x))
+ {
+ Serializer.PushError(subnode, "Unable to deserialize test step.");
+ continue; // skip to next step.
+ }
}
- }
- catch(Exception ex)
- {
- Serializer.PushError(subnode, "Unable to deserialize test step.", ex);
- continue;
- }
+ catch (Exception ex)
+ {
+ Serializer.PushError(subnode, "Unable to deserialize test step.", ex);
+ continue;
+ }
- if (result != null)
- steps.Add(result);
+ if (v != null)
+ steps.Variables.Add(v);
+ }
+ else
+ {
+ ITestStep result = null;
+ try
+ {
+ if (!Serializer.Deserialize(subnode, x => result = (ITestStep)x))
+ {
+ Serializer.PushError(subnode, "Unable to deserialize test step.");
+ continue; // skip to next step.
+ }
+ }
+ catch (Exception ex)
+ {
+ Serializer.PushError(subnode, "Unable to deserialize test step.", ex);
+ continue;
+ }
+
+ if (result != null)
+ steps.Add(result);
+ }
}
setResult(steps);
return true;
}
static XName testStepName = "TestStep";
+ static XName varName = "Variable";
/// <summary> Serialization implementation. </summary>
- public override bool Serialize( XElement elem, object target, ITypeData expectedType)
+ public override bool Serialize(XElement elem, object target, ITypeData expectedType)
{
- if(target is TestStepList)
+ if (target is TestStepList)
{
TestStepList list = (TestStepList)target;
if (!string.IsNullOrEmpty(list.SequenceName))
@@ -66,6 +91,18 @@
Serializer.Serialize(newelem, item, null, true);
elem.Add(newelem);
}
+ var vars = list.Variables;
+ if (vars != null && vars.Count > 0)
+ {
+ for (int i = 0; i < vars.Count; i++)
+ {
+ var item = vars[i];
+ var newelem = new XElement(varName);
+ Serializer.Serialize(newelem, item, null, true);
+ elem.Add(newelem);
+ }
+ }
+
return true;
}
return false;
--
Gitblit v1.9.1