HomePage.java 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2002-2018 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * https://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package example.pages;
  17. import org.openqa.selenium.WebDriver;
  18. import org.openqa.selenium.WebElement;
  19. import org.openqa.selenium.support.FindBy;
  20. import org.openqa.selenium.support.PageFactory;
  21. import static org.assertj.core.api.Assertions.assertThat;
  22. /**
  23. * The home page.
  24. *
  25. * @author Michael Simons
  26. */
  27. public class HomePage {
  28. private final WebDriver webDriver;
  29. @FindBy(css = "p")
  30. private WebElement message;
  31. @FindBy(css = "input[type=submit]")
  32. private WebElement logoutButton;
  33. public static LoginPage to(WebDriver driver, int port) {
  34. driver.get("http://localhost:" + port + "/");
  35. return PageFactory.initElements(driver, LoginPage.class);
  36. }
  37. public HomePage(WebDriver webDriver) {
  38. this.webDriver = webDriver;
  39. }
  40. public Content assertAt() {
  41. assertThat(this.webDriver.getTitle()).isEqualTo("Hello Security");
  42. return PageFactory.initElements(this.webDriver, Content.class);
  43. }
  44. public LoginPage logout() {
  45. this.logoutButton.submit();
  46. return PageFactory.initElements(this.webDriver, LoginPage.class);
  47. }
  48. public static class Content {
  49. @FindBy(css = "p")
  50. private WebElement message;
  51. public Content andTheUserNameIsDisplayed() {
  52. assertThat(this.message.getText()).isEqualTo("Hello user");
  53. return this;
  54. }
  55. }
  56. }