Data driven If statement

11 posts, 0 answers
  1. John
    John avatar
    8 posts
    Member since:
    Jul 2012

    Posted 30 Sep 2011 Link to this post

    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

  2. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 30 Sep 2011 Link to this post

    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
  3. John
    John avatar
    8 posts
    Member since:
    Jul 2012

    Posted 30 Sep 2011 Link to this post

    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
  4. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 30 Sep 2011 Link to this post

    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
  5. John
    John avatar
    8 posts
    Member since:
    Jul 2012

    Posted 01 Oct 2011 Link to this post

    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
  6. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 03 Oct 2011 Link to this post

    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
  7. John
    John avatar
    8 posts
    Member since:
    Jul 2012

    Posted 03 Oct 2011 Link to this post

    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
  8. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 03 Oct 2011 Link to this post

    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
  9. John
    John avatar
    8 posts
    Member since:
    Jul 2012

    Posted 03 Oct 2011 Link to this post

    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?!!?!?!!
  10. Licensing
    Licensing avatar
    11 posts
    Member since:
    Dec 2011

    Posted 27 Jan Link to this post

    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");

  11. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 01 Feb Link to this post

    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!
Back to Top