Code for importing data from excel

    일반 토론

  • 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

    coded ui

    Now in the first iteration the value it takes will be


    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   





        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


    2012년 4월 30일 월요일 오전 6:04

모든 응답

  • Hi Sandeep,

    The values that you need to fetch in same iteration should be put in single row:


    Let me know if I have misunderstood anything...


    2012년 4월 30일 월요일 오전 11:05
  • 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.

    coded ui

    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


    2012년 4월 30일 월요일 오전 11:26
  • 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,Assertion53

    Or 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


    • 편집됨 TejasJ 2012년 4월 30일 월요일 오후 1:25
    2012년 4월 30일 월요일 오후 1:24
  • 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)


    2012년 4월 30일 월요일 오후 2:22
  • 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.

    Egzample Data Source

    If you use a Switch Statement




     Case "LAUNCH":


     Case "LOGIN":






    2012년 5월 1일 화요일 오전 10:41