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.

EditableModeChangeTest.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.table;
  17. import static org.junit.Assert.assertEquals;
  18. import java.io.IOException;
  19. import java.util.List;
  20. import org.junit.Test;
  21. import org.openqa.selenium.By;
  22. import org.openqa.selenium.WebElement;
  23. import org.openqa.selenium.interactions.Actions;
  24. import com.vaadin.testbench.TestBenchElement;
  25. import com.vaadin.testbench.elements.TableElement;
  26. import com.vaadin.tests.tb3.MultiBrowserTest;
  27. /**
  28. * Tests that editing and selecting work correctly.
  29. *
  30. * @author Vaadin Ltd
  31. */
  32. public class EditableModeChangeTest extends MultiBrowserTest {
  33. @Test
  34. public void testNotification() throws IOException, InterruptedException {
  35. openTestURL();
  36. TableElement table = $(TableElement.class).first();
  37. // check original value
  38. TestBenchElement cell_1_0 = table.getCell(1, 0);
  39. assertEquals(
  40. "original value not found, wrong cell or contents (1st column of the 2nd row expected)",
  41. "Teppo", cell_1_0.getText());
  42. // double-click to edit cell contents
  43. cell_1_0.click();
  44. new Actions(getDriver()).doubleClick(cell_1_0).build().perform();
  45. sleep(100);
  46. // fetch the updated cell
  47. WebElement textField = table.getCell(1, 0).findElement(
  48. By.className("v-textfield"));
  49. assertEquals(
  50. "original value not found, wrong cell or contents (1st column of the 2nd row expected)",
  51. "Teppo", textField.getAttribute("value"));
  52. // update value
  53. textField.clear();
  54. textField.sendKeys("baa");
  55. // click on another row
  56. table.getCell(0, 1).click();
  57. // check the value got updated correctly
  58. assertEquals(
  59. "updated value not found, wrong cell or contents (1st column of the 2nd row expected)",
  60. "baa", table.getCell(1, 0).getText());
  61. // check that selection got updated correctly
  62. List<WebElement> selected = table.findElement(
  63. By.className("v-table-body")).findElements(
  64. By.className("v-selected"));
  65. assertEquals(1, selected.size());
  66. WebElement content = selected.get(0).findElement(
  67. By.className("v-table-cell-wrapper"));
  68. assertEquals(
  69. "expected value not found, wrong cell or contents (1st column of the 1st row expected)",
  70. "Teemu", content.getText());
  71. compareScreen("selection");
  72. }
  73. }