Reputation: 3801
What is the "proper" way to pass in parameters?
Code snippet below (pieces have been removed that aren't relevant)...
I am passing in the login parameters in the [TestMethod] itself, and not in the LoginPage class object. Is that the right way to do this? Or, should I be passing the strings into the LoginPage class itself? (I realized there are other ways where I don't need to hard-code anywhere, but I am strictly referring to this hard-code scenario)
class LoginPage
{
IWebDriver driver;
By username = By.Id("user_login");
By password = By.XPath(".//*[@id='user_pass']");
By loginButton = By.Name("wp-submit");
public void loginToWordpress(string userid, string pass)
{
driver.FindElement(username).SendKeys(userid);
driver.FindElement(password).SendKeys(pass);
}
}
and the corresponding test....
[TestMethod]
public void assertPageSource()
{
LoginPage login = new LoginPage(driver);
login.loginToWordpress("admin", "demo123");
login.clickOnLoginButton();
}
Upvotes: 1
Views: 1012
Reputation: 27
Refer to this two articles --
https://raw.githubusercontent.com/wiki/SeleniumHQ/selenium/PageObjects.md
https://www.toolsqa.com/selenium-webdriver/c-sharp/encapsulation-oops-principle/
Upvotes: 1
Reputation: 21
I can think of below ways:
1.@DataProvider annotation from TestNG can be used for passing parameters Here's a good example : https://www.edureka.co/blog/dataprovider-in-testng/
2.Passing parameters using an excel file - you can save the username and passwords in the file(although not the best practice) and use the file for passing parameters. Apache POI is used for reading/writing Excel file in Java, not sure about C#
3.Create a table with usernames and passwords, connect to the table through your code and use the values as parameters
Upvotes: 1