Esempio n. 1
0
        private void AssertCorrectSelectorAttributeUsageForControl(SimplePageForTest page)
        {
            this.WebDriver.Stub(x => x.FindElement(this.GetByCriteria(TestSelector))).Return(this.WebElement);
            this.WebElement.Stub(x => x.Text).Return("table text");
            var tableControl = this.GetTableControl(page);

            tableControl.Text.Should().Be("table text");
            tableControl.Should().NotBeSameAs(this.GetTableControl(page));
        }
        protected T GetPropertyValue <T>(SimplePageForTest page, string propertyName)
        {
            var buttonProperty = page.GetType().GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            if (buttonProperty == null)
            {
                Assert.Fail("Page '{0}' does not cointain property '{1}' which required for the tests.".F(page.GetType().FullName, propertyName));
            }

            return((T)buttonProperty.GetValue(page, null));
        }
Esempio n. 3
0
        private void AssertCorrectSelectorAttributeUsage(SimplePageForTest page)
        {
            this.WebElement.Stub(x => x.TagName).Return("button");
            this.WebDriver.Stub(x => x.FindElement(this.GetByCriteria(TestSelector))).Return(this.WebElement);
            this.WebElement.Stub(x => x.Text).Return("abcd");

            var button = this.GetButton(page);

            button.Text.Should().Be("abcd");
            button.Should().NotBeSameAs(this.GetButton(page));
        }
Esempio n. 4
0
        public void AllPublicPropertiesCheckIfPageHasBeenInitialized()
        {
            var page = new SimplePageForTest();
            var properties = typeof(BasePage).GetProperties(BindingFlags.Instance | BindingFlags.Public);

            foreach (var propertyInfo in properties)
            {
                var info = propertyInfo;
                var exception = Assert.Throws<TargetInvocationException>(() => info.GetValue(page, null));
                exception.InnerException.Should().BeOfType<PageInitializationException>("because page was initialized incorrect.");
            }
        }
Esempio n. 5
0
        public void AllPublicPropertiesCheckIfPageHasBeenInitialized()
        {
            var page       = new SimplePageForTest();
            var properties = typeof(BasePage).GetProperties(BindingFlags.Instance | BindingFlags.Public);

            foreach (var propertyInfo in properties)
            {
                var info      = propertyInfo;
                var exception = Assert.Throws <TargetInvocationException>(() => info.GetValue(page, null));
                exception.InnerException.Should().BeOfType <PageInitializationException>("because page was initialized incorrect.");
            }
        }
Esempio n. 6
0
        public void AllPublicMethodsCheckIfPageHasBeenInitialized()
        {
            var publicMethodCallExpressions = new Expression<Action<BasePage>>[]
                {
                    x => x.ExecuteScript("return 1;"),
                    x => x.ExecuteAsyncScript("return 2;"),
                    x => x.FindElement(By.Id("start")),
                    x => x.FindElements(By.ClassName("end"))
                };
            var page = new SimplePageForTest();
            var methods = typeof(BasePage).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
                .Where(x => !x.IsSpecialName);
            var coveredMethods = publicMethodCallExpressions.Select(x => x.Body).Cast<MethodCallExpression>().Select(x => x.Method.Name);
            var uncoveredMethods = methods.Where(x => !coveredMethods.Contains(x.Name)).Select(x => x.Name).ToArray();

            Assert.IsEmpty(uncoveredMethods, "'{0}' methods does not covered. Please add expressions to test them.", string.Join(", ", uncoveredMethods));
            foreach (var publicMethodCallExpression in publicMethodCallExpressions)
            {
                Assert.Throws<PageInitializationException>(() => publicMethodCallExpression.Compile()(page));
            }
        }
Esempio n. 7
0
        public void AllPublicMethodsCheckIfPageHasBeenInitialized()
        {
            var publicMethodCallExpressions = new Expression <Action <BasePage> >[]
            {
                x => x.ExecuteScript("return 1;"),
                x => x.ExecuteAsyncScript("return 2;"),
                x => x.FindElement(By.Id("start")),
                x => x.FindElements(By.ClassName("end"))
            };
            var page    = new SimplePageForTest();
            var methods = typeof(BasePage).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
                          .Where(x => !x.IsSpecialName);
            var coveredMethods   = publicMethodCallExpressions.Select(x => x.Body).Cast <MethodCallExpression>().Select(x => x.Method.Name);
            var uncoveredMethods = methods.Where(x => !coveredMethods.Contains(x.Name)).Select(x => x.Name).ToArray();

            Assert.IsEmpty(uncoveredMethods, "'{0}' methods does not covered. Please add expressions to test them.", string.Join(", ", uncoveredMethods));
            foreach (var publicMethodCallExpression in publicMethodCallExpressions)
            {
                Assert.Throws <PageInitializationException>(() => publicMethodCallExpression.Compile()(page));
            }
        }
Esempio n. 8
0
 private TableControl GetTableControl(SimplePageForTest page, string propertyName = "TableControl")
 {
     return(this.GetPropertyValue <TableControl>(page, propertyName));
 }
Esempio n. 9
0
 private SelectElement GetSelect(SimplePageForTest page)
 {
     return(this.GetPropertyValue <SelectElement>(page, "Select"));
 }
Esempio n. 10
0
 private ButtonElement GetButton(SimplePageForTest page)
 {
     return(this.GetPropertyValue <ButtonElement>(page, "Button"));
 }
Esempio n. 11
0
        private void AssertCorrectSelectorAttributeUsageForControl(SimplePageForTest page)
        {
            this.WebDriver.Stub(x => x.FindElement(this.GetByCriteria(TestSelector))).Return(this.WebElement);
            this.WebElement.Stub(x => x.Text).Return("table text");
            var tableControl = this.GetTableControl(page);

            tableControl.Text.Should().Be("table text");
            tableControl.Should().NotBeSameAs(this.GetTableControl(page));
        }
Esempio n. 12
0
        private void AssertCorrectSelectorAttributeUsage(SimplePageForTest page)
        {
            this.WebElement.Stub(x => x.TagName).Return("button");
            this.WebDriver.Stub(x => x.FindElement(this.GetByCriteria(TestSelector))).Return(this.WebElement);
            this.WebElement.Stub(x => x.Text).Return("abcd");

            var button = this.GetButton(page);

            button.Text.Should().Be("abcd");
            button.Should().NotBeSameAs(this.GetButton(page));
        }
Esempio n. 13
0
 private TableControl GetTableControl(SimplePageForTest page, string propertyName = "TableControl")
 {
     return this.GetPropertyValue<TableControl>(page, propertyName);
 }
Esempio n. 14
0
 private SelectElement GetSelect(SimplePageForTest page)
 {
     return this.GetPropertyValue<SelectElement>(page, "Select");
 }
Esempio n. 15
0
 private ButtonElement GetButton(SimplePageForTest page)
 {
     return this.GetPropertyValue<ButtonElement>(page, "Button");
 }