Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ComboBoxAddNewItemAndResetProviderAtSameRoundTest.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package com.vaadin.tests.components.combobox;
  2. import org.junit.Test;
  3. import org.openqa.selenium.Keys;
  4. import org.openqa.selenium.interactions.Actions;
  5. import com.vaadin.testbench.By;
  6. import com.vaadin.testbench.elements.ButtonElement;
  7. import com.vaadin.testbench.elements.CheckBoxElement;
  8. import com.vaadin.testbench.elements.ComboBoxElement;
  9. import com.vaadin.testbench.elements.LabelElement;
  10. import com.vaadin.tests.tb3.SingleBrowserTest;
  11. import static org.junit.Assert.assertTrue;
  12. public class ComboBoxAddNewItemAndResetProviderAtSameRoundTest
  13. extends SingleBrowserTest {
  14. protected enum SelectionType {
  15. ENTER, TAB, CLICK_OUT;
  16. }
  17. private ComboBoxElement comboBoxElement;
  18. private LabelElement valueLabelElement;
  19. private String inputValue = "000";
  20. @Override
  21. public void setup() throws Exception {
  22. super.setup();
  23. openTestURL();
  24. waitForElementPresent(By.className("v-filterselect"));
  25. waitForElementPresent(By.id("reset-label"));
  26. waitForElementPresent(By.id("value-label"));
  27. comboBoxElement = $(ComboBoxElement.class).first();
  28. }
  29. /**
  30. * Scenario: add new item and reset the data provider in the same round,
  31. * then add the same value again with ENTER
  32. */
  33. @Test
  34. public void addNewItemAndReset_reAddWithEnter() {
  35. itemHandling(SelectionType.ENTER, inputValue);
  36. }
  37. /**
  38. * Scenario: add new item and reset the data provider in the same round,
  39. * then add the same value again with TAB
  40. */
  41. @Test
  42. public void addNewItemAndReset_reAddWithTab() {
  43. itemHandling(SelectionType.TAB, inputValue);
  44. }
  45. /**
  46. * Scenario: add new item and reset the data provider in the same round,
  47. * then add the same value again with clicking out side of the CB
  48. */
  49. @Test
  50. public void addNewItemAndReset_reAddWithClickOut() {
  51. itemHandling(SelectionType.CLICK_OUT, inputValue);
  52. }
  53. /**
  54. * Scenario: add new item and reset the data provider in the same round with
  55. * 2 seconds delay, then add the same value again with ENTER
  56. */
  57. @Test
  58. public void slowAddNewItemAndReset_reAddWithEnter() {
  59. delay(true);
  60. itemHandling(SelectionType.ENTER, inputValue);
  61. }
  62. /**
  63. * Scenario: add new item and reset the data provider in the same round with
  64. * 2 seconds delay, then add the same value again with TAB
  65. */
  66. @Test
  67. public void slowAddNewItemAndReset_reAddWithTab() {
  68. delay(true);
  69. itemHandling(SelectionType.TAB, inputValue);
  70. }
  71. /**
  72. * Scenario: add new item and reset the data provider in the same round with
  73. * 2 seconds delay, then add the same value again with clicking out side
  74. */
  75. @Test
  76. public void slowAddNewItemAndReset_reAddWithClickOut() {
  77. delay(true);
  78. itemHandling(SelectionType.CLICK_OUT, inputValue);
  79. }
  80. private void itemHandling(SelectionType selectionType, String input) {
  81. assertValueLabelText("Value Label");
  82. sendKeysToInput(input);
  83. sleep(1000);
  84. // reset the dataProvider
  85. reset();
  86. // re-add the same value and select
  87. sendKeysToInput(input);
  88. performSelect(selectionType);
  89. assertLogMessage();
  90. }
  91. private void assertLogMessage() {
  92. sleep(2000);
  93. // current test is not stable for collecting all the logs,
  94. // so that we need to do the assertion with full log and contents.
  95. assertTrue("The full log should contain the following text",
  96. getLogs().toString().contains("ComboBox value : 000"));
  97. assertTrue("The full log should contain the following text",
  98. getLogs().toString().contains("New item has been added"));
  99. assertTrue("The full log should contain the following text",
  100. getLogs().toString().contains("DataProvider has been reset"));
  101. }
  102. private void sendKeysToInput(CharSequence... keys) {
  103. new Actions(getDriver()).moveToElement(comboBoxElement).perform();
  104. comboBoxElement.sendKeys(keys);
  105. }
  106. private void performSelect(SelectionType selectionType) {
  107. switch (selectionType) {
  108. case ENTER:
  109. sendKeysToInput(Keys.ENTER);
  110. break;
  111. case TAB:
  112. sendKeysToInput(Keys.TAB);
  113. break;
  114. case CLICK_OUT:
  115. $(ButtonElement.class).id("button-for-click").click();
  116. break;
  117. }
  118. }
  119. private void assertValueLabelText(String value) {
  120. valueLabelElement = $(LabelElement.class).id("value-label");
  121. waitUntil(driver -> value.equals(valueLabelElement.getText()));
  122. }
  123. private void delay(boolean delay) {
  124. CheckBoxElement checkBox = $(CheckBoxElement.class).id("delay");
  125. if (delay != checkBox.isChecked()) {
  126. checkBox.click();
  127. }
  128. }
  129. private void reset() {
  130. $(ButtonElement.class).id("reset").click();
  131. }
  132. }