Example #1
0
        /// <summary>
        /// Navigates to the element through the given path, reads
        /// </summary>
        /// <param name="parentnode"></param>
        /// <param name="path">Member name path to the control starting at the main control</param>
        /// <returns>IHTMLElement wrapper</returns>
        private static HTMLElement GetHTMLElement(this IIE inst, Control parentnode, string path)
        {
            if (ControlRootExtension.GetRoot() == null)
            {
                throw new InvalidOperationException("IE tests must run in the w3wp.exe address space");
            }
            var control = GetControl(inst, ControlRootExtension.GetRoot(), path);

            return(GetHTMLElement(inst, control.ClientID));
        }
Example #2
0
 /// <summary>
 /// [OneTimeSetUp]
 /// </summary>
 public static void SetUpDatabase(this IIE inst)
 {
     using (var db = new ASP_DBEntities())
     {
         var sql = @"
             SELECT ISNULL(MAX(mainid), 0)
             FROM Main
             ";
         max_mainid = db.Database.SqlQuery <long>(sql).FirstOrDefault();
     }
 }
Example #3
0
 /// <summary>
 /// [OneTimeTearDown]
 /// </summary>
 public static void TearDownDatabase(this IIE inst)
 {
     using (var db = new ASP_DBEntities())
     {
         var sql   = @"
             DELETE FROM Main
             WHERE mainid > @max_mainid
         ";
         var param = new SqlParameter("max_mainid", max_mainid);
         db.Database.ExecuteSqlCommand(sql, param);
     }
 }
Example #4
0
        private static Control GetControl(this IIE inst, Control parentnode, IEnumerable <string> fields)
        {
            var fieldname = fields.First();
            var node      = (Control)parentnode.GetType().GetField(fieldname, BindingFlags.Instance | BindingFlags.NonPublic).GetValue(parentnode);

            if (fields.Count() == 1) // Base case: return the terminal node
            {
                return(node);
            }
            else // walk down the object tree
            {
                return(GetControl(inst, node, fields.Skip(1)));
            }
        }
Example #5
0
        /// <summary>
        /// Select the item with the given value from the input element
        /// collection with the given name and wait for the response when
        /// expectPostBack is true.
        /// </summary>
        /// <param name="name">name attribute of the element</param>
        /// <param name="value">value of the item to click on</param>
        /// <param name="expectPostBack">Whether to expect a server request from the click. Defaults to false</param>
        /// <param name="expectedStatusCode">Expected StatusCode of the response</param>
        /// <param name="delay">Optional delay time in milliseconds before clicking the element</param>
        /// <param name="pause">Optional pause time in milliseconds after IE claims DocumentComplete</param>
        public static void Select(this IIE inst, string name, string value, bool expectPostBack = false, int expectedStatusCode = 200, int delay = 0, int pause = 0)
        {
            var list = IEExtensionBase.GetHTMLElements(name);

            if (list == null)
            {
                throw new Exception(String.Format("No HTML input elements with name = found", name));
            }
            for (int idx = 0; idx <= list.Count; idx++)
            {
                if (idx == list.Count)
                {
                    throw new Exception(String.Format("HTML input element '{0}': value '{1}' not found", name, value));
                }
                else if (list[idx].getAttribute("value") == value)
                {
                    Click(inst, name, idx, expectPostBack, expectedStatusCode, delay, pause);
                    break;
                }
            }
        }
Example #6
0
        /// <summary>
        /// Select the item with the given value from a ListControl and wait for the response
        /// when expectPostBack is true.
        /// </summary>
        /// <param name="path">Member name path to the control starting at the main control</param>
        /// <param name="value">value of the item to click on</param>
        /// <param name="expectPostBack">Whether to expect a server request from the click. Defaults to false</param>
        /// <param name="expectedStatusCode">Expected StatusCode of the response</param>
        /// <param name="delay">Optional delay time in milliseconds before clicking the element</param>
        /// <param name="pause">Optional pause time in milliseconds after IE claims DocumentComplete</param>
        public static void Select(this IIE inst, string path, string value, bool expectPostBack = false, int expectedStatusCode = 200, int delay = 0, int pause = 0)
        {
            var list = GetControl(inst, path) as ListControl;

            if (list == null)
            {
                throw new Exception(String.Format("ListControl at '{0}' not found", path));
            }
            for (int idx = 0; idx <= list.Items.Count; idx++)
            {
                if (idx == list.Items.Count)
                {
                    throw new Exception(String.Format("ListControl at '{0}': value '{1}' not found", path, value));
                }
                else if (list.Items[idx].Value == value)
                {
                    string itemID = String.Format("{0}_{1}", list.ClientID, idx);
                    ClickID(inst, itemID, expectPostBack, expectedStatusCode, delay, pause);
                    break;
                }
            }
        }
Example #7
0
 /// <summary>
 /// [OneTimeSetUp]
 /// Start Internet Explorer and set up events
 /// </summary>
 public static void SetUpIE(this IIE inst)
 {
     IEExtensionBase.SetUpIE();
 }
Example #8
0
        /// <summary>
        /// Recursively walk down the path starting at the MainControl instance  and return
        /// the Control instance there.
        /// </summary>
        /// <param name="path">Member name path to the control starting at the main control</param>
        /// <returns></returns>
        private static Control GetControl(this IIE inst, Control parentnode, string path)
        {
            var fields = path.Split('.');

            return(GetControl(inst, parentnode, fields));
        }
Example #9
0
 /// <summary>
 /// Get the element adapter with the given clientID
 /// </summary>
 /// <param name="clientID">ClientID resp. HTML id attribute of the element</param>
 /// <returns>IHTMLElement wrapper</returns>
 public static HTMLElement GetHTMLElement(this IIE inst, string clientID)
 {
     return(IEExtensionBase.GetHTMLElement(clientID));
 }
Example #10
0
 /// <summary>
 /// Write into the HTML element (usually a text input) with the given clientID
 /// </summary>
 /// <param name="clientId">HTML id attribute of the element to click on</param>
 /// <param name="text">Text to write</param>
 public static void WriteID(this IIE inst, string clientId, string text)
 {
     IEExtensionBase.WriteID(clientId, text);
 }
Example #11
0
        /// <summary>
        /// Click the ASP.NET control element (usually a Button instance) with the given clientID and wait for the response
        /// when expectPostBack is true.
        /// </summary>
        /// <param name="clientId">HTML id attribute of the element to click on</param>
        /// <param name="expectPostBack">Whether to expect a server request from the click</param>
        /// <param name="expectedStatusCode">Expected StatusCode of the response</param>
        /// <param name="delay">Optional delay time in milliseconds before clicking the element</param>
        /// <param name="pause">Optional pause time in milliseconds after IE claims DocumentComplete</param>
        public static void ClickID(this IIE inst, string clientId, bool expectPostBack = true, int expectedStatusCode = 200, int delay = 0, int pause = 0)
        {
            var button = GetHTMLElement(inst, clientId);

            IEExtensionBase.Click(button, expectPostBack, expectedStatusCode, delay, pause);
        }
Example #12
0
        /// <summary>
        /// Click the ASP.NET control element (usually a Button instance) at the given path and wait for the response
        /// when expectPostBack is true.
        /// </summary>
        /// <param name="path">Member name path to the control starting at the main control</param>
        /// <param name="expectPostBack">Whether to expect a server request from the click</param>
        /// <param name="expectedStatusCode">Expected StatusCofe of the response</param>
        /// <param name="delay">Optional delay time in milliseconds before clicking the element</param>
        /// <param name="pause">Optional pause time in milliseconds after IE claims DocumentComplete</param>
        public static void Click(this IIE inst, string path, bool expectPostBack = true, int expectedStatusCode = 200, int delay = 0, int pause = 0)
        {
            var button = GetHTMLElement(inst, ControlRootExtension.GetRoot(), path);

            IEExtensionBase.Click(button, expectPostBack, expectedStatusCode, delay, pause);
        }
Example #13
0
 /// <summary>
 /// Get the HTML document body of the current document in Internet Explorer
 /// </summary>
 /// <returns> HTML document body</returns>
 public static string Html(this IIE inst)
 {
     return(IEExtensionBase.Html());
 }
Example #14
0
 /// <summary>
 /// Click the HTML element (usually a Button) with the given clientID
 /// and wait for the response when expectPostBack is true.
 /// </summary>
 /// <param name="clientId">HTML id attribute of the element to click on</param>
 /// <param name="expectPostBack">Whether to expect a server request from the click</param>
 /// <param name="expectedStatusCode">Expected StatusCode of the response</param>
 /// <param name="delay">Optional delay time in milliseconds before clicking the element</param>
 /// <param name="pause">Optional pause time in milliseconds after IE claims DocumentComplete</param>
 public static void ClickID(this IIE inst, string clientId, bool expectPostBack = true, int expectedStatusCode = 200, int delay = 0, int pause = 0)
 {
     IEExtensionBase.ClickID(clientId, expectPostBack, expectedStatusCode, delay, pause);
 }
Example #15
0
 /// <summary>
 /// Click the HTML element (usually a Button) with the given name and
 /// index and wait for the response when expectPostBack is true.
 /// </summary>
 /// <param name="name">name attribute of the element</param>
 /// <param name="index">Index of the element collection with that name, defaults to 0</param>
 /// <param name="expectPostBack">Whether to expect a server request from the click</param>
 /// <param name="expectedStatusCode">Expected StatusCofe of the response</param>
 /// <param name="delay">Optional delay time in milliseconds before clicking the element</param>
 /// <param name="pause">Optional pause time in milliseconds after IE claims DocumentComplete</param>
 public static void Click(this IIE inst, string name, int index = 0, bool expectPostBack = true, int expectedStatusCode = 200, int delay = 0, int pause = 0)
 {
     IEExtensionBase.ClickName(name, index, expectPostBack, expectedStatusCode, delay, pause);
 }
Example #16
0
 /// <summary>
 /// [OneTimeTearDown]
 /// Quit Internet Explorer
 /// </summary>
 public static void TearDownIE(this IIE inst)
 {
     IEExtensionBase.TearDownIE();
 }
Example #17
0
        /// <summary>
        /// Write into the ASP.NET control (usually a TextBox instance) at the given path
        /// </summary>
        /// <param name="path">Member name path to the control starting at the main control</param>
        /// <param name="text">Text to write</param>
        public static void Write(this IIE inst, string path, string text)
        {
            var input = GetHTMLElement(inst, ControlRootExtension.GetRoot(), path);

            input.setAttribute("value", text);
        }
Example #18
0
 /// <summary>
 /// Returns the ASP.NET control instance at the given path
 /// </summary>
 /// <param name="path">Member name path to the control starting at the main control</param>
 /// <returns>ASP.NET control</returns>
 public static Control GetControl(this IIE inst, string path)
 {
     return(GetControl(inst, ControlRootExtension.GetRoot(), path));
 }
Example #19
0
 /// <summary>
 /// Asynchronously issue a GET request for the specified absolute path at
 /// http://127.0.0.1 as "localhost" seems to never reach OnDocumentComplete.
 /// This requires changing the binding in .\.vs\config\applicationhost.config to
 /// <binding protocol="http" bindingInformation="*:51333:127.0.0.1" />
 /// Wait for the response for AppSettings["RequestTimeout"] seconds.
 /// </summary>
 /// <param name="path">URL path</param>
 /// <param name="expectedStatusCode">Expected StatusCofe of the response</param>
 /// <param name="delay">Optional delay time in milliseconds before clicking the element</param>
 /// <param name="pause">Optional pause time in milliseconds after IE claims DocumentComplete</param>
 public static void Navigate(this IIE inst, string path, int expectedStatusCode = 200, int delay = 0, int pause = 0)
 {
     IEExtensionBase.Navigate(path, expectedStatusCode, delay, pause);
 }
Example #20
0
 /// <summary>
 /// Write into the HTML element (usually a text input) with the given clientID
 /// </summary>
 /// <param name="name">name attribute of the element</param>
 /// <param name="text">Text to write</param>
 /// <param name="index">Index of the element collection with that name, defaults to 0</param>
 public static void Write(this IIE inst, string name, string text, int index = 0)
 {
     IEExtensionBase.WriteName(name, text, index);
 }