/// <summary>
 /// Validate that the result in the given position in the search results has the title that is expected
 /// </summary>
 /// <param name="resultNum">The position in the search results of the element to validate</param>
 /// <param name="resultTitle">The expected title of the element</param>
 /// <returns>True if the result is as expected, false if the result is not as expected</returns>
 public bool ValidateResult(int resultNum, string resultTitle)
 {
     //Get all the rows in the result table
     var rows = _resultsTable.FindElements(By.XPath("child::li"));
     //Get the title of the specified row
     var recievedTitle = rows[resultNum-1].FindElement(By.XPath("child::div/child::div/child::div/child::div/child::div/child::a/child::h2")).Text;
     if (recievedTitle == resultTitle)
     {
         LogFunctions.WriteInfo("Title of item " + resultNum + " in the list of results is as expected: " + recievedTitle);
         return true;
     }
     LogFunctions.WriteError("Title of item " + resultNum + " in the list of results is not as expected.");
     LogFunctions.WriteError("Expected Title: " + resultTitle);
     LogFunctions.WriteError("Title on the page was: " + recievedTitle);
     return false;
 }
Exemplo n.º 2
0
        /// <summary>
        /// This method is used to write the test results of each test run to a database.
        /// Update the Server, Database(in the dbName variable), User Id, and Password field in the connection string below
        /// The SqlCommand will also need to be updated with the tablename and the columns adjusted to match the database
        /// </summary>
        public static void LogResult()
        {
            var          si        = ScenarioContext.Current.ScenarioInfo;
            var          fi        = FeatureContext.Current.FeatureInfo;
            var          error     = ScenarioContext.Current.TestError;
            const string dbName    = "<databasename>";
            var          errorText = "";
            string       testResult;

            if (error != null)
            {
                errorText = error.Message;
            }
            if (TestPass && error == null)
            {
                testResult = "Pass";
            }
            else
            {
                testResult = "Fail";
            }
            if (WriteToDb)
            {
                using (var conn = new SqlConnection())
                {
                    conn.ConnectionString =
                        "Server=<server>;Database=" + dbName + ";User Id=<username>;Password=<password>";
                    conn.Open();
                    try
                    {
                        var command =
                            new SqlCommand(
                                "insert into dbo.<tableName> Values ('" + fi.Title + "','" + si.Title.Replace("'", "") + "',0,'" + MyTimeStamp +
                                "','" + StartTime + "','" + DateTime.Now + "','" +
                                errorText.Replace("\"", "") + "','" + _mainUrl + "','" + testResult + "','" + MyLog +
                                "','" + Browser.GetThreadID() + "','" + "0" + "')", conn);
                        Assert.IsTrue(command.ExecuteNonQuery() == 1);
                    }
                    catch (SqlException)
                    {
                        LogFunctions.WriteError("Did not get expected result from SQL.");
                        throw;
                    }
                    LogFunctions.WriteInfo("Result Logged to " + dbName + " Database");
                }
            }
        }
Exemplo n.º 3
0
 public void GivenIExpectTheReturnedTitleToBe(string resultTitle)
 {
     _amazonData.searchResultTitle = resultTitle;
     LogFunctions.WriteInfo("Stored Result Title: " + _amazonData.searchResultTitle);
 }
Exemplo n.º 4
0
 public void GivenIwantToValidateTheSpecifiedTitle(int resultNum)
 {
     _amazonData.searchResultNum = resultNum;
     LogFunctions.WriteInfo("Stored Result Number: " + _amazonData.searchResultNum);
 }
Exemplo n.º 5
0
 public void GivenIUseSearchTerm(string searchTerm)
 {
     _amazonData.searchTerm = searchTerm;
     LogFunctions.WriteInfo("Stored Search Term: " + _amazonData.searchTerm);
 }
 /// <summary>
 /// Click on the search button
 /// </summary>
 public void ClickSearchButton()
 {
     Browser.Click(_searchButton);
     LogFunctions.WriteInfo("Search Button has been clicked.");
 }
 /// <summary>
 /// Type in the search term that has been passed in
 /// </summary>
 /// <param name="searchTerm"></param>
 public void TypeSearchTerm(string searchTerm)
 {
     BrowserFunctions.Type(_searchbox,searchTerm);
     LogFunctions.WriteInfo("Search Term " + searchTerm + " entered into website.");
 }