IndexPage.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright 2002-2017 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. * http://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 sample.webdriver;
  17. import org.openqa.selenium.WebDriver;
  18. import org.openqa.selenium.WebElement;
  19. import org.openqa.selenium.support.PageFactory;
  20. import static org.assertj.core.api.Assertions.assertThat;
  21. /**
  22. * @author Rob Winch
  23. * @since 5.0
  24. */
  25. public class IndexPage {
  26. private WebDriver driver;
  27. private WebElement logout;
  28. public IndexPage(WebDriver webDriver) {
  29. this.driver = webDriver;
  30. }
  31. public static <T> T to(WebDriver driver, int port, Class<T> page) {
  32. driver.get("http://localhost:" + port +"/");
  33. return (T) PageFactory.initElements(driver, page);
  34. }
  35. public IndexPage assertAt() {
  36. assertThat(this.driver.getTitle()).isEqualTo("Secured");
  37. return this;
  38. }
  39. public LoginPage logout() {
  40. this.logout.click();
  41. return LoginPage.create(this.driver);
  42. }
  43. }