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

Data driven If statement

10 Answers 261 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 2
John asked on 30 Sep 2011, 02:07 PM

Is there a way to camper values from the Data table?  For example:

If([User Role] = “Admin”) then run anything under the true branch.  In my case I want to do different validation for each role and do not want to go down the coding path as of yet. 

Any ideas?

Thanks,

John

10 Answers, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 30 Sep 2011, 04:14 PM
Hi John,
     you can record separate tests for each specific type of user. Then you can add multiple (non-coded) IF/ELSE statements each of which checks whether you're logged in with a specific type of user.
Now you can make use of the TestAsStep feature:
http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/add-custom-step/test-as-step.aspx
Inside each IF clause you can add the corresponding (in terms of user type) test as a TestAsStep.

Let me know if you have any additional questions on this.

Kind regards,
Stoich
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
John
Top achievements
Rank 2
answered on 30 Sep 2011, 05:13 PM
Stoich,
we are on the same page but the question is that I will have mixed rolls.  Each row will have the ID of admin, manager, or staff.  Can I place a condition to compare the current Row data in the none coded IF?  I was not sure on how to place the compare in the none code form?

Thanks,
John
0
Cody
Telerik team
answered on 30 Sep 2011, 11:27 PM
Hi John,

Test Studio does not support data driving the IF ELSE logical blocks. They can be driven by properties of the UI. is there anything unique that shows up based on the user type e.g. Admin in the upper right vs Manager vs Staff? If so you can write an IF UI text block = "Admin" do this ELSE IF UI text block = "Manager" do this ELSE do this.

Otherwise you'll have to do something in code like this:

if (Data["Role"] == "Admin")
    this.ExecuteTest(@"c:\testprojectdir\AdminTest.aii");
if (Data["Role"] == "Manager")
    this.ExecuteTest(@"c:\testprojectdir\ManagerTest.aii");
if (Data["Role"] == "Staff")
    this.ExecuteTest(@"c:\testprojectdir\StaffTest.aii");

Greetings,
Cody
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
John
Top achievements
Rank 2
answered on 01 Oct 2011, 05:37 PM
thank you, I will play with it.  I have two questions.

1) Can you show the VB version of the code?
2) What file extension is it that I need to call?

thanks,
John
0
Cody
Telerik team
answered on 03 Oct 2011, 03:23 PM
Hi John,

Using our code conversion tool, here's the VB.NET equivalent:

If  Data("Role")  =  "Admin"  Then
    Me.ExecuteTest("c:\testprojectdir\AdminTest.aii")
End   If
If  Data("Role")  =  "Manager"  Then
    Me.ExecuteTest("c:\testprojectdir\ManagerTest.aii")
End  If
If  Data("Role")  =  "Staff"  Then
    Me.ExecuteTest("c:\testprojectdir\StaffTest.aii")
End  If

You can use any file extension. That API call assumes whatever file you point to is a valid Test Studio test file and will attempt to load and parse the file.

All the best,
Cody
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
John
Top achievements
Rank 2
answered on 03 Oct 2011, 04:03 PM
I entered the following code:

If (Data("License") = "Site") Then
    Me.ExecuteTest("Edition 4.0\OFA Site WebTest.tstest")
ElseIf  (Data("License") = "Single") Then
    Me.ExecuteTest("Edition 4.0\OFA Single WebTest.tstest")
ElseIf  (Data("License") = "Single") Then
    Me.ExecuteTest("Edition 4.0\OFA Free WebTest.tstest")
End If


I ran it and it works, let me know if you see any issues with this code?

thanks again,
John
0
Cody
Telerik team
answered on 03 Oct 2011, 04:28 PM
Hi John,

Did you mean to use "Free" (or something similar) where I highlighted instead of "Single"?

If (Data("License") = "Site") Then
        Me.ExecuteTest("Edition 4.0\OFA Site WebTest.tstest")
ElseIf (Data("License") = "Single") Then
        Me.ExecuteTest("Edition 4.0\OFA Single WebTest.tstest")
ElseIf (Data("License") = "Single") Then
        Me.ExecuteTest("Edition 4.0\OFA Free WebTest.tstest")
End If

Other than that I see nothing of concern with this code.

Greetings,
Cody
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
John
Top achievements
Rank 2
answered on 03 Oct 2011, 04:32 PM
Cody,
Thanks for the catch...  lol  I did catch it in execution...  :P  I changed it but did not save it...  lol  ;) 

thanks,
John

Is it Friday yet?!!?!?!!
0
Licensing
Top achievements
Rank 1
answered on 27 Jan 2016, 09:06 PM

The following is a coded step I am trying to execute. However, it seem to not being executing through the step. I have a local data bind (using telerik test studio instead of an external source). It doesn't seem to be checking the column "Action". Any help would be very useful.

if (Data["Action"] == "1" || Data["Action"]== "3")
    // Set text contents of TboxMemoCapistextbox to 'Test'
    Pages.DEVCAPISHub.SilverlightApp.TboxMemoCapistextbox.SetText(false, "Test", 10, 100, false, true);
else
    Log.CaptureBrowser(ActiveBrowser, "InvoiceActionMenu");

0
Boyan Boev
Telerik team
answered on 01 Feb 2016, 11:03 AM
Hello Capis,

Since the column values are of type string you should convert the data to string. Your code should look like:

if (Data["Action"].ToString() == "1" || Data["Action"].ToString()== "3")

Let me know if that helps.

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