HelloWorldTests.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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;
  17. import example.pages.HomePage;
  18. import example.pages.LoginPage;
  19. import org.junit.jupiter.api.AfterEach;
  20. import org.junit.jupiter.api.BeforeEach;
  21. import org.junit.jupiter.api.Test;
  22. import org.openqa.selenium.WebDriver;
  23. import org.openqa.selenium.htmlunit.HtmlUnitDriver;
  24. /**
  25. * Test the Hello World application.
  26. *
  27. * @author Michael Simons
  28. */
  29. public class HelloWorldTests {
  30. private WebDriver driver;
  31. private int port;
  32. @BeforeEach
  33. void setup() {
  34. this.port = Integer.parseInt(System.getProperty("app.httpPort"));
  35. this.driver = new HtmlUnitDriver();
  36. }
  37. @AfterEach
  38. void tearDown() {
  39. this.driver.quit();
  40. }
  41. @Test
  42. void accessHomePageWithUnauthenticatedUserSendsToLoginPage() {
  43. final LoginPage loginPage = HomePage.to(this.driver, this.port);
  44. loginPage.assertAt();
  45. }
  46. @Test
  47. void authenticatedUserIsSentToOriginalPage() {
  48. // @formatter:off
  49. final HomePage homePage = HomePage.to(this.driver, this.port)
  50. .loginForm()
  51. .username("user")
  52. .password("password")
  53. .submit();
  54. // @formatter:on
  55. }
  56. @Test
  57. void authenticatedUserLogsOut() {
  58. // @formatter:off
  59. LoginPage loginPage = HomePage.to(this.driver, this.port)
  60. .loginForm()
  61. .username("user")
  62. .password("password")
  63. .submit()
  64. .logout();
  65. // @formatter:on
  66. loginPage.assertAt();
  67. loginPage = HomePage.to(this.driver, this.port);
  68. loginPage.assertAt();
  69. }
  70. }