Esempio n. 1
0
        public void ShouldReturnTheValueOfCheckedForACheckboxEvenIfItLacksThatAttribute()
        {
            driver.Get(formPage);
            WebElement checkbox = driver.SelectElement("//input[@id='checky']");

            Assert.AreEqual("false", checkbox.GetAttribute("checked"));
            checkbox.SetSelected();
            Assert.AreEqual("true", checkbox.GetAttribute("checked"));
        }
Esempio n. 2
0
        public virtual ElementWrapper CheckIfValue(string value, bool caseInsensitive = false, bool trimValue = true)
        {
            var    tag          = GetTagName();
            string elementValue = null;

            //input
            if (tag == "input")
            {
                elementValue = WebElement.GetAttribute("value");
            }
            //textarea
            if (tag == "textarea")
            {
                elementValue = GetInnerText();
            }

            if (trimValue)
            {
                elementValue = elementValue?.Trim();
                value        = value.Trim();
            }
            if (!string.Equals(value, elementValue,
                               caseInsensitive ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal))
            {
                throw new UnexpectedElementStateException($"Attribute contains unexpected value. Expected value: '{value}', Provided value: '{elementValue}' \r\n Element selector: {FullSelector} \r\n");
            }
            return(this);
        }
Esempio n. 3
0
        public void ShouldReturnTheValueOfTheDisabledAttrbuteEvenIfItIsMissing()
        {
            driver.Get(formPage);
            WebElement inputElement = driver.SelectElement("//input[@id='working']");

            Assert.AreEqual("false", inputElement.GetAttribute("disabled"));
        }
Esempio n. 4
0
        public void ShouldReturnEmptyAttributeValuesWhenPresentAndTheValueIsActuallyEmpty()
        {
            driver.Get(simpleTestPage);
            WebElement body = driver.SelectElement("//body");

            Assert.AreEqual("", body.GetAttribute("style"));
        }
Esempio n. 5
0
 public string GetReference()
 {
     return(Invoker.DoActionWithResult(
                "Get link reference",
                () => FindImmediately(() => WebElement.GetAttribute("href"), ""),
                href => $"Get href of link '{href}'"));
 }
Esempio n. 6
0
        public bool HasError()
        {
            WaitForDisplayed(Timeouts.Default);
            string error = WebElement.GetAttribute("aria-invalid");

            return(error.Equals("false"));
        }
        public string GetAttribute(string attributeName)
        {
            LOG.Information("Retrieving attribute {0} from element: {1}", attributeName, WebElement);
            string attribute = WebElement.GetAttribute(attributeName);

            LOG.Information("{0}: {1}", attributeName, attribute);
            return(attribute);
        }
Esempio n. 8
0
        public void IsEnabled()
        {
            string attributeDisabled = WebElement.GetAttribute("disabled");
            string messagePassed     = $"The (Button) [ {ControlName} ] is Enabled - CORRECT -.";
            string messageFailed     = $"The (Button) [ {ControlName} ] is Disabled - WRONG -, when it should by Enabled.";

            ExceptionManager.IsTrue(attributeDisabled == null, messagePassed, messageFailed);
        }
Esempio n. 9
0
        public void ShouldReturnTheEmptyStringWhenGettingTheValueOfAnAttributeThatIsNotListed()
        {
            driver.Get(simpleTestPage);
            WebElement head      = driver.SelectElement("/html");
            String     attribute = head.GetAttribute("cheese");

            Assert.AreEqual("", attribute);
        }
Esempio n. 10
0
        public void testShouldReturnValueOfClassAttributeOfAnElement()
        {
            driver.Get(xhtmlTestPage);

            WebElement heading   = driver.SelectElement("//h1");
            string     className = heading.GetAttribute("class");

            Assert.AreEqual("header", className);
        }
Esempio n. 11
0
        protected virtual string GetTextAction()
        {
            if (string.IsNullOrEmpty(WebElement.Text))
            {
                return(WebElement.GetAttribute("value") ?? string.Empty);
            }

            return(WebElement.Text);
        }
Esempio n. 12
0
 /// <summary>
 /// Clears the value of an element.
 /// </summary>
 public void Clear()
 {
     _session.Logger.WriteLine("Clearing " + this);
     if (WebElement.GetAttribute("readonly") == "true")
     {
         throw new InvalidOperationException("Cannot clear a readonly element.");
     }
     WebElement.Clear();
 }
Esempio n. 13
0
        public static string GetCssAtribute(this WebElement element)
        {
            if (element is null)
            {
                throw new System.ArgumentNullException(nameof(element));
            }

            return(element.GetAttribute("class"));
        }
Esempio n. 14
0
        public void testShouldReturnTheValueOfTheStyleAttribute()
        {
            driver.Get(formPage);

            WebElement element = driver.SelectElement("//form[3]");
            string     style   = element.GetAttribute("style");

            Assert.AreEqual("display: block", style);
        }
Esempio n. 15
0
        /// <param name="attributeName">write name of attribute to check</param>
        /// <param name="expression">define condition</param>
        /// <param name="failureMessage">When value of the element does not satisfy the condition this fail failureMessage is written to the throwen exception in the output.</param>
        /// <returns></returns>
        public virtual ElementWrapper CheckAttribute(string attributeName, Func <string, bool> expression, string failureMessage = null)
        {
            var attribute = WebElement.GetAttribute(attributeName);

            if (!expression(attribute))
            {
                throw new UnexpectedElementStateException($"Attribute '{attributeName}' contains unexpected value. Provided value: '{attribute}' \r\n Element selector: {FullSelector} \r\n {failureMessage ?? ""}");
            }
            return(this);
        }
Esempio n. 16
0
        public string Getvalue()
        {
            string Value = WebElement.Text;

            if (string.IsNullOrEmpty(Value))
            {
                Value = WebElement.GetAttribute("value");
            }
            return(Value);
        }
Esempio n. 17
0
        public bool IsExecutionTabShown(string runName)
        {
            string fullRunTitleValue = GetExecutionTabFullTitleValue(runName);

            WebElement executionFrame = mainPage.GetElement().ByXPath(Locators.runFrameXPath(fullRunTitleValue));

            string currentExecutionFrameClassValue = executionFrame.GetAttribute(WEBUIautomation.Tags.TagAttributes.Class);

            return(currentExecutionFrameClassValue == Locators.shownTabFrameClassValue);
        }
Esempio n. 18
0
        public bool IsDltShown(string testName)
        {
            string fullTitleValue = GetDltTabFullTitleValue(testName);

            WebElement dltFrame = mainPage.GetElement().ByXPath(Locators.dltIFrameXPath(fullTitleValue));

            string currentDltFrameClassValue = dltFrame.GetAttribute(WEBUIautomation.Tags.TagAttributes.Class);

            return(currentDltFrameClassValue == Locators.shownTabFrameClassValue);
        }
Esempio n. 19
0
        public string GetValue()
        {
            string attribute = WebElement.GetAttribute("value");

            string message = $"The (Text Field): [ {ControlName} ] contains the attribute value: [ {attribute} ].";

            LoggerManagerClass.Instance.Information(message);
            TestCaseProvider.Instance.AddStepInCurrentTestCase(LogStepStatus.Passed, message);

            return(attribute);
        }
Esempio n. 20
0
        /// <summary>Get attribute text from current element
        /// </summary>
        /// <param name="Attribute">Attribute to get</param>
        /// <returns>Text in named attribute</returns>
        public string GetAttribute(string Attribute)
        {
            ThrowIfUnbound();

            string returnValue = WebElement.GetAttribute(Attribute);

            if ((returnValue == null))
            {
                throw new AttributeReturnedNull(MappingDetails, Attribute);
            }
            return(returnValue);
        }
Esempio n. 21
0
        /// <summary>
        /// Find the requested element with the given attribute.
        /// Note: This requires first locating an element and then calling this.
        /// </summary>
        /// <param name="attributeName">Attribute name of the requested element.</param>
        /// <returns></returns>
        public string GetAttribute(string attributeName)
        {
            if (WebElement != null)
            {
                return(WebElement.GetAttribute(attributeName));
            }
            else
            {
                LogManager.Error($"Unable to find the attribute {attributeName} for the requested element");

                return(string.Empty);
            }
        }
Esempio n. 22
0
        public void ShouldReturnTheValueOfSelectedForOptionsInSelectsEvenIfTheyLackThatAttribute()
        {
            driver.Get(formPage);
            WebElement selectBox = driver.SelectElement("//select[@name='selectomatic']");
            IList      options   = selectBox.GetChildrenOfType("option");
            WebElement one       = (WebElement)options[0];
            WebElement two       = (WebElement)options[1];

            Assert.IsTrue(one.Selected);
            Assert.IsFalse(two.Selected);
            Assert.AreEqual("true", one.GetAttribute("selected"));
            Assert.AreEqual("false", two.GetAttribute("selected"));
        }
Esempio n. 23
0
        public void IsDisabled()
        {
            bool   isDisabled        = false;
            string attributeDisabled = WebElement.GetAttribute("disabled");

            if (attributeDisabled != null)
            {
                isDisabled = WebElement.GetAttribute("disabled").Contains("true");
            }
            string messagePassed = $"The (Button) [ {ControlName} ] is Disabled - CORRECT -.";
            string messageFailed = $"The (Button) [ {ControlName} ] is not Disabled - WRONG -, when it should by Disabled.";

            ExceptionManager.IsTrue(isDisabled, messagePassed, messageFailed);
        }
Esempio n. 24
0
        /// <summary>
        /// Returns a human-readable interpretation of the element.
        /// </summary>
        public override string ToString()
        {
            var id = WebElement.GetAttribute("id");

            if (!string.IsNullOrEmpty(id))
            {
                return("#" + id);
            }
            var text = WebElement.Text;

            if (!string.IsNullOrEmpty(text))
            {
                return("\"" + text + "\"");
            }
            return("<" + WebElement.TagName + ">");
        }
Esempio n. 25
0
        public virtual ElementWrapper CheckAttribute(string attributeName, string value, bool caseInsensitive = false, bool trimValue = true, string failureMessage = null)
        {
            var attribute = WebElement.GetAttribute(attributeName);

            if (trimValue)
            {
                attribute = attribute.Trim();
                value     = value.Trim();
            }
            if (!string.Equals(value, attribute,
                               caseInsensitive ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal))
            {
                throw new UnexpectedElementStateException(failureMessage ?? $"Attribute '{attributeName}' contains unexpected value. Expected value: '{value}', Provided value: '{attribute}' \r\n Element selector: {FullSelector} \r\n");
            }
            return(this);
        }
Esempio n. 26
0
        public virtual ElementWrapper CheckAttribute(string attributeName, string[] allowedValues, bool caseInsensitive = false, bool trimValue = true, string failureMessage = null)
        {
            var attribute = WebElement.GetAttribute(attributeName);

            if (trimValue)
            {
                attribute     = attribute.Trim();
                allowedValues = allowedValues.Select(s => s.Trim()).ToArray();
            }
            if (allowedValues.All(v => !string.Equals(v, attribute,
                                                      caseInsensitive ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal)))
            {
                throw new UnexpectedElementStateException(failureMessage ?? $"Attribute contains unexpected value. Expected value: '{string.Concat("|", allowedValues)}', Provided value: '{attribute}' \r\n Element selector: {FullSelector} \r\n");
            }
            return(this);
        }
Esempio n. 27
0
        public string GetValue()
        {
            OpenQA.Selenium.Support.UI.SelectElement seIsPrepopulated = new OpenQA.Selenium.Support.UI.SelectElement(WebElement);
            string Value;

            if (seIsPrepopulated.SelectedOption.ToString().Trim() != "")
            {
                Value = seIsPrepopulated.SelectedOption.GetAttribute("value");;
            }
            else
            {
                Value = WebElement.Text;
            }
            if (string.IsNullOrEmpty(Value))
            {
                Value = WebElement.GetAttribute("value");
            }


            return(Value);
        }
Esempio n. 28
0
        /// <summary>
        /// Checks href value of element A (hyperlink)
        /// </summary>
        /// <param name="url">Expected value of href.</param>
        /// <param name="kind">Type of url of expected href.</param>
        /// <param name="components">Determines what parts of url should be compared.</param>
        /// <returns></returns>
        public ElementWrapper CheckIfHyperLinkEquals(string url, UrlKind kind, params UriComponents[] components)
        {
            if (components.Length == 0)
            {
                components    = new UriComponents[1];
                components[0] = kind == UrlKind.Relative ? UriComponents.PathAndQuery : UriComponents.AbsoluteUri;
            }

            var providedHref = new Uri(WebElement.GetAttribute("href"));

            if (kind == UrlKind.Relative)
            {
                var host = BaseUrl;
                if (string.IsNullOrWhiteSpace(host))
                {
                    host = "http://example.com/";
                }
                else if (!host.EndsWith("/"))
                {
                    host += "/";
                }
                url = host + (url.StartsWith("/") ? url.Substring(1) : url);
            }
            if (kind == UrlKind.Absolute && url.StartsWith("//"))
            {
                url = providedHref.Scheme + ":" + url;
            }
            var           expectedHref   = new Uri(url);
            UriComponents finalComponent = components[0];

            components.ToList().ForEach(s => finalComponent |= s);

            if (Uri.Compare(providedHref, expectedHref, finalComponent, UriFormat.SafeUnescaped,
                            StringComparison.OrdinalIgnoreCase) != 0)
            {
                throw new UnexpectedElementStateException($"Link '{FullSelector}' provided value '{providedHref}' of attribute href. Provided value does not match with expected value '{url}'.");
            }

            return(this);
        }
Esempio n. 29
0
        /// <summary>
        /// Sends text to the element via keystrokes. If this element is a select element, then this selects the appropriate option instead of sending keystrokes.
        /// </summary>
        /// <param name="text">The text to send.</param>
        public void Write(string text)
        {
            _session.Logger.WriteLine("Writing " + text + " to " + this);
            if (WebElement.TagName != "select")
            {
                if (WebElement.GetAttribute("readonly") == "true")
                {
                    throw new InvalidOperationException("Cannot write to a readonly element.");
                }
                WebElement.Clear();
                WebElement.SendKeys(text);
                return;
            }

            var option = _session.FindElements(WebElement, "option[text()=" + Utility.CssString(text) + "] | option[@value=" + Utility.CssString(text) + "]").FirstOrDefault();

            if (option == null)
            {
                throw new InvalidDataException("Element " + this + " does not contain option " + text);
            }
            option.WebElement.Click();
        }
Esempio n. 30
0
        /// <summary>
        /// Reads the value or text of the element.
        /// </summary>
        public string Read()
        {
            var result = string.Empty;

            if (WebElement.TagName == "input" || WebElement.TagName == "textarea")
            {
                result = WebElement.GetAttribute("value") ?? string.Empty;
            }
            if (WebElement.TagName == "select")
            {
                var value  = WebElement.GetAttribute("value");
                var option = WebElement.FindElements(By.TagName("option")).FirstOrDefault(x => x.GetAttribute("value") == value);
                if (option != null)
                {
                    result = option.Text ?? string.Empty;
                }
            }
            if (result == string.Empty)
            {
                result = WebElement.Text ?? string.Empty;
            }
            return(result);
        }
Esempio n. 31
0
        public void GetAttribute()
        {
            var htmlNode = new HtmlNodeBuilder("<a href=\"http://www.google.com\">Google</a>").Build();

            var element = new WebElement(htmlNode, null);

            Assert.That(element.GetAttribute("href"), Is.EqualTo("http://www.google.com"));
        }