How can I turn a list of assertions into a table? C#/Specflow Selenium



  • I am very new to using C#/Specflow to write tests so thank you for the patience. I have a test that ends like this:

    Then the Details page should display the rating zip code
        And the Details page should display the ID
        And the Details page should display the Eligible Employee count
    

    And the code behind looks like this:

        [Then(@"the Details page should display the rating zip code")]
        public void ThenTheDetailsPageShouldDisplayTheRatingZipCode()
    
        {          
            string actualvalue = Driver.Instance.FindElement(By.CssSelector("div.GroupInfoRow:nth-child(3) > label:nth-child(2)")).Text;
            Assert.IsTrue(actualvalue.Equals(actualvalue));          
        }
    
        [Then(@"the Details page should display the ID")]
        public void ThenTheDetailsPageShouldDisplayTheID()
        {
            string actualvalue = Driver.Instance.FindElement(By.CssSelector("div.GroupInfoRow:nth-child(1) > label:nth-child(2)")).Text;
            Assert.IsTrue(actualvalue.Equals(actualvalue));
        }
    
        [Then(@"the Details page should display the Eligible Employee count")]
        public void ThenTheDetailsPageShouldDisplayTheEligibleEmployeeCount()
        {
            string actualvalue = Driver.Instance.FindElement(By.CssSelector("div.GroupInfoRow:nth-child(4) > label:nth-child(2)")).Text;
            Assert.IsTrue(actualvalue.Equals(actualvalue));
        }
    

    I would rather it be displayed in a table format but I'm not sure how to do it.

    Thank you.



  • Your specflow file should look like this:

    Then the Details page should display the rating zip code
        And the Details page should display
        | Parameter       | Value |
        |  ID             | 5     |
        |  Employee Count | 125   |
    

    And your code should look like this:

    [Then(@"the Details page should display")]
    public void DetailsPageShouldDisplay(Table table)
    {
       List<TestParameter> detailsParameter = table.CreateSet<TestParameter>().ToList();
       // then iterate through detailsParameter by Name and do proper assertions
    }
    

    And your TestParameter class should look like this:

    public class TestParameter
    {
        [TableAliases("Parameter", "Field")]
        public string Name { get; set; } = "";
    
        public string Value { get; set; } = "";
    }
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2