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.

PushStateAndReplaceStateTest.java 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package com.vaadin.tests.components.ui;
  2. import static org.junit.Assert.assertEquals;
  3. import java.net.URI;
  4. import org.junit.Test;
  5. import org.openqa.selenium.WebDriver;
  6. import org.openqa.selenium.support.ui.ExpectedCondition;
  7. import com.vaadin.testbench.By;
  8. import com.vaadin.tests.tb3.MultiBrowserTest;
  9. public class PushStateAndReplaceStateTest extends MultiBrowserTest {
  10. @Test
  11. public void testUriFragment() throws Exception {
  12. driver.get(getTestUrl());
  13. assertUri(getTestUrl());
  14. hitButton("test");
  15. assertUri(getTestUrl() + "/test");
  16. driver.navigate().back();
  17. driver.findElement(By.className("v-Notification")).getText()
  18. .contains("Popstate event");
  19. assertUri(getTestUrl());
  20. hitButton("test");
  21. URI base = new URI(getTestUrl() + "/test");
  22. hitButton("X");
  23. URI current = base.resolve("X");
  24. driver.findElement(By.xpath("//*[@id = 'replace']/input")).click();
  25. hitButton("root_X");
  26. current = current.resolve("/X");
  27. assertUri(current.toString());
  28. // Now that last change was with replace state, two back calls should go
  29. // to initial
  30. driver.navigate().back();
  31. driver.navigate().back();
  32. assertUri(getTestUrl());
  33. }
  34. private void assertUri(String uri) {
  35. final String expectedText = "Current Location: " + uri;
  36. waitUntil(new ExpectedCondition<Boolean>() {
  37. @Override
  38. public Boolean apply(WebDriver input) {
  39. return expectedText.equals(getLocationLabelValue());
  40. }
  41. });
  42. assertEquals(uri, driver.getCurrentUrl());
  43. }
  44. private String getLocationLabelValue() {
  45. String text = vaadinElementById("locationLabel").getText();
  46. return text;
  47. }
  48. }