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.

GridLayoutAlignmentsTest.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.vaadin.tests.components.gridlayout;
  2. import static org.junit.Assert.assertEquals;
  3. import org.junit.Test;
  4. import org.openqa.selenium.Point;
  5. import com.vaadin.testbench.elements.ButtonElement;
  6. import com.vaadin.testbench.elements.GridLayoutElement;
  7. import com.vaadin.testbench.elements.NativeButtonElement;
  8. import com.vaadin.tests.tb3.MultiBrowserTest;
  9. public class GridLayoutAlignmentsTest extends MultiBrowserTest {
  10. private NativeButtonElement targetButton;
  11. private Point gridLayoutLocation;
  12. private int middleY = 400 / 2 - 30 / 2;
  13. private int middleX = middleY;
  14. private int bottomX = 400 - 30;
  15. private int bottomY = bottomX;
  16. @Override
  17. protected boolean requireWindowFocusForIE() {
  18. return true;
  19. }
  20. @Test
  21. public void setAlignment() {
  22. openTestURL();
  23. targetButton = $(NativeButtonElement.class).first();
  24. GridLayoutElement gridLayout = $(GridLayoutElement.class).first();
  25. gridLayoutLocation = gridLayout.getLocation();
  26. assertOffset(middleX, middleY);
  27. $(ButtonElement.class).caption("Align top, left").first().click();
  28. assertOffset(0, 0);
  29. $(ButtonElement.class).caption("Align middle, left").first().click();
  30. assertOffset(0, middleY);
  31. $(ButtonElement.class).caption("Align bottom, left").first().click();
  32. assertOffset(0, bottomY);
  33. $(ButtonElement.class).caption("Align top, center").first().click();
  34. assertOffset(middleX, 0);
  35. $(ButtonElement.class).caption("Align middle, center").first().click();
  36. assertOffset(middleX, middleY);
  37. $(ButtonElement.class).caption("Align bottom, center").first().click();
  38. assertOffset(middleX, bottomY);
  39. $(ButtonElement.class).caption("Align top, right").first().click();
  40. assertOffset(bottomX, 0);
  41. $(ButtonElement.class).caption("Align middle, right").first().click();
  42. assertOffset(bottomX, middleY);
  43. $(ButtonElement.class).caption("Align bottom, right").first().click();
  44. assertOffset(bottomX, bottomY);
  45. }
  46. private void assertOffset(int x, int y) {
  47. Point location = targetButton.getLocation();
  48. int offsetX = location.x - gridLayoutLocation.x;
  49. int offsetY = location.y - gridLayoutLocation.y;
  50. // Border: 1px
  51. x++;
  52. y++;
  53. assertEquals("X offset incorrect", x, offsetX);
  54. assertEquals("Y offset incorrect", y, offsetY);
  55. }
  56. }