You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NavigatorViewBlocksBackButtonActionTest.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * 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, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.navigator;
  17. import static org.junit.Assert.assertEquals;
  18. import java.util.List;
  19. import org.junit.Test;
  20. import org.openqa.selenium.By;
  21. import org.openqa.selenium.WebElement;
  22. import org.openqa.selenium.remote.DesiredCapabilities;
  23. import com.vaadin.testbench.elements.ButtonElement;
  24. import com.vaadin.tests.tb3.MultiBrowserTest;
  25. public class NavigatorViewBlocksBackButtonActionTest extends MultiBrowserTest {
  26. @Override
  27. public List<DesiredCapabilities> getBrowsersToTest() {
  28. // IE web driver fails to read fragment properly, these must be tested
  29. // manually. See
  30. // https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/7966
  31. return getBrowsersExcludingIE();
  32. }
  33. @Test
  34. public void testIfConfirmBack() {
  35. openTestURL();
  36. // keep URL of main view
  37. final String initialUrl = driver.getCurrentUrl();
  38. // do it 2 times to verify that login is not broken after first time
  39. for (int i = 0; i < 2; i++) {
  40. // go to prompted view
  41. WebElement button = $(ButtonElement.class).first();
  42. button.click();
  43. // click back button
  44. driver.navigate().back();
  45. // confirm "go back by clicking confirm button
  46. WebElement buttonConfirmView = $(ButtonElement.class).first();
  47. buttonConfirmView.click();
  48. // verify we are in main view and url is correct
  49. waitForElementPresent(By
  50. .id(NavigatorViewBlocksBackButtonAction.LABEL_MAINVIEW_ID));
  51. String currentUrl = driver.getCurrentUrl();
  52. assertEquals("Current URL should be equal to initial main view URL",
  53. initialUrl, currentUrl);
  54. }
  55. }
  56. @Test
  57. public void testIfCancelBack() {
  58. openTestURL();
  59. // go to prompted view
  60. WebElement button = $(ButtonElement.class).first();
  61. button.click();
  62. // keep URL of prompted view
  63. final String initialPromptedUrl = driver.getCurrentUrl();
  64. // click back button
  65. driver.navigate().back();
  66. // verify url is correct (is not changed)
  67. waitForElementPresent(By
  68. .id(NavigatorViewBlocksBackButtonAction.LABEL_PROMPTEDVIEW_ID));
  69. String currentUrl = driver.getCurrentUrl();
  70. assertEquals("Current URL should be equal to initial prompted view URL",
  71. initialPromptedUrl, currentUrl);
  72. WebElement cancelButton = driver
  73. .findElement(By.className("v-window-closebox"));
  74. // click cancel button
  75. cancelButton.click();
  76. // verify we leave in prompted view and url is correct
  77. waitForElementPresent(By
  78. .id(NavigatorViewBlocksBackButtonAction.LABEL_PROMPTEDVIEW_ID));
  79. currentUrl = driver.getCurrentUrl();
  80. assertEquals("Current URL should be equal to initial prompted view URL",
  81. initialPromptedUrl, currentUrl);
  82. }
  83. }