If... Else

3 posts, 0 answers
  1. Nigel
    Nigel avatar
    53 posts
    Member since:
    Jan 2012

    Posted 29 Feb 2012 Link to this post


    Another question that will doubtless be easily answered by someone who knows what they're doing.

    I want my script to branch depending on the value I can retrieve from a databound Excel spreadsheet cell.

    I know how to get the value from the cell using this VB in the Code Behind window, and I can set it as an extracted value available to the Test Studio script with the last line:

    Dim row As Integer = 2
    Dim column As Integer = 4           
    Dim input As String = "C:\Users\edwardni\Documents\Test Studio Projects\Base\Data\BaseData.xlsx"           
    Dim app As New Microsoft.Office.Interop.Excel.Application()
    Dim inputBook As Microsoft.Office.Interop.Excel.Workbook = app.Workbooks.Open(input, 0, False, 3, "", "", False, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", True, False, 0, True, False, False)
    Dim inputSheet As Microsoft.Office.Interop.Excel.Worksheet = DirectCast((inputBook.Worksheets.Item("SetupAllRoles")), Microsoft.Office.Interop.Excel.Worksheet)
    Dim selection As String = TryCast(DirectCast(inputSheet.Cells(row, column), Microsoft.Office.Interop.Excel.Range).Text, String)
    SetExtractedValue("IsAdmin", selection)

    Required Solution
    What I want to do in the script is to have an IF... Else statement like this:

    IF ($(IsAdmin) = "Y")
         <do some stuff>
         <do some different stuff>

    But I don't know how to build the above structure in the script itself.  There is nothing I need to record against so I have nothing to convert to a logical step.

    All responses gratefully received,
    Nigel Edwards, Transition Computing.
  2. Stoich
    Stoich avatar
    1 posts

    Posted 05 Mar 2012 Link to this post

    Hello Nigel,
    you don't need to write the code to access an Excel book on your own. We offer that functionality out of the box with the data-driven functionality:

    Simply data-bind your test to the desired Excel file (make sure the file follows the required format). From there you can create your IF statement like so (if your test is data-bound):
    If Data("myColumn").ToString().Equals("value1") Then
    End If

    Or you can get an extracted value and also use that in the fix:

    Kind regards,
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Nigel
    Nigel avatar
    53 posts
    Member since:
    Jan 2012

    Posted 05 Mar 2012 Link to this post

    Thanks for your input, Stoich.  I'll look through the information in the links you sent.  :)
Back to Top