Example #1
0
 /// <summary>
 /// Triggers the element via the Angular function "trigger".
 /// </summary>
 protected void TriggerElement()
 {
     if (Browser.JavascriptLibraries.Contains(JavaScriptLibrary.Angular))
     {
         Browser.ExecuteScript("angular.element(document.querySelector('#" + Id + "')).triggerHandler('input');", false);
     }
 }
Example #2
0
        /// <summary>
        /// Sets an attribute value by the provided name.
        /// </summary>
        /// <param name="name"> The name of the attribute to write. </param>
        /// <param name="value"> The value to be written. </param>
        public void SetAttributeValue(string name, string value)
        {
            name  = _propertiesToRename.ContainsKey(name) ? _propertiesToRename[name] : name;
            value = value.Replace("\r", "\\r")
                    .Replace("\n", "\\n");

            var script = "TestR.setElementValue('" + Id + "','" + name + "','" + value + "')";

            Browser.ExecuteScript(script);
            AddOrUpdateElementAttribute(name, value);
            TriggerElement();
        }
Example #3
0
        /// <summary>
        /// Fires an event on the element.
        /// </summary>
        /// <param name="eventName"> The events name to fire. </param>
        /// <param name="eventProperties"> The properties for the event. </param>
        public void FireEvent(string eventName, Dictionary <string, string> eventProperties)
        {
            var values = eventProperties.Aggregate("", (current, item) => current + ("{ key: '" + item.Key + "', value: '" + item.Value + "'},"));

            if (values.Length > 0)
            {
                values = values.Remove(values.Length - 1, 1);
            }

            var script = "TestR.triggerEvent(document.getElementById('" + Id + "'), '" + eventName.ToLower() + "', [" + values + "]);";

            Browser.ExecuteScript(script);
        }
Example #4
0
        /// <summary>
        /// Gets an attribute value by the provided name.
        /// </summary>
        /// <param name="name"> The name of the attribute to read. </param>
        /// <param name="refresh"> A flag to force the element to refresh. </param>
        /// <returns> The attribute value. </returns>
        public string GetAttributeValue(string name, bool refresh)
        {
            string value;

            if (refresh)
            {
                name = _propertiesToRename.ContainsKey(name) ? _propertiesToRename[name] : name;
                var script = "TestR.getElementValue('" + Id + "','" + name + "')";
                value = Browser.ExecuteScript(script);
            }
            else
            {
                value = GetCachedAttribute(name);
            }

            if (string.IsNullOrWhiteSpace(value))
            {
                return(string.Empty);
            }

            SetElementAttributeValue(name, value);
            return(value);
        }
Example #5
0
 /// <summary>
 /// Gets Raw Html.
 /// </summary>
 public string Html()
 {
     return(Browser.ExecuteScript("document.getElementById('" + Id + "').innerHTML"));
 }
Example #6
0
 /// <summary>
 /// Focuses on the element.
 /// </summary>
 public void Focus()
 {
     Browser.ExecuteScript("document.getElementById('" + Id + "').focus()");
 }
Example #7
0
 /// <summary>
 /// Clicks the element.
 /// </summary>
 public void Click()
 {
     Browser.ExecuteScript("document.getElementById('" + Id + "').click()");
 }