Throw exception back to test studio

4 posts, 0 answers
  1. Alex
    Alex avatar
    24 posts
    Member since:
    Aug 2010

    Posted 10 Nov 2011 Link to this post

    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();
        }
    }
  2. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 14 Nov 2011 Link to this post

    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.
  3. Alex
    Alex avatar
    24 posts
    Member since:
    Aug 2010

    Posted 15 Nov 2011 Link to this post

    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?
  4. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 15 Nov 2011 Link to this post

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