Code for importing data from excel
-
Monday, April 30, 2012 6:04 AM
Hello,
Im using a coded ui test.Its a data driven test and I have connected excel as the data source.The excel content is given below
Now in the first iteration the value it takes will be
TestUser,Pswd007,ONE
Second : blank value,blank value,TWO
Third : blank value,blank value,THREE
Now the requirement : The scenario force me to have only one iteration which ” takes the
First value : from first Coloumn-first row(TestUser)
Second value : Second coloumn-first row (Pswd007)
Third : Third coloumn all rows (ONE,TWO,THREE)
Ie if I use MessageBox.Show then the result should be
TestUser
Pswd007
ONE
TWO
THREE (ie in the first iteration itself it should take all the values in the third coloumn)
Can anybody provide me the code to implement this?
Thanks in advance
Sandeep
- Edited by Sandeep Raveendran Monday, April 30, 2012 6:12 AM first coloumn
All Replies
-
Monday, April 30, 2012 11:05 AM
Hi Sandeep,
The values that you need to fetch in same iteration should be put in single row:
TestUser,Pswd007,ONE,TWO,THREE
Let me know if I have misunderstood anything...
-Tejas.
-
Monday, April 30, 2012 11:26 AM
Hello Tejas,
Sorry.I think you are mistaken and probably its my fault in explaining the scenario.
Let me explain it again.
Scenario is user logs into an application and checking some assertion in the home page.
Here when the fisrt user logs in he have 5 assertions to check.So in the first iteration the values should be
User 1 pwd001 Assertion 1 Assertion 2 Assertion 3 Assertion 4 Assertion 5
Then it moves down User 2. (Hope you understand this )
Is it possible to have a code for this logic?
Im ready to explain again still you are not able to get what im asking about :)
Many thanks
Sandeep
-
Monday, April 30, 2012 1:24 PM
So that means one iteration has five assertions in it and all the values to be compared are data driven, you want them to get from datasource in same iteration? : "One Iteration, Five Assertions" : Use this when single method covers multiple assertions (probably of different things) :
Iteration1: User1,Password1,Assertion11,Assertion21,Assertion31,Assertion41,Assertion51
Iteration2: User2,Password2,Assertion12,Assertion22,Assertion32,Assertion42,Assertion52
Iteration3: User3,Password3,Assertion13,Assertion23,Assertion33,Assertion43,Assertion53Or you have five iterations of same test with different assertion values and you want to share the same credentials across the iterations? : "Five Iteration, Five Assertions" : Use this when same method is executed multiple times to assert same thing with different parameters :
Iteration1: User1,Password1,Assertion11
Iteration2: User1,Password1,Assertion12
Iteration3: User1,Password1,Assertion13-Tejas.
- Edited by TejasJ Monday, April 30, 2012 1:25 PM
-
Monday, April 30, 2012 2:22 PM
Hello Tejas,
The first method you specified , already I had in my mind and rejected.Because its better to specify the assertion in rows(as I mentioned in the above image) than columns to make it easily understandable and to keep the excel sheet looks good(as I have a lot many assertions to add further as the project progresses to next levels.
About second method : I think it wont meet our requirement.Bcoz the user needs to be logged in just 1 time until all five assertions are verified.In the second method mentioned here,the user is tempting to log in again and again in all the iterations.
So, any other methods to make this work?
I think using Microsoft.Office.Interop.Excel can do the task.
Further more inputs on this? (codes)
Sandeep
-
Tuesday, May 01, 2012 10:41 AM
Hi Sandeep
Can I recommend having one column of your data source that contains the action to be performed and start off in row 1 with launching the Application Under Test then Row 2 Login and then Row 3 some other action.
If you use a Switch Statement
eg.
Switch(this.datacontext.datarow1["Action"].tostring.upper())
{
Case "LAUNCH":
this.UIMap.LaunchApp();
Case "LOGIN":
this.UIMap.LoginParams.UID=this.datacontext.datarow1["Data1"].tostring();
this.UIMap.LoginParams.PW=this.datacontext.datarow1["Data2"].tostring();
this.UIMap.Login();
}
HTH

