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

How to Stop Test Execution Conditionally

3 Answers 226 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ken White
Top achievements
Rank 1
Ken White asked on 28 Jul 2010, 08:42 PM
We have a test that creates a web site using our proprietary tool. The test works great and includes a step to check to see if the website exists first and if not, to create it. If the web site already exists we mark the test as failed (and the rest of the test stops on Failure).

Now however, we'd like to do the same thing but not mark it as a failure if the website already exists. But we still want it to stop execution of the test.

So basically: Does site exist? If No, then create it. If Yes, then stop (but don't call it 'failed' just stop).

Here is the code we were using when we were calling it a failure, (this code works).
[CodedStep(@"Be sure site does not already exist")]
public void CreateNewTemplateSite_CodedStep()
{
    ActiveBrowser.RefreshDomTree();
    List<HtmlSpan> elements = new List<HtmlSpan>(ActiveBrowser.Find.AllByCustom<HtmlSpan>
        (x => x.InnerText == Data["NewSiteName"].ToString()));
    if (elements.Count != 0)
        Assert.Fail(string.Concat("Template site already exists: ", Data["NewSiteName"].ToString()));
}

What do we replace the Assert.Fail with that will successfully stop the test while still marking it "passed"?

Thanks for the help.

3 Answers, 1 is accepted

Sort by
0
Missing User
answered on 28 Jul 2010, 09:46 PM
Hi Ken,

Thanks for the post and question. From what I can tell, there really isn't anything that will end the test in one line in the state that you are looking for. I'll log a feature request for this though.

In the meantime, instead of the Assert.Fail, you can loop through the remaining test steps and disable them as in:

for(int i = this.ExecutionContext.CurrentStep.Order + 1; i < this.ExecutionContext.Test.Steps.Count; i++)
this.ExecutionContext.Test.Steps[i].Enabled = false;

This should Pass all steps already executed and mark steps after this as Not Executed.

Best wishes,
Nelson Sin
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
Jason
Top achievements
Rank 2
answered on 01 Feb 2011, 09:24 PM
Nelson,

I believe I can use the code snippet you provided - I have a data-driven test that I want to fail and stop execution on given the absence of a certain condition.  If I use the above code to loop through each remaining step and disable it so it doesn't run, will they remain disabled when the next iteration of the test runs?
0
Stoich
Telerik team
answered on 04 Feb 2011, 03:29 PM
Hello Jason,
     sounds like what you need is an If/Else statements. Check out this video:
http://tv.telerik.com/watch/automated-testing-tools/conditional-logic-ifelse-statement-webui-test-studio
This feature was made available in our Q3 release.

This feature only works for UI Verificaiton Conditions. For other types for conditions you will need to write your own custom if/else statement in code.

Let me know if you have any questions on this!

All the best,
Stoich
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
Tags
General Discussions
Asked by
Ken White
Top achievements
Rank 1
Answers by
Missing User
Jason
Top achievements
Rank 2
Stoich
Telerik team
Share this question
or