Exemple #1
0
        public override List <ResponseAssertionResults> Execute(HttpRequestDto httpRequestDto,
                                                                IMeasuredResponse response)
        {
            ResponseAssertionResultsCollection.Clear();
            if (httpRequestDto.ResponseAssertions.Count > 0)
            {
                foreach (var responseAssertion in httpRequestDto.ResponseAssertions)
                {
                    var responseAssertionResults = new ResponseAssertionResults
                    {
                        AssertionType = responseAssertion.ToString()
                    };
                    var htmlDocument = new HtmlDocument();
                    htmlDocument.LoadHtml(response.Content);
                    if (_loadTestLocators.Any(x => x.LocatorType.Equals(responseAssertion.Locator)))
                    {
                        var currentLocator =
                            _loadTestLocators.First(x => x.LocatorType.Equals(responseAssertion.Locator));
                        try
                        {
                            LoadTestElement htmlElement =
                                currentLocator.LocateElement(htmlDocument, responseAssertion.LocatorValue);
                            if (_loadTestEnsureHandler.Any(x => x.EnsureType.Equals(responseAssertion.AssertionType)))
                            {
                                var currentEnsureHandler = _loadTestEnsureHandler.First(x =>
                                                                                        x.EnsureType.Equals(responseAssertion.AssertionType));
                                responseAssertionResults =
                                    currentEnsureHandler.Execute(htmlElement, responseAssertion.ExpectedValue);
                            }
                            else
                            {
                                responseAssertionResults.FailedMessage =
                                    $"AssertionType {responseAssertion.AssertionType} is not supported.";
                                responseAssertionResults.Passed = false;
                            }
                        }
                        catch (Exception ex)
                        {
                            responseAssertionResults.FailedMessage = ex.Message;
                            responseAssertionResults.Passed        = false;
                        }
                    }
                    else
                    {
                        responseAssertionResults.FailedMessage =
                            $"Locator {responseAssertion.Locator} is not supported.";
                        responseAssertionResults.Passed = false;
                    }

                    ResponseAssertionResultsCollection.Add(responseAssertionResults);
                }
            }

            return(ResponseAssertionResultsCollection);
        }
Exemple #2
0
        public override List <ResponseAssertionResults> Execute(HttpRequestDto httpRequestDto, IMeasuredResponse response)
        {
            ResponseAssertionResultsCollection.Clear();
            var responseAssertionResults = new ResponseAssertionResults
            {
                AssertionType = "StatusCode is SUCCESS",
                Passed        = true,
            };

            if ((int)response.StatusCode <= 200 && (int)response.StatusCode >= 299)
            {
                responseAssertionResults.FailedMessage = $"Request's status code was not successful - {response.StatusCode} {response.ResponseUri}.";
            }

            ResponseAssertionResultsCollection.Add(responseAssertionResults);

            return(ResponseAssertionResultsCollection);
        }