How to Stop Test Execution Conditionally

4 posts, 0 answers
  1. Ken White
    Ken White avatar
    2 posts
    Member since:
    Jul 2009

    Posted 28 Jul 2010 Link to this post

    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.
  2. Missing user
    Missing user avatar

    Posted 28 Jul 2010 Link to this post

    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
  3. Jason
    Jason avatar
    14 posts
    Member since:
    Jul 2010

    Posted 01 Feb 2011 Link to this post

    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?
  4. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 04 Feb 2011 Link to this post

    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
Back to Top
  Cast Your Vote at DevPro Connections! Cast Your Vote at  Win IT Pro Connections!