Using Coded Step as If Clause in If...Then

5 posts, 0 answers
  1. Tyler
    Tyler avatar
    4 posts
    Member since:
    Sep 2011

    Posted 25 Oct 2011 Link to this post

    Greetings,

    I am trying to create a test where certain steps of that test will only run if the browser is a certain browser.  I created a coded step to assert whether or not the browser is Fire Fox, and I was wondering if there is a way that I can use that within the built in if...then logical step included in Test Studio.  If not, is there another way that I can achieve this action?

    Thank you for any advice you can offer.

    Tyler
  2. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 26 Oct 2011 Link to this post

    Hi Tyler,

    This is easily accomplished without code or a logical step.

    Highlight a step and go to the Properties Pane. Under the "Misc" heading, locate the "RunsAgainst" property and change it to the desired browser type. 

    Best wishes,
    Anthony
    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. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 26 Oct 2011 Link to this post

    Hi Tyler,

    You can do this in code as well. See this page for an example. 

    Greetings,
    Anthony
    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
  4. Tyler
    Tyler avatar
    4 posts
    Member since:
    Sep 2011

    Posted 26 Oct 2011 Link to this post

    Thank you for the help Anthony.

    Using the RunsAgainst property option for each step worked.  With your coded solution, I have used something like that in different parts of my tests where it was a small action to be run for each browser.  The problem with that approach for my issue is I want to run approximately 5 test as steps and 10 other steps if the browser is IE, so I was hoping to be able to use the logical if...then...else option in Test Studio so I could just drag all of those steps in to the 'if'.  Not sure if this could be a possible enhancement where we can set the coded step to be recognized as a verification and then use is as part of the if...just a thought - it would be easier than having to change the property of many steps in test and easier to see what the test was doing when looking at it rather than having to click each step to see it's properties.  Either way, the initial issue I was having is solved.

    Thanks,

    Tyler
  5. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 26 Oct 2011 Link to this post

    Hi Tyler,

    I'm glad your issue is solved.

    You're correct; you cannot use a coded step for the qualifying verification in a Test Studio If/Else logical step. You can, however, use the following lines in a coded step to execute a sub-test based on browser type:

    if (ActiveBrowser.BrowserType == BrowserType.InternetExplorer)
    {
        this.ExecuteTest("Bing.tstest");
    }
    else if (ActiveBrowser.BrowserType == BrowserType.FireFox)
    {
        this.ExecuteTest("Ask.tstest");
    }
    else
    {
        throw new ApplicationException("Unknown browser type");
    }

    Kind regards,
    Anthony
    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
Back to Top