I have 4 page object classes to represent 4 operational pages. Each page contains similar table with a few having extra components like extra buttons.
Currently I have I'm faced with "large class" to handle the different variations of the table.
I have it conditioned to simply check the URL then continue performing actions on the table for that page.
Goal: I would like to figure out how I should refactor my code in a way that I can handle the table when I hit either of the pages without having so many page objects in one class and if conditions duplicating code.
Example: 3 pages use table 1 which contains an extra button
1 page uses table 2 which does not have an extra button
public class Table
{
public readonly TableMap Map;
public class Table()
{
Map = new TableMap();
}
public void OpenDoc()
{
var pageCurrentUrl = Driver.Url;
switch(pageCurrentUrl)
{
case URLOne:
case URLTwo:
case URLThree:
//open doc within table 1
break;
case URLFour:
//open doc within table 2
break;
}
}
}
public class TableMap
{
//table for three pages
public class IWebElement ButtonOneTable1 => Driver.FindElement(By.CssSelector("element"));
public class IWebElement ButtonTwoTable1 => Driver.FindElement(By.CssSelector("element"));
public class IWebElement RowsTable1 => Driver.FindElement(By.CssSelector("element"));
public class IWebElement ColumnsTable1 => Driver.FindElement(By.CssSelector("element"));
//table for 1 page
public class IWebElement ButtonOneTable2 => Driver.FindElement(By.CssSelector("element"));
public class IWebElement RowsTable2 => Driver.FindElement(By.CssSelector("element"));
public class IWebElement ColumnsTable2 => Driver.FindElement(By.CssSelector("element"));
}
Essentially I have way to many page objects in this class and I have code duplicate in that switch statement that I'd like to refactor.
Aucun commentaire:
Enregistrer un commentaire