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.

JSPIntegrationIT.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package com.vaadin.tests.integration;
  2. import com.vaadin.testbench.TestBenchTestCase;
  3. import org.junit.After;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.WebElement;
  8. import org.openqa.selenium.phantomjs.PhantomJSDriver;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11. import static org.junit.Assert.assertEquals;
  12. import static org.junit.Assert.assertNotEquals;
  13. public class JSPIntegrationIT extends TestBenchTestCase {
  14. private static final String URL_PREFIX = "http://localhost:8080/";
  15. private static final String primaryUIUrl = URL_PREFIX + "primaryui";
  16. private static final String jspUrl = URL_PREFIX + "staticfiles/vaadinsessions.jsp";
  17. private static final String secondaryUIUrl = URL_PREFIX + "secondaryui";
  18. @Test
  19. public void listVaadinSessions() {
  20. assertUICount(0);
  21. // Open a new UI
  22. getDriver().navigate().to(primaryUIUrl);
  23. assertUICount(1);
  24. UIData firstUI = getUIs().get(0);
  25. // Open a new UI
  26. getDriver().navigate().to(primaryUIUrl);
  27. UIData secondUI = getUIs().get(0);
  28. // Should now have UI for the same service with different uiId
  29. assertUICount(1);
  30. assertNotEquals(firstUI.uiId, secondUI.uiId);
  31. assertEquals(firstUI.serviceName, secondUI.serviceName);
  32. getDriver().navigate().to(secondaryUIUrl);
  33. // Should now have another services
  34. List<UIData> twoUIs = getUIs();
  35. assertEquals(2, twoUIs.size());
  36. assertNotEquals(twoUIs.get(0).serviceName, twoUIs.get(1).serviceName);
  37. }
  38. private static class UIData {
  39. private String serviceName;
  40. private int uiId;
  41. }
  42. private List<UIData> getUIs() {
  43. List<UIData> uis = new ArrayList<UIData>();
  44. getDriver().get(jspUrl);
  45. List<WebElement> rows = getDriver()
  46. .findElements(By.xpath("//tr[@class='uirow']"));
  47. for (WebElement row : rows) {
  48. UIData data = new UIData();
  49. List<WebElement> tds = row.findElements(By.xpath("./td"));
  50. data.serviceName = tds.get(0).getText();
  51. data.uiId = Integer.parseInt(tds.get(2).getText());
  52. uis.add(data);
  53. }
  54. return uis;
  55. }
  56. private void assertUICount(int i) {
  57. assertEquals(i, getUIs().size());
  58. }
  59. @Before
  60. public void setup() {
  61. setDriver(new PhantomJSDriver());
  62. }
  63. @After
  64. public void teardown() {
  65. getDriver().quit();
  66. }
  67. }