i was required to do assigment of selenium by POM design. I created class of functios and there i'm using with functions in main. My question is if i did it well and if i didn't miss something, like if the design of POM is correcet and if i should add try and catch each function or other things.
//Function class
public class Functions
{
IWebDriver driver;
static string path = Path.Combine("DataEX.xlsx");
XSSFWorkbook workbook = new XSSFWorkbook(File.Open(path, FileMode.Open));
public Functions(IWebDriver driver)
{
this.driver = driver;
}
public void OpenBrowser()
{
driver.Navigate().GoToUrl(url);
}
public void existsElement(string cssselectorName)
{
try
{
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector(cssselectorName)));
}
catch(Exception e)
{
throw new Exception(e.Message);
}
}
public void Click(string cssselectorName)
{
driver.FindElement(By.CssSelector(cssselectorName)).Click();
}
public void Set(string cssselectorName,int row_from_file, int col_from_file)
{
var sheet = workbook.GetSheetAt(0);
DataFormatter formatter = new DataFormatter();
var value = formatter.FormatCellValue(sheet.GetRow(row_from_file).GetCell(col_from_file)).Trim();
driver.FindElement(By.CssSelector(cssselectorName)).SendKeys(value);
}
public void CloseBrowser()
{
driver.Close();
driver.Quit();
}
}
//Main class
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
IWebDriver driver = new EdgeDriver();
driver.Manage().Window.Maximize();
Functions function = new Functions(driver);
function.OpenBrowser();
function.existsElement("div[id='header_logo']");
function.Click("div[class='header_user_info']");
function.Set("input[id='email_create']",1,2);
function.Click("button[id='SubmitCreate']");
function.existsElement("form[id='account-creation_form']");
function.Click("input[id='id_gender1']");
function.CloseBrowser();
}
}