Giter VIP home page Giter VIP logo

Comments (2)

tipsey avatar tipsey commented on September 27, 2024

You'll need to leverage native C# and Nuget packages. Check out "SpreadsheetLight". I used version 3.4.11 with success:

using System.IO;
using SpreadsheetLight;

Example:

[TestClass]
public class ReadExcel
{
    [TestMethod]
    public void ExcelReader()
    {
        int row = 0; //To Skip first row header in Excel
        int failed = 0;
   
        string exeDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) +"\\Data";
        using (SLDocument sl = new SLDocument())
        {

            //Locate ExcelLogins.xlsx and Open
            string file = System.IO.Path.Combine(exeDir, "ExcelLogins.xlsx");
            Console.WriteLine(file);
            FileStream fs = new FileStream(file, FileMode.Open);
            SLDocument sheet = new SLDocument(fs, "Sheet1"); //Name of worksheet always has to be default Sheet1

            SLWorksheetStatistics stats = sheet.GetWorksheetStatistics();

            for (int j = 1; j < stats.EndRowIndex + 1; j++)
            {
                
                //Disregard the Title Row this is
                row++;
                if (row == 1)
                {
                    continue;
                }
                // Get the first column of the row (SLS is a 1-based index)

                //0 j = RowCounter, 1 = Column 1, 2 = Column 2 etc

                var Email = sheet.GetCellValueAsString(j, 1);
                var Password = sheet.GetCellValueAsString(j, 2);
    

                //SETUP BROWSER
                Browser.InitBrowser(System.Configuration.ConfigurationManager.AppSettings["BrowserType"]);
                Browser.Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(Timeout);
                var driver = Browser.Driver;
             

                try
                {
                    driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(Timeout);
                    driver.Manage().Window.Maximize();
                    driver.Navigate().GoToUrl("https://pathtoLoginPage");
                    //Login in English
                    // MainPage.Btn_English(driver).Click();
                    LoginPage.Txtbx_Username(driver).Clear();
                    LoginPage.Txtbx_Username(driver).SendKeys(Email);
                    LoginPage.Txtbx_Password(driver).Clear();
                    LoginPage.Txtbx_Password(driver).SendKeys(Password);
                    LoginPage.Btn_Login(driver).Click();

                    //TEST TO SEE IF LOGIN SUCCESSFULLY

                    try
                    {
                        //Click something on page to determine success
                        LoginPage(driver).Click();
                        Console.WriteLine("Login Successful");
                    }
                    catch (Exception)
                    {
                        //BUG Not catching last row exception: make sure last row is valid?

                        failed = failed + 1;
                        Console.WriteLine("FAILED Login: " + Email + " " + Password);
                        continue;
                    }
                   
                    Browser.CloseAllDrivers();
                }

                catch (Exception)
                {
                    Console.WriteLine("Problem with " + Email + " " + Password);
                    if (driver != null)
                        driver.Quit();
                    //When last row get test results
                    if (j == stats.EndRowIndex + 1)
                    {
                        Console.WriteLine("Number of Emails Tested: " + j);
                        Console.WriteLine("Number of Emails Failed: " + failed);
                    }
                    
                    continue;
                }

                //Close any Browser
                if (driver != null)
                    driver.Quit();

                //When last row get test results
                if (j >= stats.EndRowIndex - 1)
                {
                    Console.WriteLine("Number of Emails Tested: " + j);
                    //Console.WriteLine("Number of Emails Failed Not Including Last Row: " + failed);
                }
            }        

        }

        Console.WriteLine("Number of Emails Failed: " + failed);
        Browser.CloseAllDrivers();
    }  
}

}

from easyrepro.

meeta0311 avatar meeta0311 commented on September 27, 2024

Thankyou so much.. I will try this method.

from easyrepro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.