Reading multiple data from excel in Selenium POM pattern

Hi Lakshya

Thanks for your all  tutorials and they are very much informative

I have problem which holding me back to proceed to build the framework using POM( reference https://www.ampower.me/article/Selenium/An-example-of-test-automation-framework-C-Selenium-WebDriver-NUnit-PART-3-96-411531)

I have loginpage with username , password and login button, for username and password data is retrieved from excel sheet which contains multiple user name and password

 

My requirement is for each row i.e. for user name and password I need to put pass or fail status in excel sheet and take screenshot

Below are the screenshot of my code

Can you please advise or suggest how to proceed and what modification I need to do to my scripts

 

I have create two classes LoginPages.cs and LoginTest.cs

 

TestCase Execute UserName Password LoggedUserName
LoginAdmin Yes srikanth.panchikarla@nnnnn.com b Srikanth
LoginAdmin No srikanth.panchikarla@ovvagton.c c Srikanth
LoginAdmin No srikanth.panchikarla@jjd.com b Srikanth

 

LoginPages.cs

I am logging out and logging in again so that next set of data can be entered

public LoginPages Login(string sheetname)
{

ExcelDataAccess s = new ExcelDataAccess();
DataSet ds=s.ReadExcel(sheetname);
foreach (DataRow item in ds.Tables[0].Rows)
{

string DisplayedUserName = item[“LoggedUserName”].ToString();
var executeModule = item[“Execute”].ToString();
if (executeModule == “Yes”)
{
try
{
emailInput.SendKeys(item[“UserName”].ToString());
passwordInput.SendKeys(item[“Password”].ToString());
//DisplayedUserName = item[“LoggedUserName”].ToString();
loginButton.Click();
Thread.Sleep(5000);
logoutLink.Click();
}
catch (Exception ex)
{
string msg = ex.Message;
}
}
}

return this;
}

 

LoginTest.cs

[Test]
public void AdminLogin()
{
LoginPages loginpage = new LoginPages(Driver).GoTo().LoginLinkClick();
// loginpage = new LoginPages(Driver).LoginAs(“LoginAdmin”);
loginpage = new LoginPages(Driver).Login(“LoginAdmin”);
Driver.GetScreenshot().SaveAsFile(_screenshotFolderPath, ImageFormat.Png);
}

Please let me know if you need any further information

Thanks and regards

Srikanth

Add Comment
  • 0 Answer(s)
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.