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.

SliderHandleBaseClickTest.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package com.vaadin.tests.components.slider;
  2. import com.vaadin.tests.tb3.MultiBrowserTest;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. import org.openqa.selenium.By;
  6. import org.openqa.selenium.WebElement;
  7. import org.openqa.selenium.interactions.Actions;
  8. import static org.junit.Assert.assertEquals;
  9. public class SliderHandleBaseClickTest extends MultiBrowserTest {
  10. private WebElement base;
  11. private int offsetStep;
  12. @Before
  13. public void setUp() throws Exception {
  14. super.setup();
  15. openTestURL();
  16. base = findElement(By.className("v-slider-base"));
  17. offsetStep = base.getSize().getWidth() / 10;
  18. }
  19. @Test
  20. public void testHandlerHasMoved() {
  21. // dragAndDropBy function starts calculating click position from the
  22. // middle of the component .
  23. // So the click will always be at the position (center + offsetStep)px
  24. // Will move by one from the middle
  25. new Actions(driver).dragAndDropBy(base, offsetStep, 0).perform();
  26. sleep(100);
  27. assertEquals("The Slider value should be 6 after moving by one offset",
  28. 6, getSliderValue(), 0);
  29. // Will move by two from the middle, in this case from 5
  30. new Actions(driver).dragAndDropBy(base, offsetStep * 2, 0).perform();
  31. sleep(100);
  32. assertEquals("The Slider value should be 7 after moving by two offsets",
  33. 7, getSliderValue(), 0);
  34. }
  35. private double getSliderValue() {
  36. return Double.valueOf(
  37. findElement(By.className("v-slider-feedback")).getText());
  38. }
  39. @Test
  40. public void testHandlerNotMoved() {
  41. // Disable click event handling
  42. findElement(By.id("toggleHandling")).click();
  43. new Actions(driver).dragAndDropBy(base, offsetStep, 0).perform();
  44. sleep(100);
  45. assertEquals(String.format(
  46. "Slider value should not have changed. Expected 3.0 , but was %f",
  47. getSliderValue()), 3.0,getSliderValue(), 0.0);
  48. // Enable click event handling
  49. findElement(By.id("toggleHandling")).click();
  50. }
  51. }