I am a newbie to Selenium and after much research, I have come to a halt. I have seen various examples with code similar to what I have below:
class LoginPage { private IWebDriver driver; public LoginPage(IWebDriver driver) { this.driver = driver; } //HomePage appears when Login successful public HomePage DoLogin(string user, string pass) { driver.FindElement(By.Name("userfield")).SendKeys(user); driver.FindElement(By.Name("passfield")).SendKeys(pass).Submit(); //what is the above fails and i stay on the LoginPage? returning a HomePage object will be a bad idea here HomePage homepage = new HomePage(driver) PageFactory.InitElements(driver, homepage) return homepage; } } class HomePage{ public HomePage(WebDriver driver) { this.driver = driver; } public void clickExitButton() { exitButton.click(); } public LoginPage logout() { clickExitButton(); LoginPage loginpage = new LoginPage(driver) PageFactory.InitElements(driver, loginpage); return loginpage; } }
My question:
What is either of the classes fail to do what they are supposed to do? What if Login fails? It will still return HomePage object. This should not be the case, right? What can be done to tackle a fail? Most of the examples I have seen assume that things "will" work out correctly.
Is the above implementation correct for C#? Most of the examples I have seen are for Java - just wanted to convert them to C# as I know C# :)
Thanks!