Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

ComboBoxTestBenchPerformanceTest.java 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package com.vaadin.tests.components.combobox;
  2. import static org.hamcrest.MatcherAssert.assertThat;
  3. import static org.hamcrest.number.IsCloseTo.closeTo;
  4. import org.junit.Test;
  5. import org.openqa.selenium.Keys;
  6. import com.vaadin.testbench.elements.ComboBoxElement;
  7. import com.vaadin.tests.tb3.SingleBrowserTest;
  8. public class ComboBoxTestBenchPerformanceTest extends SingleBrowserTest {
  9. /**
  10. * TestBench timeout is 20s, require 15s to make sure cluster load won't
  11. * affect the result badly.
  12. */
  13. private static final double TIME_LIMIT = 15000d;
  14. @Test
  15. public void testSelectionPerformance() throws Exception {
  16. openTestURL();
  17. long before = System.currentTimeMillis();
  18. setComboBoxValue("abc123"); // new
  19. long after = System.currentTimeMillis();
  20. assertThat((double) after - before, closeTo(0d, TIME_LIMIT));
  21. before = System.currentTimeMillis();
  22. setComboBoxValue("11"); // existing (2nd page)
  23. after = System.currentTimeMillis();
  24. assertThat((double) after - before, closeTo(0d, TIME_LIMIT));
  25. before = System.currentTimeMillis();
  26. setComboBoxValue("abc123"); // previously added (3rd page)
  27. after = System.currentTimeMillis();
  28. assertThat((double) after - before, closeTo(0d, TIME_LIMIT));
  29. }
  30. public void setComboBoxValue(final String value) {
  31. ComboBoxElement combobox = $(ComboBoxElement.class).first();
  32. if (combobox.getPopupSuggestions().contains(value)) {
  33. // Select existing item
  34. combobox.selectByText(value);
  35. } else {
  36. // Enter new item
  37. combobox.clear();
  38. combobox.sendKeys(value);
  39. combobox.sendKeys(Keys.ENTER);
  40. }
  41. // Make sure Vaadin is ready before leaving the method
  42. testBench().waitForVaadin();
  43. }
  44. }