Comments (2)
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.
Thankyou so much.. I will try this method.
from easyrepro.
Related Issues (20)
- Compatibility with selenium 4.11 version and CFT
- [BUG] Command Bar not found when header is expanded
- [FEATURE] Get/Retrieve/Search records from timeline
- [BUG] Setting value on Subject field on Case entity (tree-view type)
- [FEATURE] Read the Values from the SLA Timer Section
- [HOW-TO] Run tests on Jenkins
- [HOW-TO] Use with Customer Service Workspace app
- Command xrmApp.Navigation.OpenSubArea("Area", "Sub-Area"); running in Local but failing in pipeline
- How to Close Alert dialogue box of Dynamics crm Opened via Xrm.Navigation.openAlertDialog.
- .NET 6 not .NET Core 6
- Timeout Issue with System.Net.HttpWebRequest.GetResponse()
- [BUG] <Getting webdriver exception "unknown error: unable to discover open pages" when running the test on server through ADO test plan. Code works locally>
- [BUG]GetFormNotifications() does not get notifications text. Get error
- Moving to .NET Core HOT 1
- MFA secret key issue HOT 8
- How to click on the phone (subgrid record header) phone number HOT 5
- Url is not working even after adding & in the url in app.config file HOT 1
- How can I effectively load and execute the EasyRepro framework within Visual Studio Code? HOT 1
- Not able to find xpath from inspect element for any change area options.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from easyrepro.