示例#1
0
        public void ProductsAreDisplayedOnPageAccordingToSearch()
        {
            var searchText = "Faded Short Sleeve T-shirts";

            LogHelper.Info("Trying to check that products are displayed on the page according to the search via API");
            var searchData = new FormUrlEncodedContent(
                new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("controller", "search"),
                new KeyValuePair <string, string>("orderby", "position"),
                new KeyValuePair <string, string>("orderway", "desc"),
                new KeyValuePair <string, string>("search_query", searchText),
                new KeyValuePair <string, string>("submit_search", "")
            }
                );

            var response = ApiHelper.SendPostRequest(_client, EndPoints.BasePath, searchData, ContentTypeConstants.FormUrlencoded);

            var firstItemTitleXpath = "//*[contains(@class,'first-in-line') and contains(@class,'first-item')]//*[@class='product-name']";

            HtmlAssertions.GetHtmlElementText(response.Result.Content.ReadAsStringAsync().Result, firstItemTitleXpath).Should().Contain(searchText);
        }
        public void LoginWithValidCredentials()
        {
            LogHelper.Info("Trying to login via API");
            var loginData = new FormUrlEncodedContent(
                new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("controller", "authentication"),
                new KeyValuePair <string, string>("email", ConfigurationManager.AppSettings["Login"]),
                new KeyValuePair <string, string>("passwd", ConfigurationManager.AppSettings["Password"]),
                new KeyValuePair <string, string>("SubmitLogin", "")
            }
                );

            var response = ApiHelper.SendPostRequest(_client, EndPoints.BasePath, loginData,
                                                     ContentTypeConstants.FormUrlencoded);

            var logOutButtonXpath  = "//*[@class='logout']";
            var accountButtonXpath = "//*[@class='account']";

            HtmlAssertions.IsElementExistsOnHtmlPage(response.Result.Content.ReadAsStringAsync().Result, logOutButtonXpath).Should().BeTrue();
            HtmlAssertions.IsElementExistsOnHtmlPage(response.Result.Content.ReadAsStringAsync().Result, accountButtonXpath).Should().BeTrue();
        }