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

If... Else

2 Answers 110 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nigel
Top achievements
Rank 2
Nigel asked on 29 Feb 2012, 05:57 PM
Hi,

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

Scenario
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>
ELSE
     <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 Answers, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 05 Mar 2012, 11:50 AM
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:
http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/data-driven-testing.aspx

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:
http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/code-samples/general/extracted-variables-in-code.aspx

Kind regards,
Stoich
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Nigel
Top achievements
Rank 2
answered on 05 Mar 2012, 01:41 PM
Thanks for your input, Stoich.  I'll look through the information in the links you sent.  :)
Tags
General Discussions
Asked by
Nigel
Top achievements
Rank 2
Answers by
Stoich
Telerik team
Nigel
Top achievements
Rank 2
Share this question
or