Beispiel #1
0
        public void ThenTheDetailsAreReturned()
        {
            dynamic data = JObject.Parse(_jsonReader.ReadJson("GetResults.json"));
            dynamic results;

            if (_iRestResponse.ResponseStatus.ToString() != "Error")
            {
                results = JObject.Parse(_iRestResponse.Content.ToString());
                HttpStatusCode statusCode        = _iRestResponse.StatusCode;
                int            numericStatusCode = (int)statusCode;
                _responseStatus = numericStatusCode.ToString();
            }
            else
            {
                results         = null;
                _responseStatus = null;
            }

            var responseCode = _jsonReader.ReadJson("WSData.json", "GET_RESPONSE_CODE");

            try
            {
                if (results != null)
                {
                    //For the 1st object
                    //Assert.AreEqual("expectedValue", "actualValue");
                    Assert.AreEqual((string)data.data[0].first_name, (string)results.data[0].first_name);

                    /*
                     * Example:
                     * Assert.AreEqual((string)data.data[0].first_name, (string)results.data[0].first_name);
                     * 1. Need to write assertions depending on the number of objects and number of fields returned from each objects.
                     */

                    //Verify the response code
                    //Assert.AreEqual("expected_Response_status", responseStatus);

                    ///*Example:
                    Assert.AreEqual(responseCode, _responseStatus);
                }
                else
                {
                    // If the created detals are not returned
                    //Assert.AreEqual("Expected_Response_Status", responseStatus);

                    ///*Example:
                    Assert.AreEqual(responseCode, _responseStatus);
                }

                ExtentReporting.LogReportStatement(AventStack.ExtentReports.Status.Pass, _scenarioContext.StepContext.StepInfo.StepDefinitionType + " " + _scenarioContext.StepContext.StepInfo.Text + " Step Passed");
                ExtentReporting.LogReportStatement(AventStack.ExtentReports.Status.Pass, _scenarioContext.ScenarioInfo.Title.ToString() + " TestPassed");
            }
            catch (AssertionException e)
            {
                ExtentReporting.LogReportStatement(AventStack.ExtentReports.Status.Fail, _scenarioContext.StepContext.StepInfo.StepDefinitionType + " " + _scenarioContext.StepContext.StepInfo.Text + " Step Failed");
                ExtentReporting.LogReportStatement(AventStack.ExtentReports.Status.Fail, _scenarioContext.ScenarioInfo.Title.ToString() + " TestFailed: " + e.Message);
            }

            ExtentReporting.FlushReport();
        }
Beispiel #2
0
        public void WhenICallTheURL()
        {
            _iRestResponse = _allWebServiceRequests.GetRequest(_apiUrl);

            if (_iRestResponse.ResponseStatus.ToString() != "Error")
            {
                ExtentReporting.LogReportStatement(AventStack.ExtentReports.Status.Pass, _scenarioContext.StepContext.StepInfo.StepDefinitionType + " " + _scenarioContext.StepContext.StepInfo.Text + " Step Passed");
            }

            else
            {
                ExtentReporting.LogReportStatement(AventStack.ExtentReports.Status.Fail, _scenarioContext.StepContext.StepInfo.StepDefinitionType + " " + _scenarioContext.StepContext.StepInfo.Text + " Step Failed: " + _iRestResponse.ErrorMessage.ToString());
                ExtentReporting.FlushReport();
                Assert.Fail(_scenarioContext.StepContext.StepInfo + " Step Failed");
            }
        }
Beispiel #3
0
        public void GivenIHaveTheAPIURLForGETRequest()
        {
            ExtentReporting.SetupExtentReport("Webservice Test Report", "Webservice Request");
            ExtentReporting.CreateTest(_scenarioContext.ScenarioInfo.Title);
            _apiUrl = _jsonReader.ReadJson("WSData.json", "GET");

            if (_apiUrl != "")
            {
                ExtentReporting.LogReportStatement(AventStack.ExtentReports.Status.Pass, _scenarioContext.StepContext.StepInfo.StepDefinitionType + " " + _scenarioContext.StepContext.StepInfo.Text + " Step Passed");
            }

            else
            {
                ExtentReporting.LogReportStatement(AventStack.ExtentReports.Status.Fail, _scenarioContext.StepContext.StepInfo.StepDefinitionType + " " + _scenarioContext.StepContext.StepInfo.Text + " Step Failed: " + "There is something worng with the URL. Please check the URL and try again.");
                ExtentReporting.FlushReport();
                Assert.Fail(_scenarioContext.StepContext.StepInfo + " Step Failed");
            }
        }
        public void ExecuteGetRequest()
        {
            var            getRequestURL     = _jsonReader.ReadJson("WSData.json", "GET"); /*"getRequestURL";*/
            var            irestResponse     = _webServiceRequests.GetRequest(getRequestURL);
            var            response          = irestResponse.Content.ToString();
            HttpStatusCode statusCode        = irestResponse.StatusCode;
            int            numericStatusCode = (int)statusCode;

            method = MethodBase.GetCurrentMethod();

            ExtentReporting.SetupExtentReport("Webservice Test Report", "Webservice Request");
            ExtentReporting.CreateTest(method.Name);
            dynamic results      = JObject.Parse(response);
            dynamic data         = JObject.Parse(_jsonReader.ReadJson("GetResults.json"));
            var     responseCode = _jsonReader.ReadJson("WSData.json", "GET_RESPONSE_CODE");

            try
            {
                //For the 1st object
                //Assert.AreEqual("expectedValue", "actualValue");
                Assert.AreEqual((string)data.data[0].first_name, (string)results.data[0].first_name);

                /*
                 * Example:
                 * Assert.AreEqual((string)data.data[0].first_name, (string)results.data[0].first_name);
                 * 1. Need to write assertions depending on the number of objects and number of fields returned from each objects.
                 */

                //Verify the response code
                //Assert.AreEqual("expected_Response_status", responseStatus);

                ///*Example:
                Assert.AreEqual(responseCode, numericStatusCode.ToString());

                ExtentReporting.LogReportStatement(AventStack.ExtentReports.Status.Pass, method.Name.ToString() + " TestPassed \n" + "\n API Resposne:" + "\n" + irestResponse.Content);
            }
            catch (AssertionException e)
            {
                ExtentReporting.LogReportStatement(AventStack.ExtentReports.Status.Error, e.Message);
                ExtentReporting.LogReportStatement(AventStack.ExtentReports.Status.Fail, method.Name.ToString() + " TestFailed: " + e.Message);
            }
            ExtentReporting.FlushReport();
        }