I’ve got a variable failure, that can have three values: passed, failure, or error. What I want to happen during serialization is to create an element based on the value. For passed, I want to ignore the element. For failure I want a failure element. For error, I want an error element. How can this be done?
In the class Test, there is a list of Steps called m_steps. In Step there is a variable called m_failure, which holds passed, failure or error. I want the element created by m_steps to be non-element(passed), failure, or error.
[XmlRoot("testsuite")]
public class Suite
{
[XmlAttribute("name")]
public string m_name;
[XmlElement("testcase")]
public List<Test> m_tests;
[XmlIgnore]
public string m_timestamp;
public class Test
{
[XmlAttribute("name")]
public string m_name;
[XmlElement("failure")] // want to be ignore, failure or error instead of just failure
public List<Step> m_steps;
[XmlAttribute("assertions")]
public int m_assertions;
}
public class Step
{
[XmlIgnore]
public string m_failure; // holds passed, failure, or error
[XmlTextAttribute]
public string m_message;
[XmlIgnore]
public string m_image;
[XmlAttribute("type")]
public string m_type;
}
Looking for:
To:
<?xml version="1.0" encoding="UTF-8"?>
-<testsuite name=" SimpleCalculationsSuite" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-<testcase name="Add 3+4" assertions="1"></testcase>
-<testcase name="Fail 3-4" assertions="1">
<failure type="Text">The control text is not correct. Expected-7 Actual--1</failure>
</testcase>
-<testcase name="Error 3*4" assertions="1">
<error type="Click">The * button was not found</error>
</testsuite>
From:
Suite: SimpleCalculationsSuite
Test:Add 3+4
Passed:Text:The control text, 7, is correct.
Test:Fail 3-4
Failed:Text:The control text is not correct. Expected-7 Actual--1
Test:Error 3*4
Error:Click: The * button was not found
I ended up modifying Test to also include a list of errors. With this I was able to have both failure and error nodes present in the XML file. I also had to modify some of the program to allow this to happen.