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.

TreeItemDoubleClickTest.java 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package com.vaadin.v7.tests.components.tree;
  2. import static org.hamcrest.MatcherAssert.assertThat;
  3. import org.junit.Test;
  4. import org.openqa.selenium.WebElement;
  5. import org.openqa.selenium.interactions.Actions;
  6. import com.vaadin.testbench.By;
  7. import com.vaadin.testbench.elements.ButtonElement;
  8. import com.vaadin.tests.tb3.MultiBrowserTest;
  9. public class TreeItemDoubleClickTest extends MultiBrowserTest {
  10. @Test
  11. public void test() throws InterruptedException {
  12. openTestURL();
  13. String caption = "Tree Item 2";
  14. doubleClick(getTreeNodeByCaption(caption));
  15. try {
  16. assertLogText("Double Click " + caption);
  17. } catch (AssertionError e) {
  18. // double click is flaky, try again
  19. doubleClick(getTreeNodeByCaption(caption));
  20. assertLogText("Double Click " + caption);
  21. }
  22. changeImmediate();
  23. caption = "Tree Item 3";
  24. doubleClick(getTreeNodeByCaption(caption));
  25. try {
  26. assertLogText("Double Click " + caption);
  27. } catch (AssertionError e) {
  28. // double click is flaky, try again
  29. doubleClick(getTreeNodeByCaption(caption));
  30. assertLogText("Double Click " + caption);
  31. }
  32. }
  33. private void changeImmediate() {
  34. $(ButtonElement.class).caption("Change immediate flag").first().click();
  35. assertLogText("tree.isImmediate() is now");
  36. }
  37. private WebElement getTreeNodeByCaption(String caption) {
  38. return getDriver()
  39. .findElement(By.xpath("//span[text() = '" + caption + "']"));
  40. }
  41. private void doubleClick(WebElement element) {
  42. new Actions(getDriver()).doubleClick(element).build().perform();
  43. sleep(100);
  44. }
  45. private void assertLogText(String text) {
  46. assertThat(String.format("Couldn't find text '%s' from the log.", text),
  47. logContainsText(text));
  48. }
  49. }