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

Throw exception back to test studio

3 Answers 118 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.
Alex
Top achievements
Rank 1
Alex asked on 10 Nov 2011, 03:53 PM
I'm doing a POC for using Test Studio integrated with WatiN. I've got most of the way there I'm running into issues where I'm trying to pass an exception back to the test studio. In order to use WatiN with Test Studio I need to for the browser into STA mode and in order to do that I need to setup a delegate. In side the delegate I'm having trouble taking the assert failure and passing it back to test studio. Do you have any suggestions?

public class WebTest1 : BaseWebAiiTest
{
    #region [ Dynamic Pages Reference ]
 
    private Pages _pages;
 
    /// <summary>
    /// Gets the Pages object that has references
    /// to all the elements, frames or regions
    /// in this project.
    /// </summary>
    public Pages Pages
    {
        get
        {
            if (_pages == null)
            {
                _pages = new Pages(Manager.Current);
            }
            return _pages;
        }
    }
 
    #endregion
 
    [CodedStep("WatiN Test")]
    public void WatiNTest()
    {
        ForceSTA(() =>
        {               
            using (var browser = WatiN.Core.Browser.AttachTo<IE>(WatiN.Core.Find.ByUrl("about:blank")))
            {
                browser.GoTo("http://www.google.com");
                browser.TextField(WatiN.Core.Find.ByName("q")).TypeText("WatiN");
                browser.Button(WatiN.Core.Find.ByName("btnG")).Click();
                Assert.IsTrue(browser.ContainsText("WatiNg"));
            }
        });
    }
 
    private void ForceSTA(Action action)
    {
        Thread staThread = new Thread(new ThreadStart(
            delegate
            {                   
                try
                {
                    action.Invoke();
                }
                catch (Exception)
                {
                    Log.WriteLine("Fail");                       
                }
        
            }));
 
        staThread.SetApartmentState(ApartmentState.STA);
        staThread.Start();
        staThread.Join();
    }
}

3 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 14 Nov 2011, 09:45 PM
Hello Alex,

Sorry but I have to ask why are you trying to mix Test Studio with WatiN? Those are like two competing (and not compatible) frameworks.

It's also unclear to us exactly what the problem is and how we can help. I'm looking for Test Studio code in your code sample, but don't see any (beyond creating a Pages object which doesn't really do anything). What is "action.Invoke()"?

All the best,
Cody
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Alex
Top achievements
Rank 1
answered on 15 Nov 2011, 08:37 PM
Understandable question Cody,

My company utilizies a number of different automation solutions. We are trying to narrow it to one or two. We have a considerable investment (man hours) in WatiN and don't want to lose that.

The sample included is a coded step that can be run from Test Studio Express (not sure about stand alone). Your right that this is more specific to C# developement than Test Studio code. The action.invoke() points back to the lamba expression ForceSTA(() => . This is used to wrap the watin execution in STA mode. I was more curious about what causes a step in test studio to fail. Does this system pass back an exception which is what triggers the step failure or is there another method?
0
Cody
Telerik team
answered on 15 Nov 2011, 11:57 PM
Hi Alex,

Yes, our test runner has a generic try catch block that triggers Test Studio to log a test failure using this approach:

try
{
    // Loop through each test step in the test
}
catch (Exception)
{
    // Abort the test, log the failure, move on to next test in test list
}

Thus to force a test to fail, just thrown an exception, any exception. This is what our Assert class does.

Does that help?

Greetings,
Cody
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Alex
Top achievements
Rank 1
Answers by
Cody
Telerik team
Alex
Top achievements
Rank 1
Share this question
or