This is a migrated thread and some comments may be shown as answers.

Getting row number from the data bind excel sheet in coded step.

9 Answers 299 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Priyanka
Top achievements
Rank 1
Priyanka asked on 21 Aug 2013, 06:11 AM
Hello Telerik team,
Is is possible to call the external Excel sheet which is already bind to the test in coded step??
I have to write the result Pass/Fail in currently selected row in Excel sheet based on some condition.
Steps that i performed:
1. Added excel sheet then Bind that excel sheet to the test using Data Bind option.
2. Bind the excel sheet column to the steps using Binding Property.
3. Based on the excel column, Data is inserted in that column.
4. Now, Based on the some condition, i have to write the result Pass/Fail in that same excel for that row.
   For that i have created the coded step, in which i am checking the condition and based on the Condition Pass/Fail should be write for same row.But i am not getting the currently selected rowindex from excel.

I am again trying to open the same open, so i didn't get the row number which is binded in the steps.
So is it any another way to perform this???
Please find the attached file for your ref.

Thanks,
Priyanka

9 Answers, 1 is accepted

Sort by
0
Accepted
Cody
Telerik team
answered on 26 Aug 2013, 04:04 PM
Hello,

I apologize for the delay getting back to you on this. We are temporarily overloaded in support at the moment.

But i am not getting the currently selected rowindex from excel.

I'm afraid our data driven testing doesn't work that way. During test initialization Test Studio reads all of the data from the datasource and creates an in-memory .NET DataTable object with the data put into it. Once the data has been fully read Test Studio closes the datasource (e.g. Excel file). It then begins iterating through these rows of data.

We do provide a way to get at the full data source specification in code:

this.ExecutionContext.Test.DataInfo.DataProvider;       // The name of the Excel file, always from the tests Data folder
this.ExecutionContext.Test.DataInfo.DataTable;          // The name of the sheet e.g. Sheet1$
this.ExecutionContext.Test.DataInfo.DataRangeString;    // The range as a string e.g. "2:5"

Using the above information along with:
this.Data.IterationIndex; // The current iteration, always starts at 0

You could calculate the correct place in the Excel file to write into. I hope this helps.

Regards,
Cody
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Priyanka
Top achievements
Rank 1
answered on 27 Aug 2013, 06:00 AM
Hi Cody,
As you said, i have use following code in my script:
  ExecutionContext.Current.Test.DataInfo.DataProvider;
  ExecutionContext.Current.Test.DataInfo.DataTable;
  ExecutionContext.Current.Test.DataInfo.DataRangeString;

I can able to fetch this.Data.IterationIndex; property in code, it is working properly when we use it in script test.
But when i am  trying to capture it inside the namespace class method then couldn't found Data.IterationIndex property.

I have already created forum for that http://www.telerik.com/automated-testing-tools/community/forums/test-studio/general-discussions/unable-to-get-data-iterationindex-property-inside-class-method.aspx
Please give me solutions for that at earliest as possible.

Thanks,



0
Cody
Telerik team
answered on 27 Aug 2013, 08:20 PM
Hello Priyanka,

"Data" is an object that is defined in the base class "BaseWebAiiTest", which is the base class for all Test Studio test code behind files. Since your utility class does not derive from this base class, you are not inheriting its definition. But please do NOT use BaseWebAiiTest for your utility class because the base class will not get initialized properly, including the Data object.

Instead you can do one of two things:

  • Pass "Data" as a parameter to your utility class methods
  • Pass "Data" as a parameter to the constructor of your utility class, store it in a variable and refer to the variable in your utility class methods
Regards,
Cody
Telerik
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Cody
Telerik team
answered on 27 Aug 2013, 08:22 PM
Hello Priyanka,

"Data" is an object that is defined in the base class "BaseWebAiiTest", which is the base class for all Test Studio test code behind files. Since your utility class does not derive from this base class, you are not inheriting its definition. But please do NOT use BaseWebAiiTest for your utility class because the base class will not get initialized properly, including the Data object.

Instead you can do one of two things:

  • Pass "Data" as a parameter to your utility class methods
  • Pass "Data" as a parameter to the constructor of your utility class, store it in a variable and refer to the variable in your utility class methods
Regards,
Cody
Telerik
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Priyanka
Top achievements
Rank 1
answered on 29 Aug 2013, 06:52 AM
Hi cody,

Thanks for your help,I am passing Data as parameter to utility class methods and it is working properly.
I have also try to Pass "Data" as a parameter to the constructor of  utility class, but i am not getting it. Is it possible to you to explain me in detail.
I have write the following code in my UtilityClass.
UtilityClass.test

  public static class Utility
    {
        public static void Validate(string mypath, string alertmsg, string comparemsg, string passmsg)
        {
            Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel.Workbook workbook = excelApp.Workbooks.Open(mypath);
            System.Threading.Thread.Sleep(1000);
            
            if(alertmsg == comparemsg )
            {
                 excelApp.Cells[ 2, 1] = passmsg; ---------------------------------------- Here, i want to pass Data.IterationIndex+2 instead of 2
            }
            else
            {
                excelApp.Cells[2 , 1] = "Pass: Record save";---------------------------Here, i want to pass Data.IterationIndex+2 instead of 2
            }
           
            excelApp.Visible = true;
            excelApp.ActiveWorkbook.Save();
            workbook.Close(false, Type.Missing, Type.Missing);
            excelApp.Workbooks.Close();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
            excelApp.Quit();
            GC.Collect();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
        }
    }
       
I am calling that Validate method in another test i.e. SSN_Duplicate.test

[CodedStep(@"New Coded Step")]
        public void SSN_Duplicate_CodedStep()
        {
            ArtOfTest.WebAii.Core.Browser radwindow=ActiveBrowser.Frames["Radwindow1"];
            ArtOfTest.WebAii.Controls.HtmlControls.HtmlDiv condiv=radwindow.Find.ById<ArtOfTest.WebAii.Controls.HtmlControls.HtmlDiv>("jpopup_container");
            ArtOfTest.WebAii.Controls.HtmlControls.HtmlDiv popupdiv=condiv.Find.ById<ArtOfTest.WebAii.Controls.HtmlControls.HtmlDiv>("popup_message");
            string msg=popupdiv.InnerText;
           
            string path= @"C:\Users\priyanka.kadam\Desktop\Automation_excel\Data_Driven_Test.xlsx";
            Utility.Validate(path,msg,"Attention!SSN #Already exists.","Fail:SSN Duplication");
        }

0
Accepted
Cody
Telerik team
answered on 29 Aug 2013, 05:52 PM
Hi Priyanka,

I have also try to Pass "Data" as a parameter to the constructor of  utility class, but i am not getting it. Is it possible to you to explain me in detail.

Sure. First to do this you can't use static class or static method. Here is sample code to demonstrate the approach:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
using ArtOfTest.WebAii;
using ArtOfTest.WebAii.Core;
using ArtOfTest.WebAii.Design;
 
namespace UtilityClassLibrary
{
    public class UtilityClass
    {
        BaseWebAiiTest theTest;
 
        public UtilityClass(BaseWebAiiTest _test)
        {
            theTest = _test;
        }
 
        public void function1()
        {
            int currentIteration = theTest.Data.IterationIndex;
 
        }
    }
}

Regards,
Cody
Telerik
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Accepted
Cody
Telerik team
answered on 29 Aug 2013, 06:13 PM
Hello,

The code to put in your Test Studio test didn't make it through. Here it is:

using UtilityClassLibrary;
 
namespace MySampleTests
{
    public class ScratchTest2 : BaseWebAiiTest
    {
        private UtilityClass myUtility;
 
        public UtilityClass Utilities
        {
            get
            {
                if (null == myUtility)
                {
                    myUtility = new UtilityClass(this);
                }
                return myUtility;
            }
        }
 
        [CodedStep(@"New Coded Step")]
        public void ScratchTest2_CodedStep()
        {
            Utilities.function1();
        }
    }
}

Regards,
Cody
Telerik
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Priyanka
Top achievements
Rank 1
answered on 30 Aug 2013, 06:37 AM
Hi cody,

Thanks for explaning this things in details and it is working properly.
Thanks for your valuable guidance.

I have write another forum but didn't get replay yet.
Can you please help me out to solve that problem, its urgent.
Please check out the following forum.
http://www.telerik.com/automated-testing-tools/community/forums/test-studio/general-discussions/how-to-pass-excel-worksheet-name-path-as-string.aspx

Thanks,
0
Cody
Telerik team
answered on 03 Sep 2013, 08:08 PM
Hi,

I see that Velin has answered your other forum post.

Regards,
Cody
Telerik
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Priyanka
Top achievements
Rank 1
Answers by
Cody
Telerik team
Priyanka
Top achievements
Rank 1
Share this question
or