0

I am using C#, Selenium with the page object model.

I need to understand how to pass a username and password from my test code, into my page object.

Example of my current test below:

[TestMethod]
public void Registeruser()
{
     Registrationpage.GoTo();
     Registrationpage.Enterusername();
     Registrationpage.EnterEmail();
}

Extract from Registration page (page object)

public static void Enterusername()
{
    Driver.Instance.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_UserName")).SendKeys("testusername");
}

public static void Email()
{
    Driver.Instance.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Email")).SendKeys("testemail");
}

As you can see, at present i have my entrys in the sendkeys of my pageobject.

Instead, I want to be able to specify the testusername and testemail entrys in my test code so i can vary the text entered on each test.

I understand i need to specify these as strings, but i dont quite understand how to go about this in the pageobject code,I hope this makes sense, any help appreciated ( below is what I want to do)

[TestMethod]
public void Registeruser()
{
     Registrationpage.GoTo();
     Registrationpage.Enterusername(testusername);
     Registrationpage.EnterEmail(testemail);
}
Yi Zeng
  • 32,020
  • 13
  • 97
  • 125
Parkyster
  • 155
  • 3
  • 14

1 Answers1

1

You might want to change your methods to take in string parameters.

public static void Enterusername(string testusername)
{
    Driver.Instance.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_UserName")).SendKeys(testusername);
}

public static void EnterEmail(string testemail)
{
    Driver.Instance.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Email")).SendKeys(testemail);
}

Then call the methods with strings:

[TestMethod]
public void Registeruser()
{
    Registrationpage.GoTo();
    Registrationpage.Enterusername("user3451887");
    Registrationpage.EnterEmail("user3451887@stackoverflow.com");
}
Yi Zeng
  • 32,020
  • 13
  • 97
  • 125