I have a number of feature files which need to assert the pre-populated data on the webpage - each feature file has its own step definition file
e.g in customer feature step def file:
[Then(@"I expect all fields on the screen populated with Customer Details from the Database")]
public void PopulatedWithCustomerDetailsFromTheDatabase ()
{
foreach (var entry in dataDictionary)
{
Assert.That(pages.CustomerPage.GetText(entry.Key), Is.EqualTo(entry.Value));
}
}
in the company step definition file:
[Then(@"I expect all fields on the screen populated with Company Details from the Database")]
public void PopulatedWithCompanyDetailsFromTheDatabase()
{
foreach (var entry in dataDictionary)
{
Assert.That(pages.CompanyDetailsPage.GetText(entry.Key), Is.EqualTo(entry.Value));
}
}
Both use the relevant page object class to get the text from the page and assert its correct. Its been recommended that i dont share step definitions like this as they are using different page objects which i agree with. The problem is i will need to do this on another 50+ pages, CustomerPage, CompanyDetailsPage, StockPage, DeliveryPage etc...
Any advice on how i could structure this so i have more commonality in the step defs? - there must be a better way, i'm just duplicating code but struggling to visualise a solution from an architectural perspective.
Actions common to many pages should be encapsulated as the own page models and Page models can be composed of multiple page models - how can this be achieved?
To clarify each page is different so in addition to above step defs, for the Address page feature i have a step def:
[Then(@"I expect all fields on the screen populated with AddressDetails from the Database")]
public void PopulatedWithAddressDetailsFromTheDatabase()
{
foreach (var entry in dataDictionary)
{
Assert.That(pages.AddressDetailsPage.GetText(entry.Key), Is.EqualTo(entry.Value));
}
}
which has fields like address line1, address line 2 etc....
and the Stock Page feature which has step def:
[Then(@"I expect all fields on the screen populated with Stock from the Database")]
public void PopulatedWithStockFromTheDatabase()
{
foreach (var entry in dataDictionary)
{
Assert.That(pages.StockPage.GetText(entry.Key), Is.EqualTo(entry.Value));
}
}
which has stock list fields etc...for 50 different pages
List<string>. Then inside your test, call a helper method that pulls the data from the database in aList<string>. At that point, you can use aCollectionAssertto compare the twoLists inside the test. - JeffC