Example #1
0
        public void Selenium_ClickOnRadioButtonIntoIFrame_WithoutChangingPadding()
        {
            using (var webDriver = WebDriverHelper.CreateSession())
            {
                webDriver.ResizeWindow(SeleniumConfig.BrowserSize);
                webDriver.Navigate().GoToUrl(Path.Combine(ConfigHelper.GetCodeLocation(), _iframeWithComponents));
                var frame = webDriver.FindElement(OpenQA.Selenium.By.Id(_iframeId));
                webDriver.SwitchTo().Frame(frame);
                var element = new ByChained(By.XPath("//input[@name='sex'][@type='radio']"), By.XPath("./self::input[@value='male']"));

                var webElement = webDriver.FindElement(element);
                if (webElement.Displayed && webElement.Enabled)
                {
                    //webDriver.FindElement(element).Click();
                    var action = new Actions(webDriver);
                    action.Click(webElement).Build().Perform();
                }
                var    allElements   = webDriver.FindElements(By.XPath("//input[@name='sex'][@type='radio']"));
                string selectedValue = string.Empty;
                foreach (var el in allElements)
                {
                    if (el.Selected)
                    {
                        selectedValue = el.GetAttribute("value");
                    }
                }
                Assert.AreEqual("male", selectedValue);
            }
        }
Example #2
0
        protected static TPage GetInstance <TPage>(IWebDriver driver, string baseUrl, string expectedTitle = "") where TPage : BasePage, new()
        {
            TPage pageInstance = new TPage()
            {
                Driver  = driver,
                BaseURL = baseUrl
            };

            PageFactory.InitElements(driver, pageInstance);

            if (string.IsNullOrWhiteSpace(expectedTitle))
            {
                expectedTitle = pageInstance.DefaultTitle;
            }

            new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(5))
            .Until <OpenQA.Selenium.IWebElement>((d) =>
            {
                return(d.FindElement(ByChained.TagName("body")));
            });

            AssertIsEqual(expectedTitle, driver.Title, "Page Title");

            return(pageInstance);
        }
        /// <summary>
        /// Returns the new page instance and at the same time ensures that the
        /// page URL and the Title matches.
        /// </summary>
        /// <typeparam name="TPage"></typeparam>
        /// <param name="driver"></param>
        /// <param name="expectedTitle"></param>
        /// <param name="ignoreTitle"></param>
        /// <returns></returns>
        private static TPage GetAndAssertInstance <TPage>(IWebDriver driver, string expectedTitle = "", bool ignoreTitle = false, bool ignoreUrl = false) where TPage : PageBase, new()
        {
            TPage pageInstance = new TPage()
            {
                Driver = driver,
            };

            PageFactory.InitElements(driver, pageInstance);

            if (string.IsNullOrWhiteSpace(expectedTitle))
            {
                expectedTitle = pageInstance.DefaultTitle;
            }

            //Selenium no longer waits for page to load after 2.21
            new WebDriverWait(driver, TimeSpan.FromSeconds(Convert.ToInt32(TestConfig.DefaultTimeOutSeconds)))
            .Until(d => d.FindElement(ByChained.TagName("body")));

            if (!ignoreTitle)
            {
                bool isEqual = (expectedTitle == driver.Title);
                //Assert.IsTrue(isEqual, "Page Title");
                Assert.AreEqual(expectedTitle, driver.Title, "Page Title");
            }

            if (!ignoreUrl)
            {
                if (!driver.Title.Contains(pageInstance.Url))
                {
                    //TODO: check url HERE
                }
            }

            return(pageInstance);
        }
Example #4
0
        protected static TPage GetInstance <TPage>(IWebDriver driver, string baseUrl, string expectedTitle = "") where TPage : BasePage, new()
        {
            TPage pageInstance = new TPage()
            {
                Driver  = driver,
                BaseURL = baseUrl
            };

            PageFactory.InitElements(driver, pageInstance);

            if (string.IsNullOrWhiteSpace(expectedTitle))
            {
                expectedTitle = pageInstance.DefaultTitle;
            }

            //wait up to 5s for an actual page title since Selenium no longer waits for page to load after 2.21

            new WebDriverWait(driver, TimeSpan.FromSeconds(5))
            .Until <IWebElement>((d) => {
                return(d.FindElement(ByChained.TagName("body")));
            });

            //AssertIsEqual(expectedTitle, driver.Title, "Page Title");

            return(pageInstance);
        }
Example #5
0
        public ComponentScopeLocateResult Find(IWebElement scope, ComponentScopeLocateOptions options, SearchOptions searchOptions)
        {
            By by = By.CssSelector(string.Join(",", options.Terms));

            if (options.OuterXPath != null)
            {
                by = new ByChained(By.XPath(options.OuterXPath + "*"), by);
            }

            if (options.Index.HasValue)
            {
                var elements = scope.GetAll(by.With(searchOptions));
                if (elements.Count <= options.Index.Value)
                {
                    if (searchOptions.IsSafely)
                    {
                        return(new MissingComponentScopeLocateResult());
                    }
                    else
                    {
                        throw ExceptionFactory.CreateForNoSuchElement(by: by, searchContext: scope);
                    }
                }
                else
                {
                    return(new SequalComponentScopeLocateResult(elements[options.Index.Value], sequalStrategy));
                }
            }
            else
            {
                return(new SequalComponentScopeLocateResult(by, sequalStrategy));
            }
        }
Example #6
0
        public void Select(string value)
        {
            this.Driver.WaitForAngular();
            var radioSelector = new ByChained(this.Selector, By.CssSelector($"mat-radio-button[data-allors-radio-display='{value}'] label"));
            var radio         = this.Driver.FindElement(radioSelector);

            radio.Click();
        }
Example #7
0
            public static void FillInDropdownBox(string label, string value)
            {
                By byLocator = By.XPath(string.Format("//label[contains(., '{0}')]/following-sibling::div/div[contains(@class, 'dropdown')]", label));

                WaitAndClick(byLocator);

                byLocator = new ByChained(byLocator, By.XPath(string.Format("ul[contains(@class, 'dropdown-menu')]/li[contains(., '{0}')]", value)));
                WaitAndClick(byLocator);
            }
        private void Collapse(SelectorComponent panel)
        {
            this.Driver.WaitForAngular();

            var byChained = new ByChained(panel.Selector, By.XPath($".//mat-icon[contains(text(), 'expand_less')]"));
            var collapse  = this.Driver.FindElement(byChained);

            collapse.Click();
        }
Example #9
0
        private void DownloadStatements()
        {
            NavigateHome();
            Browser.FindElement(By.PartialLinkText("POSTFACH")).Click();
            Browser.FindElement(By.Name("trigger:postfachbutton::")).Click();

            //switch tab
            var    originalHandle = Browser.CurrentWindowHandle;
            string postfachHandle = null;

            foreach (var windowHandle in Browser.WindowHandles)
            {
                if (!windowHandle.Equals(originalHandle))
                {
                    Browser.SwitchTo().Window(windowHandle);
                    if (Browser.Title.Equals("Postfach", StringComparison.OrdinalIgnoreCase))
                    {
                        postfachHandle = windowHandle;
                    }
                    else
                    {
                        Browser.Close();
                    }
                }
            }
            Browser.SwitchTo().Window(postfachHandle);

            foreach (var file in Directory.GetFiles(DownloadPath, "*).pdf"))
            {
                File.Delete(file);
            }

            var byDate = new ByChained(By.ClassName("inboxCol2"), By.TagName("a"));

            while (Browser.FindElements(byDate).Count > 0)
            {
                var dateLink = Browser.FindElement(byDate);
                var dateText = dateLink.Text;
                var date     = DateTime.Parse(dateText);
                dateLink.Click();

                var fileName = Browser.FindElement(By.ClassName("detailCol1")).Text;
                Browser.FindElement(By.ClassName("btnDownload")).Click();

                //rename file
                var origPath = Path.Combine(DownloadPath, fileName);
                File.Move(origPath, Path.Combine(DownloadPath, date.ToString("yyyy-MM") + Path.GetExtension(origPath)));

                Browser.FindElement(By.XPath("//*[@id='deliveryActions']/input[@value='LÖSCHEN']")).Click();
                Browser.FindElement(By.Id("ja")).Click();
            }
            Browser.Close();
            Browser.SwitchTo().Window(originalHandle);
        }
        /// <summary>
        /// Creates a list of <see cref="By"/> locators based on the attributes of this member.
        /// </summary>
        /// <param name="member">The <see cref="MemberInfo"/> containing information about
        /// the member of the Page Object class.</param>
        /// <returns>A list of <see cref="By"/> locators based on the attributes of this member.</returns>
        protected static ReadOnlyCollection <By> CreateLocatorList(MemberInfo member)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member", "memeber cannot be null");
            }

            var  useSequenceAttributes = Attribute.GetCustomAttributes(member, typeof(FindsBySequenceAttribute), true);
            bool useSequence           = useSequenceAttributes.Length > 0;

            var  useFindAllAttributes = Attribute.GetCustomAttributes(member, typeof(FindsByAllAttribute), true);
            bool useAll = useFindAllAttributes.Length > 0;

            if (useSequence && useAll)
            {
                throw new ArgumentException("Cannot specify FindsBySequence and FindsByAll on the same member");
            }

            List <By> bys        = new List <By>();
            var       attributes = Attribute.GetCustomAttributes(member, typeof(FindsByAttribute), true);

            if (attributes.Length > 0)
            {
                Array.Sort(attributes);
                foreach (var attribute in attributes)
                {
                    var castedAttribute = (FindsByAttribute)attribute;
                    if (castedAttribute.Using == null)
                    {
                        castedAttribute.Using = member.Name;
                    }

                    bys.Add(CreateByInstance(castedAttribute));
                }

                if (useSequence)
                {
                    ByChained chained = new ByChained(bys.ToArray());
                    bys.Clear();
                    bys.Add(chained);
                }

                if (useAll)
                {
                    ByAll all = new ByAll(bys.ToArray());
                    bys.Clear();
                    bys.Add(all);
                }
            }

            return(bys.AsReadOnly());
        }
Example #11
0
            //
            // Static Methods
            //
            protected static ReadOnlyCollection <By> CreateLocatorList(MemberInfo member)
            {
                if (member == null)
                {
                    throw new ArgumentNullException("member", "memeber cannot be null");
                }
                Attribute[] customAttributes = Attribute.GetCustomAttributes(member, typeof(FindsBySequenceAttribute), true);
                bool        flag             = customAttributes.Length > 0;

                Attribute[] customAttributes2 = Attribute.GetCustomAttributes(member, typeof(FindsByAllAttribute), true);
                bool        flag2             = customAttributes2.Length > 0;

                if (flag && flag2)
                {
                    throw new ArgumentException("Cannot specify FindsBySequence and FindsByAll on the same member");
                }
                List <By> list = new List <By> ();

                Attribute[] customAttributes3 = Attribute.GetCustomAttributes(member, typeof(FindsByAttribute), true);
                if (customAttributes3.Length > 0)
                {
                    Array.Sort <Attribute> (customAttributes3);
                    Attribute[] array = customAttributes3;
                    for (int i = 0; i < array.Length; i++)
                    {
                        Attribute        attribute        = array [i];
                        FindsByAttribute findsByAttribute = (FindsByAttribute)attribute;
                        if (findsByAttribute.Using == null)
                        {
                            findsByAttribute.Using = member.Name;
                        }
                        list.Add(findsByAttribute.Finder);
                    }
                    if (flag)
                    {
                        ByChained item = new ByChained(list.ToArray());
                        list.Clear();
                        list.Add(item);
                    }
                    if (flag2)
                    {
                        ByAll item2 = new ByAll(list.ToArray());
                        list.Clear();
                        list.Add(item2);
                    }
                }
                return(list.AsReadOnly());
            }
        private static List <By> GetListOfComplexBys(bool useSequence, bool useAll, List <By> bys)
        {
            if (useSequence)
            {
                ByChained chained = new ByChained(bys.ToArray());
                bys.Clear();
                bys.Add(chained);
            }

            if (useAll)
            {
                ByAll all = new ByAll(bys.ToArray());
                bys.Clear();
                bys.Add(all);
            }

            return(bys);
        }
Example #13
0
        public List <By> FindVisibleElementsLocators(By parentBy, string xpathSelector)
        {
            var result  = new List <By>();
            var i       = 1;
            var by      = new ByChained(parentBy, By.XPath($"{xpathSelector}[{i}]"));
            var element = GetExistingElementOrNull(by);

            while (element != null)
            {
                if (element.Displayed)
                {
                    result.Add(by);
                }
                i++;
                by      = new ByChained(parentBy, By.XPath($"{xpathSelector}[{i}]"));
                element = GetExistingElementOrNull(by);
            }
            return(result);
        }
Example #14
0
        /// <summary>
        /// Initializes the HtmlControl (and perhaps Section in the future) members of this Page Object that
        /// have the ControlAttribute (or SectionAttribute).
        /// </summary>
        /// <param name="owner"></param>
        protected void InitElements(Page owner)
        {
            var type    = GetType();
            var members = new List <MemberInfo>();

            members.AddRange(type.GetFields(NonPublicAndFlattenedBindingOptions));
            members.AddRange(type.GetProperties(NonPublicAndFlattenedBindingOptions));

            foreach (var member in members)
            {
                var attributes = Attribute.GetCustomAttributes(member, typeof(FindsByAttribute), true)
                                 .Select(a => (FindsByAttribute)a).ToArray();

                if (attributes.Any())
                {
                    var bys = attributes.Where(a => !String.IsNullOrEmpty(a.Using))
                              .OrderBy(a => a.Priority)
                              .Select(a => CreateBy(a.How, a.Using))
                              .ToArray();
                    var by = new ByChained(bys);

                    var field    = member as FieldInfo;
                    var property = member as PropertyInfo;
                    if (field != null)
                    {
                        var T = field.FieldType;
                        field.SetValue(this, CreateInstance(T, owner, @by));
                    }
                    else if (property != null)
                    {
                        var T = property.PropertyType;
                        property.SetValue(this, CreateInstance(T, owner, @by), null);
                    }
                }
            }
        }
Example #15
0
 public object CreateInstance(Type type, Page page, ByChained @by)
 {
     return(Activator.CreateInstance(type, page, @by));
 }