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

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

4 Answers 112 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tyler
Top achievements
Rank 1
Tyler asked on 25 Oct 2011, 08:02 PM
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

4 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 26 Oct 2011, 06:16 PM
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
0
Anthony
Telerik team
answered on 26 Oct 2011, 08:16 PM
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
0
Tyler
Top achievements
Rank 1
answered on 26 Oct 2011, 09:28 PM
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
0
Anthony
Telerik team
answered on 26 Oct 2011, 10:54 PM
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
Tags
General Discussions
Asked by
Tyler
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Tyler
Top achievements
Rank 1
Share this question
or