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.

AbstractWidgetSetIT.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package com.vaadin.test.defaultwidgetset;
  2. import java.util.List;
  3. import org.junit.Assert;
  4. import org.junit.Before;
  5. import org.junit.Rule;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.WebElement;
  8. import org.openqa.selenium.phantomjs.PhantomJSDriver;
  9. import com.vaadin.testbench.ScreenshotOnFailureRule;
  10. import com.vaadin.testbench.TestBenchTestCase;
  11. import com.vaadin.testbench.elements.ButtonElement;
  12. import com.vaadin.testbench.elements.LabelElement;
  13. import com.vaadin.testbench.elements.TextFieldElement;
  14. public abstract class AbstractWidgetSetIT extends TestBenchTestCase {
  15. @Rule
  16. public ScreenshotOnFailureRule rule = new ScreenshotOnFailureRule(this,
  17. true);
  18. @Before
  19. public void setup() {
  20. // Screenshot rule tears down the driver
  21. setDriver(new PhantomJSDriver());
  22. }
  23. protected void testAppStartsUserCanInteract(String expectedWidgetSet) {
  24. testAppStartsUserCanInteract(expectedWidgetSet, false);
  25. }
  26. protected void testAppStartsUserCanInteract(String expectedWidgetSet,
  27. boolean debug) {
  28. String url = "http://localhost:8080";
  29. if (debug) {
  30. url += "?debug";
  31. }
  32. getDriver().get(url);
  33. TextFieldElement nameInput = $(TextFieldElement.class).first();
  34. nameInput.setValue("John Dåe");
  35. $(ButtonElement.class).first().click();
  36. Assert.assertEquals("Label shown", 2,
  37. $(LabelElement.class).all().size());
  38. Assert.assertEquals("Thanks John Dåe, it works!",
  39. $(LabelElement.class).get(1).getText());
  40. Assert.assertEquals(expectedWidgetSet,
  41. findElement(By.id("widgetsetinfo")).getText());
  42. }
  43. protected void assertNoUnknownComponentShown() {
  44. Assert.assertEquals(0,
  45. findElements(By.className("vaadin-unknown-caption")).size());
  46. }
  47. protected void assertUnknownComponentShown(String componentClass) {
  48. WebElement unknownComponentCaption = findElement(
  49. By.className("vaadin-unknown-caption"));
  50. Assert.assertTrue(unknownComponentCaption.getText().contains(
  51. "does not contain implementation for " + componentClass));
  52. }
  53. protected void assertHasDebugMessage(String message) {
  54. List<WebElement> elements = getDriver().findElements(
  55. By.xpath("//span[@class='v-debugwindow-message']"));
  56. boolean found = false;
  57. for (WebElement element : elements) {
  58. if (element.getText().contains(message)) {
  59. found = true;
  60. break;
  61. }
  62. }
  63. Assert.assertTrue(
  64. "Cannot find debug message containing '" + message + "'",
  65. found);
  66. }
  67. }