TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Alex Lonyay
NA
123
9.6k
Need help when dealing with Excel Complex Data in MSTest
May 10 2020 8:52 AM
Currently, I am fetching data from particular sheet where it matched a "Key" value - But now I want to access data from all sheets where it matches "Key" value
In my excel - I have two sheets: LogInUserData and Sheet2
Now in LogInUserData
Key
Email
Password
RememberMe
LogInSuccessfully
[email protected]
a
0
LogInWithWrongEmail
a.a
a
0
LogInWithWrongPass
[email protected]
b
0
And in Sheet2
Key
Klarna
LogInSuccessfully
Demo
And in Sheet2
KeyKlarna
LogInSuccessfullyDemo
Now, I want to access values of Key "Loginsuccessfully" from both the sheets - I have code but that fetches it from only first sheet and not from other - so how do i access complex data sheet from excel
I'm using ODBC Connection
public
static
string
TestDataFileConnection(
string
fileName)
{
string
Filename =
"C:\\Users\\PalakS\\source\\repos\\Daily update\\UnitTestProject2 - 10-04\\UnitTestProject2\\ExcelData\\LogInPageData.xlsx"
;
string
connectionString =
string
.Format(
"Dsn=Excel Files;READONLY=false;DBQ={0};"
, Filename);
System.Data.Odbc.OdbcCommand odbcCmd =
new
System.Data.Odbc.OdbcCommand(
""
,
new
System.Data.Odbc.OdbcConnection(connectionString));
return
connectionString;
}
public
static
T GetTestData<T>(
string
fileName,
string
sheet,
string
keyName)
{
using
(var connection =
new
OdbcConnection(TestDataFileConnection(fileName)))
{
connection.Open();
var query =
string
.Format(
"select * from [{0}$]where key = '{1}'"
, sheet, keyName);
var value = connection.Query<T>(query).FirstOrDefault();
connection.Close();
return
value;
}
}
Function call:
LogInUserModel user = AccessExcelData.GetTestData<LogInUserModel>(
"LogInPageData.xlsx"
,
"LogInUserData"
,
"LogInSuccessfully"
);
string
email = user.Email.ToString();
Reply
Answers (
3
)
How to use redraw events
Zephyr for jira Test cases example