Class BaseConfiguration
Represents the base configuration settings for HTTP clients used in the Xping SDK library. This abstract class provides common configuration settings that are shared by both the HttpClientConfiguration and BrowserConfiguration classes.
public abstract class BaseConfiguration
- Inheritance
-
BaseConfiguration
- Derived
- Inherited Members
Fields
DefaultHttpRequestTimeoutInSeconds
Default Http request timeout in seconds.
public const int DefaultHttpRequestTimeoutInSeconds = 30
Field Value
Properties
FollowHttpRedirectionResponses
Gets or sets a boolean value which determines whether to follow HTTP redirection responses. Default is true.
public bool FollowHttpRedirectionResponses { get; set; }
Property Value
HttpRequestTimeout
Gets or sets a value that specifies the maximum time to wait for a network request or a browser operation to
finish. If the time exceeds this value, current operation is terminated. See
DefaultHttpRequestTimeoutInSeconds for its default value.
public TimeSpan HttpRequestTimeout { get; set; }
Property Value
MaxRedirections
Gets or sets the maximum number of allowed HTTP redirects. Default is 50.
public int MaxRedirections { get; set; }
Property Value
PropertyBag
Gets a property bag which represents the custom properties of the test steps execution.
public PropertyBag<object> PropertyBag { get; }
Property Value
Methods
AddCookie(Cookie)
Stores a cookie in the current test settings instance.
public void AddCookie(Cookie cookie)
Parameters
cookie
CookieThe cookie to be added.
Exceptions
- ArgumentNullException
Thrown when cookie is null.
AddCookies(CookieCollection)
Adds a collection of cookies to the current test settings. This method iterates through each cookie in the provided CookieCollection and adds them individually using the AddCookie method.
public void AddCookies(CookieCollection cookieCollection)
Parameters
cookieCollection
CookieCollectionThe collection of cookies to be added. Must not be null.
Exceptions
- ArgumentNullException
Thrown when cookieCollection is null.
ClearCookies()
Clears all the cookies stored in the current test settings instance.
public void ClearCookies()
ClearCredentials()
Clears the credentials stored in current test settings instance.
public void ClearCredentials()
ClearHttpContent()
Clears the HTTP content stored in the current test settings instance.
public void ClearHttpContent()
Remarks
Please note this method does not update the content-type header.
ClearHttpRequestHeaders()
Clears the HTTP request headers stored in the current test settings instance.
public void ClearHttpRequestHeaders()
GetCookies()
Returns a list of cookies stored in the current test settings instance.
public CookieCollection GetCookies()
Returns
- CookieCollection
A CookieCollection containing all the cookies from the test settings.
GetHttpContent()
Returns HTTP content stored in the current test settings instance.
public HttpContent? GetHttpContent()
Returns
- HttpContent
HttpContent stored in the current test settings. Null is returned if no HttpContent defined.
GetHttpMethod()
Returns HTTP method stored in the current test settings instance.
public HttpMethod GetHttpMethod()
Returns
- HttpMethod
HTTP method stored in the current test settings. Get is returned if not specified.
GetHttpRequestHeaders()
Returns HTTP request headers stored in the current test settings instance.
public IDictionary<string, IEnumerable<string>> GetHttpRequestHeaders()
Returns
- IDictionary<string, IEnumerable<string>>
HTTP request headers or empty dictionary if none specified.
SetCredentials(NetworkCredential)
Sets the credentials for HTTP request headers using basic authentication.
important
The credentials are encoded in Base64, which does not provide encryption. Base64 is a binary-to-text encoding scheme that is easily reversible. Therefore, the credentials are sent in plain text.
public void SetCredentials(NetworkCredential credential)
Parameters
credential
NetworkCredentialThe NetworkCredential object containing the user's credentials.
SetHttpContent(HttpContent, bool)
Stores the specified HttpContent and optionally sets the corresponding content-type header in the current TestSettings instance.
public void SetHttpContent(HttpContent httpContent, bool setContentHeaders = true)
Parameters
httpContent
HttpContentThe HttpContent to store.
setContentHeaders
boolIf true, automatically sets the
content-type
header based on the type of HttpContent provided.
Remarks
note
It is important to note that invoking this method does not alter the HTTP method of the requests; specifically, it does not set the HTTP method to POST. If required, the HTTP method should be set independently of the HttpContent.
setContentHeaders
is set to true
, the 'content-type' header will be
automatically set based on the httpContent
provided:
StringContent
:"text/plain"
JsonContent
:"application/json"
FormUrlEncodedContent
:"application/x-www-form-urlencoded"
MultipartFormDataContent
:"multipart/form-data"
ByteArrayContent
:"application/octet-stream"
StreamContent
:"application/octet-stream"
HttpContent httpContent = JsonContent.Create("{\"name\":\"John\", \"age\":30, \"car\":null}");
var testSettings = TestSettings.Default;
testSettings.SetHttpContent(httpContent);
Exceptions
- ArgumentNullException
Throws when httpContent is null.
SetHttpMethod(HttpMethod)
Stores the specified HTTP method in the test settings for use in subsequent HTTP requests.
public void SetHttpMethod(HttpMethod httpMethod)
Parameters
httpMethod
HttpMethodThe HTTP method to be used for requests.
SetHttpRequestHeaders(IDictionary<string, IEnumerable<string>>)
Stores the specified HTTP request headers for subsequent use in requests made by the HttpClient and headless browser. This method ensures that all prepared headers are applied to requests, facilitating consistent communication with web servers.
public void SetHttpRequestHeaders(IDictionary<string, IEnumerable<string>> headers)
Parameters
headers
IDictionary<string, IEnumerable<string>>A dictionary of header names and their corresponding values to be applied to outgoing requests.
Examples
var httpRequestHeaders = new Dictionary<string, IEnumerable<string>>
{
{ HeaderNames.UserAgent, ["Chrome/51.0.2704.64 Safari/537.36"] }
};
var testSettings = TestSettings.Default;
testSettings.SetHttpRequestHeaders(httpRequestHeaders);