/// <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;
 }
Ejemplo 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");
                }
            }
        }