1

I have a test case automation selenium C# language to test login multiple users from excel file. But, I have a problem to test with code. When I run this code, it still login completely the data from excel file. However, the system displayed failure my code test. It shown the reason fail: Message: System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation. ----> System.ArgumentNullException : text cannot be null Parameter name: text Here my test code selenium C#:

using excel = Microsoft.Office.Interop.Excel;


using NUnit.Framework;

using System;

using OpenQA.Selenium.Support.PageObjects;

using LoginPage.Objects;

namespace NUnit.Tests1.TestCases

{
[TestFixture]
public class Data_Driven : Login_Page
{    
    [Test]
    public void Test_Login_Excel()
    {
        try
        {
            excel.Application x = new excel.Application(); //
            excel.Workbook y = x.Workbooks.Open(@"D:\NUnit.Tests1\Test_Login.xlsx"); 
            excel._Worksheet x1WorkSheet = y.Sheets[1]; 
            excel.Range datarange = x1WorkSheet.UsedRange;
            int sw = datarange.Count;
            Console.WriteLine(sw);

            
                for (int i = 2; i <= datarange.Count; i++)
                {
                    if (datarange != null)
                    {
                        string Username = Convert.ToString(datarange.Cells[1][i].value2);
                        string Password = Convert.ToString(datarange.Cells[2][i].value2);
                        waitfunction();
                        var LoginPage = new Login_Page();
                        PageFactory.InitElements(driver, LoginPage);
                        LoginPage.Username.SendKeys(Username);
                        LoginPage.Password.SendKeys(Password);
                        LoginPage.Login.Click();
                        sleepfunction();
                        LoginPage.Username.Clear();
                        sleepfunction();
                        LoginPage.Password.Clear();                
                    }
                    else
                    {
                        return;
                    }
                    
                }
                       
        } catch (Exception e)
            {
                throw (e);
            }
     }
}       

}

Please help me to fix this problem to the system pass test case. Thanks every one!

Phu
  • 11
  • 1

0 Answers0