Class TestSession
Represents a test session that contains a collection of test steps and their results.
[Serializable]
public sealed class TestSession : IDisposable, IAsyncDisposable, ISerializable, IDeserializationCallback, IEquatable<TestSession>
- Inheritance
-
TestSession
- Implements
- Inherited Members
- Extension Methods
Remarks
A test session is a class that represents a test execution and its attributes. It consists of one or more test steps that execute different actions or validations on the URL, such as DNS lookup, HTTP request, HTML parsing, or headless browser interaction. A test session has a start date and a duration that indicate when and how long the testing took place. It also has a state that indicates the overall status of the test session, such as completed, failed, or declined. A test session can store various data related to the test operation in a PropertyBag<TValue>, which is a dictionary of key-value pairs of serializable objects. The property bag can contain data such as resolved IP addresses from DNS lookup, HTTP response headers, HTML content, or captured screenshots from the headless browsers. A test session can be serialized and deserialized to and from stream, using the TestSessionSerializer. This enables the test session to be saved and loaded for further analysis and comparison, or transferred between different machines or applications.
Constructors
TestSession()
Initializes a new instance of the TestSession class.
public TestSession()
TestSession(SerializationInfo, StreamingContext)
Initializes a new instance of the TestSession class with serialized data.
public TestSession(SerializationInfo info, StreamingContext context)
Parameters
info
SerializationInfoThe SerializationInfo that holds the serialized object data about the test session.
context
StreamingContextThe StreamingContext that contains contextual information about the source or destination.
Properties
DeclineReason
Returns decline reason for the current test session.
public string? DeclineReason { get; init; }
Property Value
Remarks
A test session may be declined if it attempts to run a test component that needs a headless browser, but no headless browser is available. Another cause of a declined test session is invalid data that blocks the test execution.
Duration
Gets the total duration of all the steps in the test session.
public TimeSpan Duration { get; }
Property Value
Failures
Returns a read-only collection of the failed test steps within current test session.
public IReadOnlyCollection<TestStep> Failures { get; }
Property Value
Id
Gets the unique identifier of the test session.
public Guid Id { get; }
Property Value
IsValid
Returns a boolean value indicating whether the test session is valid or not.
public bool IsValid { get; }
Property Value
Remarks
Valid test session has all test steps completed successfully. Check Failures to get failed test steps.
StartDate
Gets the start date of the test session.
public required DateTime StartDate { get; init; }
Property Value
State
Gets the state of the test session.
public required TestSessionState State { get; init; }
Property Value
- TestSessionState
A TestSessionState enum that represents the state of the current test session.
Steps
Returns a read-only collection of the test steps executed within current test session.
public required IReadOnlyCollection<TestStep> Steps { get; init; }
Property Value
Url
A Uri object that represents the URL of the page being validated.
public required Uri Url { get; init; }
Property Value
Methods
Dispose()
Releases the resources stored in the TestSession.
public void Dispose()
DisposeAsync()
Asynchronously releases the resources stored in the TestSession.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
Equals(object?)
Determines whether the current TestSession object is equal to a specified object.
public override bool Equals(object? obj)
Parameters
obj
objectThe object to compare with the current object.
Returns
- bool
true
if the current object and obj are both TestSession objects and have the same id; otherwise,false
.
Equals(TestSession?)
Determines whether the current TestSession object is equal to another TestSession object.
public bool Equals(TestSession? other)
Parameters
other
TestSessionThe TestSession object to compare with the current object.
Returns
- bool
true
if the current object and other have the same id; otherwise,false
.
GetHashCode()
Returns the hash code for the current TestSession object.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer hash code.
ToString()
Returns a string that represents the current TestSession object.
public override string ToString()
Returns
- string
A string that represents the current object.
Operators
operator ==(TestSession?, TestSession?)
Determines whether two TestSession objects have the same id.
public static bool operator ==(TestSession? lhs, TestSession? rhs)
Parameters
lhs
TestSessionThe first TestSession object to compare.
rhs
TestSessionThe second TestSession object to compare.
Returns
- bool
true
if lhs and rhs have the same id; otherwise,false
.
operator !=(TestSession?, TestSession?)
Determines whether two TestSession objects have different id.
public static bool operator !=(TestSession? lhs, TestSession? rhs)
Parameters
lhs
TestSessionThe first TestSession object to compare.
rhs
TestSessionThe second TestSession object to compare.
Returns
- bool
true
if lhs and rhs have different id; otherwise,false
.