Exemplo n.º 1
0
        public void TestAttributeWithNoTagNameAndPropertyThrowsAnException()
        {
            var attribute = new ElementLocatorAttribute {
                Type = "submit"
            };

            LocatorBuilder.GetElementLocators(attribute);
        }
Exemplo n.º 2
0
        public void TestAttributeWithNoTagNameAndPropertyThrowsAnException()
        {
            var attribute = new ElementLocatorAttribute {
                Type = "submit"
            };

            Assert.Throws <ElementExecuteException>(() =>
                                                    LocatorBuilder.GetElementLocators(attribute));
        }
Exemplo n.º 3
0
        public void TestAttributeWithLinkTextReturnsLinkTextLocator()
        {
            var attribute = new ElementLocatorAttribute {
                Text = "Hello World"
            };

            var resultList = LocatorBuilder.GetElementLocators(attribute);

            Assert.AreEqual(1, resultList.Count);
            var item = resultList.First();

            Assert.AreEqual(By.LinkText("Hello World"), item);
        }
Exemplo n.º 4
0
        public void TestAttributeWithCssClassReturnsCssClassLocator()
        {
            var attribute = new ElementLocatorAttribute {
                Class = ".something"
            };

            var resultList = LocatorBuilder.GetElementLocators(attribute);

            Assert.AreEqual(1, resultList.Count);
            var item = resultList.First();

            Assert.AreEqual(By.ClassName(".something"), item);
        }
Exemplo n.º 5
0
        public void TestAttributeWithNameReturnsNameLocator()
        {
            var attribute = new ElementLocatorAttribute {
                Name = "MyName"
            };

            var resultList = LocatorBuilder.GetElementLocators(attribute);

            Assert.AreEqual(1, resultList.Count);
            var item = resultList.First();

            Assert.AreEqual(By.Name("MyName"), item);
        }
Exemplo n.º 6
0
        public void TestAttributeWithIdReturnsCssSelectorLocator()
        {
            var attribute = new ElementLocatorAttribute {
                CssSelector = "div#MyId"
            };

            var resultList = LocatorBuilder.GetElementLocators(attribute);

            Assert.AreEqual(1, resultList.Count);
            var item = resultList.First();

            Assert.AreEqual(By.CssSelector("div#MyId"), item);
        }
Exemplo n.º 7
0
        public void TestAttributeWithTagNameAndTypeAndTitleReturnsCompoundXPathLocator()
        {
            var attribute = new ElementLocatorAttribute {
                TagName = "input", Type = "email", Title = "my title"
            };

            var resultList = LocatorBuilder.GetElementLocators(attribute);

            Assert.AreEqual(1, resultList.Count);
            var item = resultList.First();

            Assert.AreEqual(By.XPath("//input[@title='my title' and @type='email']"), item);
        }
Exemplo n.º 8
0
        public void TestAttributeWithTagNameAndTypeAndIndexReturnsComplexXPathLocator()
        {
            var attribute = new ElementLocatorAttribute {
                TagName = "input", Type = "email", Index = 1
            };

            var resultList = LocatorBuilder.GetElementLocators(attribute);

            Assert.AreEqual(1, resultList.Count);
            var item = resultList.First();

            Assert.AreEqual(By.XPath("(//input[@type='email'])[0]"), item);
        }
Exemplo n.º 9
0
        public void TestAttributeWithLinkAreaTagAndUrlReturnsXPathLocator()
        {
            var attribute = new ElementLocatorAttribute {
                TagName = "area", Url = "mylink.htm"
            };

            var resultList = LocatorBuilder.GetElementLocators(attribute);

            Assert.AreEqual(1, resultList.Count);
            var item = resultList.First();

            Assert.AreEqual(By.XPath("//area[@href='mylink.htm']"), item);
        }
Exemplo n.º 10
0
        public void TestAttributeWithImageTagAndUrlReturnsXPathLocator()
        {
            var attribute = new ElementLocatorAttribute {
                TagName = "img", Url = "myimage.png"
            };

            var resultList = LocatorBuilder.GetElementLocators(attribute);

            Assert.AreEqual(1, resultList.Count);
            var item = resultList.First();

            Assert.AreEqual(By.XPath("//img[@src='myimage.png']"), item);
        }
Exemplo n.º 11
0
        public void TestAttributeWithIdReturnsIdLocator()
        {
            var attribute = new ElementLocatorAttribute {
                Id = "MyId"
            };

            var resultList = LocatorBuilder.GetElementLocators(attribute);

            Assert.AreEqual(1, resultList.Count);
            var item = resultList.First();

            Assert.AreEqual(By.Id("MyId"), item);
        }
Exemplo n.º 12
0
        public void TestAttributeWithXPathReturnsXPathLocator()
        {
            var attribute = new ElementLocatorAttribute {
                XPath = ".//[@element='row']"
            };

            var resultList = LocatorBuilder.GetElementLocators(attribute);

            Assert.AreEqual(1, resultList.Count);
            var item = resultList.First();

            Assert.AreEqual(By.XPath(".//[@element='row']"), item);
        }
Exemplo n.º 13
0
        public void TestAttributeWithTagNameAndAltReturnsXPathLocator()
        {
            var attribute = new ElementLocatorAttribute {
                TagName = "input", Alt = "test"
            };

            var resultList = LocatorBuilder.GetElementLocators(attribute);

            Assert.AreEqual(1, resultList.Count);
            var item = resultList.First();

            Assert.AreEqual(By.XPath("//input[@alt='test']"), item);
        }
Exemplo n.º 14
0
        public void TestAttributeWithTagNameReturnsTagLocator()
        {
            var attribute = new ElementLocatorAttribute {
                TagName = "input"
            };

            var resultList = LocatorBuilder.GetElementLocators(attribute);

            Assert.AreEqual(1, resultList.Count);
            var item = resultList.First();

            Assert.AreEqual(By.TagName("input"), item);
        }
Exemplo n.º 15
0
        public void TestAttributeWithIdAndTagNameReturnsTwoLocators()
        {
            var attribute = new ElementLocatorAttribute {
                Id = "MyId", TagName = "a"
            };

            var resultList = LocatorBuilder.GetElementLocators(attribute);

            Assert.AreEqual(2, resultList.Count);

            var item = resultList.First();

            Assert.AreEqual(By.Id("MyId"), item);

            var item2 = resultList.Last();

            Assert.AreEqual(By.TagName("a"), item2);
        }
Exemplo n.º 16
0
        private void CompileLocator()
        {
            try
            {
                m_compiledLocatorLock.EnterWriteLock();

                SetApplicablePlugins();
                ResolveConstructors();

                m_factories = new Dictionary <string, Func <IServiceLocator, object> >();

                foreach (var record in m_records)
                {
                    if (record.Factory != null)
                    {
                        m_factories[record.Factory.Name] = record.Factory.Factory;
                    }

                    if (record.ConstructorParameters != null)
                    {
                        foreach (var param in record.ConstructorParameters.Where(p => p.ValueProvider != null))
                        {
                            m_factories[param.ValueProvider.Name] = param.ValueProvider.Factory;
                        }
                    }
                }

                var cplr = new Compiler();
                var bdr  = new LocatorBuilder();
                bdr.BuildLocatorCode(m_records, cplr);

                var code = cplr.ToString();

                try
                {
                    var assembly = cplr.Compile();

                    var factoryType = assembly.GetTypes().FirstOrDefault(i => typeof(ILocatorFactory).IsAssignableFrom(i));
                    if (factoryType == null)
                    {
                        throw new InvalidOperationException("No Servicelocator compiled");
                    }

                    var ctor = factoryType.GetConstructors().FirstOrDefault();
                    if (ctor == null)
                    {
                        throw new InvalidOperationException("Compiled locator doesn't have expected constructor");
                    }

                    m_locatorFactory = (ILocatorFactory)ctor.Invoke(new object[] { m_parent?.GetLocator(), m_factories });

                    foreach (var listener in m_generatorListeners)
                    {
                        listener.OnContainerGenerated(code, false, null);
                    }
                }
                catch (Exception ex)
                {
                    foreach (var listener in m_generatorListeners)
                    {
                        listener.OnContainerGenerated(code, true, ex);
                    }

                    throw;
                }
            }
            finally
            {
                m_compiledLocatorLock.ExitWriteLock();
            }
        }