locked
Using Debug Selection Closes My Browser RRS feed

  • Question

  • There is probably a simple solution to this, but I have not found it.

    I have several Coded UI tests for different screens of a web application.  If I try to run one independently using Debug mode and breakpoints, it always closes my browser prior to execution.  Using Run mode works fine, but I need to step through the code so what am I doing wrong?

    I do not use TestInitialize and TestCleanup.

    Thank you!

    Friday, June 17, 2011 6:40 PM

All replies

  • Can you include the source code for your test method where you are hitting the issue?

    Which OS are you on?

    Which edition of VS are you using?

    Saturday, June 25, 2011 9:23 AM
    Moderator
  • Thank you for replying!

    OS:  Windows Server 2008 R2

    VS edition: VS2010 Ultimate

    Okay, here is a very simple example.  Both of these methods run fine by themselves in run mode or when put into an ordered test (or executed from Test Manager.)  Only when I run in debug mode does the browser close prior to the method being executed. 

    It makes me believe I've messed up a setting in VS or an update has corrupted VS as I used to be able to debug without the browser closing.  Maybe associating a test method with a data source is causing an issue?  I also must add that my ordered test ends of being quite long and debugging the whole thing takes a very long time.  That is why I want to run all the test methods in Run mode to set up my data then only use the debug mode for the test method I want to step through.

    I have highlighted, in red, where I set my breakpoint in the second test method.

     

     

    Test method 1:

     

    using System;

    using System.Collections.Generic;

    using System.Text.RegularExpressions;

    using System.Windows.Input;

    using System.Windows.Forms;

    using System.Drawing;

    using Microsoft.VisualStudio.TestTools.UITesting;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using Microsoft.VisualStudio.TestTools.UITest.Extension;

    using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;

     

     

    namespace AUT

    {

        /// <summary>

        /// Summary description for Login

        /// </summary>

        [CodedUITest]

        public class Login

        {

            public Login()

            {

            }

     

            [DataSource("Microsoft.VisualStudio.TestTools.DataSource.TestCase", "http://tfs-dev-01:8080/tfs/graebel;BusinessApplications", "1804", DataAccessMethod.Sequential), TestMethod]

            public void LoginMethod()

            {

                // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.

                // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463

     

                DateTime time = DateTime.Now;

                string logdate = time.ToString("yyyyMMdd");

                string path = "C:\\Logs\\" + logdate + ".txt";

     

                //Log message

                string logMessage = ("Start of Test!");

                this.UIMap.myTextWriterAppendWithDate(path, logMessage);

     

               

                this.UIMap.OpenBrowser();

                this.UIMap.GoToURLParams.UIInternetExplorerEnhaWindowUrl = TestContext.DataRow["URL"].ToString();

                this.UIMap.GoToURL();

                this.UIMap.EnteremailemailParams.UIM_tbUsernameEditText = TestContext.DataRow["email"].ToString();

                this.UIMap.Enteremailemail();

                this.UIMap.EnterpasswordpasswordParams.UIM_tbPasswordEditPassword = Playback.EncryptText(TestContext.DataRow["password"].ToString());

                this.UIMap.Enterpasswordpassword();

                this.UIMap.ClicktheLoginbutton();

                this.UIMap.AssertBulletinBoard();

     

               

            }

     

            #region Additional test attributes

     

            // You can use the following additional attributes as you write your tests:

     

            ////Use TestInitialize to run code before running each test

            //[TestInitialize()]

            //public void MyTestInitialize()

            //{       

            //    // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.

            //    // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463

            //}

     

            ////Use TestCleanup to run code after each test has run

            //[TestCleanup()]

            //public void MyTestCleanup()

            //{       

            //    // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.

            //    // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463

            //}

     

            #endregion 

     

            /// <summary>

            ///Gets or sets the test context which provides

            ///information about and functionality for the current test run.

            ///</summary>

            public TestContext TestContext

            {

                get

                {

                    return testContextInstance;

                }

                set

                {

                    testContextInstance = value;

                }

            }

            private TestContext testContextInstance;

     

            public UIMap UIMap

            {

                get

                {

                    if ((this.map == null))

                    {

                        this.map = new UIMap();

                    }

     

                    return this.map;

                }

            }

     

            private UIMap map;

        }

    }

     

     

    Test method 2:

     

    using System;

    using System.Collections.Generic;

    using System.Text.RegularExpressions;

    using System.Windows.Input;

    using System.Windows.Forms;

    using System.Drawing;

    using Microsoft.VisualStudio.TestTools.UITesting;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using Microsoft.VisualStudio.TestTools.UITest.Extension;

    using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;

     

     

    namespace AUT

    {

        /// <summary>

        /// Summary description for PrimaryCustomer

        /// </summary>

        [CodedUITest]

        public class PrimaryCustomer

        {

            public PrimaryCustomer()

            {

            }

     

            [DataSource("Microsoft.VisualStudio.TestTools.DataSource.TestCase", "http://tfs-dev-01:8080/tfs/graebel;BusinessApplications", "3339", DataAccessMethod.Sequential), TestMethod]

            public void PrimaryCustomerMethod()

            {

     

     

                //Click Relocations link

                this.UIMap.ClicktheRelocationslinkfromtheleftnavigationpane();

     

                //Click Add New Relocation link

                this.UIMap.ClicktheAddnewRelocationlink(); <-- Breakpoint set here! 

     

                this.UIMap.ClickthePrimaryCustomersearchbutton();

     

                this.UIMap.EntercustnameParams.UIM_relocationCustomerEditText = TestContext.DataRow["custname"].ToString();

                this.UIMap.Entercustname();

                this.UIMap.SelectcustcountryfromtheCountrydropdownlistParams.UIM_relocationCustomerComboBoxSelectedItem = TestContext.DataRow["custcountry"].ToString();

                this.UIMap.SelectcustcountryfromtheCountrydropdownlist();

                this.UIMap.ClicktheSearchbutton();

     

               

               //Can use to find EXACT name or company number

                //string custname = "5490";

                string FullCompName = TestContext.DataRow["FullCompName"].ToString();

                UIMap.ClickCell(FullCompName);

     

                           

            }

     

            #region Additional test attributes

     

            // You can use the following additional attributes as you write your tests:

     

            ////Use TestInitialize to run code before running each test

            //[TestInitialize()]

            //public void MyTestInitialize()

            //{       

            //    // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.

            //    // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463

            //}

     

            ////Use TestCleanup to run code after each test has run

            //[TestCleanup()]

            //public void MyTestCleanup()

            //{       

            //    // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.

            //    // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463

            //}

     

            #endregion 

     

            /// <summary>

            ///Gets or sets the test context which provides

            ///information about and functionality for the current test run.

            ///</summary>

            public TestContext TestContext

            {

                get

                {

                    return testContextInstance;

                }

                set

                {

                    testContextInstance = value;

                }

            }

            private TestContext testContextInstance;

     

            public UIMap UIMap

            {

                get

                {

                    if ((this.map == null))

                    {

                        this.map = new UIMap();

                    }

     

                    return this.map;

                }

            }

     

            private UIMap map;

        }

    }

     

     

     


    • Edited by I Have a Name Monday, June 27, 2011 3:18 PM Added information.
    Monday, June 27, 2011 2:46 PM