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)); }
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)); }
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."); } }
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."); } }
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)); } }
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)); } }
private TableControl GetTableControl(SimplePageForTest page, string propertyName = "TableControl") { return(this.GetPropertyValue <TableControl>(page, propertyName)); }
private SelectElement GetSelect(SimplePageForTest page) { return(this.GetPropertyValue <SelectElement>(page, "Select")); }
private ButtonElement GetButton(SimplePageForTest page) { return(this.GetPropertyValue <ButtonElement>(page, "Button")); }
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)); }
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)); }
private TableControl GetTableControl(SimplePageForTest page, string propertyName = "TableControl") { return this.GetPropertyValue<TableControl>(page, propertyName); }
private SelectElement GetSelect(SimplePageForTest page) { return this.GetPropertyValue<SelectElement>(page, "Select"); }
private ButtonElement GetButton(SimplePageForTest page) { return this.GetPropertyValue<ButtonElement>(page, "Button"); }