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.

WindowElement.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package com.vaadin.tests.tb3.newelements;
  2. import org.openqa.selenium.WebElement;
  3. import org.openqa.selenium.interactions.Actions;
  4. import com.vaadin.testbench.By;
  5. import com.vaadin.testbench.elementsbase.ServerClass;
  6. /*
  7. Suggestions for new elemental api for Window
  8. */
  9. @ServerClass("com.vaadin.ui.Window")
  10. public class WindowElement extends com.vaadin.testbench.elements.WindowElement {
  11. private final String restoreBoxClass = "v-window-restorebox";
  12. private final String maximizeBoxClass = "v-window-maximizebox";
  13. private final String closeBoxClass = "v-window-closebox";
  14. public void restore() {
  15. if (isMaximized()) {
  16. getRestoreButton().click();
  17. } else {
  18. throw new AssertionError(
  19. "Window is not maximized, cannot be restored.");
  20. }
  21. }
  22. private boolean isMaximized() {
  23. return isElementPresent(By.className(restoreBoxClass));
  24. }
  25. private WebElement getRestoreButton() {
  26. return findElement(By.className("v-window-restorebox"));
  27. }
  28. public void maximize() {
  29. if (!isMaximized()) {
  30. getMaximizeButton().click();
  31. } else {
  32. throw new AssertionError(
  33. "Window is already maximized, cannot maximize.");
  34. }
  35. }
  36. private WebElement getMaximizeButton() {
  37. return findElement(By.className(maximizeBoxClass));
  38. }
  39. public void move(int xOffset, int yOffset) {
  40. Actions action = new Actions(getDriver());
  41. action.moveToElement(
  42. findElement(org.openqa.selenium.By.className("v-window-wrap")),
  43. 5, 5);
  44. action.clickAndHold();
  45. action.moveByOffset(xOffset, yOffset);
  46. action.release();
  47. action.build().perform();
  48. }
  49. /**
  50. * @return the caption of the window
  51. */
  52. @Override
  53. public String getCaption() {
  54. return findElement(By.className("v-window-header")).getText();
  55. }
  56. private WebElement getCloseButton() {
  57. return findElement(By.className(closeBoxClass));
  58. }
  59. public void close() {
  60. getCloseButton().click();
  61. }
  62. }