public void GivenNewUser() { window = BrowserWindow.Launch($"{TestConfig.UrlBase}/DecomposingPageObjects/Change1"); // demo: this code is duplicated in all test initialize methods // and here it is extended // demo: what happens if the navigation changes? HtmlCustom nav = new HtmlCustom(window); nav.SearchProperties.Add(HtmlControl.PropertyNames.TagName, "nav"); HtmlButton registerButton = new HtmlButton(nav); registerButton.SearchProperties.Add(HtmlButton.PropertyNames.DisplayText, "Register"); Mouse.Click(registerButton); RegistrationControlPageObject registrationControl = new RegistrationControlPageObject(window); this.newUsername = Guid.NewGuid().ToString("N"); this.newPassword = "******"; registrationControl.SetFormValues(this.newUsername, this.newPassword, this.newPassword); // demo: using the expsed button here // even though this page's tester created page objects which expose click methods Mouse.Click(registrationControl.RegisterButton); // demo: different style here, too // the page object is created in the iniailize instead of in each test this.accountSettingsPageObject = new AccountSettingsPageObject(window); }
public void ConfirmPasswordNotVisibleWhenCredentialsNotSet() { /*************** * HtmlDiv registerDiv = new HtmlDiv(this.window); * registerDiv.SearchProperties.Add(HtmlDiv.PropertyNames.Id, "registerControl", PropertyExpressionOperator.EqualTo); */ // demo: no need to search // this is a top level page and it can find itself in the window (more on this later) var registerControl = new RegistrationControlPageObject(this.window); /************* * SetFormValues(registerDiv, "a", "b", String.Empty); * SetFormValues(registerDiv, String.Empty, String.Empty, null); */ // demo: OOP style registerControl.SetFormValues("a", "b", String.Empty); registerControl.SetFormValues(String.Empty, String.Empty, null); /****************** * // demo: duplicate code definition for finding this input * HtmlEdit confirmPasswordDiv = new HtmlEdit(registerDiv); * confirmPasswordDiv.SearchProperties.Add(HtmlEdit.PropertyNames.ControlDefinition, "confirmPassword", PropertyExpressionOperator.Contains); * * // demo: who can actually read these assertions ?! * Assert.IsTrue(confirmPasswordDiv.Width == 0 && confirmPasswordDiv.Height == 0); */ // demo: no need for searching code // demo: can actually read the assertion, yay! :) #region Forshadow // demo: aaaand, as we'll see, the incorrect definition // for IsVisible has been moved into a property on the page object and out of the test #endregion Assert.IsFalse(registerControl.IsConfirmPasswordVisible); registerControl.SetFormValues("mike", null, null); Assert.IsFalse(registerControl.IsConfirmPasswordVisible); registerControl.SetFormValues(null, "pass", null); Assert.IsTrue(registerControl.IsConfirmPasswordVisible); registerControl.SetFormValues(String.Empty, null, null); Assert.IsFalse(registerControl.IsConfirmPasswordVisible); }
public void AfterRegisteringNewUser_AccountSettingsIsShown() { var registerControl = new RegistrationControlPageObject(this.window); registerControl.SetFormValues(Guid.NewGuid().ToString("N"), "pass", "pass"); HtmlDiv accountSettingsDiv = new HtmlDiv(window); accountSettingsDiv.SearchProperties.Add(HtmlDiv.PropertyNames.Id, "accountSettingsControl"); Assert.IsTrue(accountSettingsDiv.Width == 0 && accountSettingsDiv.Height == 0); // demo: the button is also exposed for clicking in the test Mouse.Click(registerControl.RegisterButton); Assert.IsFalse(accountSettingsDiv.Width == 0 && accountSettingsDiv.Height == 0); }
public void RegistrationButtonEnabledOnlyWhenFormValid() { var registerControl = new RegistrationControlPageObject(this.window); registerControl.SetFormValues("a", "b", String.Empty); registerControl.SetFormValues(String.Empty, String.Empty, null); // demo: the button was exposed to support these assertions Assert.IsTrue(registerControl.RegisterButton.TryFind()); Assert.IsFalse(registerControl.RegisterButton.Enabled); registerControl.SetFormValues("mike", null, null); Assert.IsFalse(registerControl.RegisterButton.Enabled); registerControl.SetFormValues(null, "password", null); Assert.IsFalse(registerControl.RegisterButton.Enabled); registerControl.SetFormValues(null, null, "nomatch"); Assert.IsFalse(registerControl.RegisterButton.Enabled); registerControl.SetFormValues(null, null, "password"); Assert.IsTrue(registerControl.RegisterButton.Enabled); }