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.

VerticalLayoutFocusWithDOMChangesTest.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.orderedlayout;
  17. import java.util.List;
  18. import org.junit.Assert;
  19. import org.junit.Test;
  20. import org.openqa.selenium.WebElement;
  21. import org.openqa.selenium.interactions.Actions;
  22. import org.openqa.selenium.remote.DesiredCapabilities;
  23. import com.vaadin.testbench.By;
  24. import com.vaadin.testbench.parallel.BrowserUtil;
  25. import com.vaadin.tests.tb3.MultiBrowserTest;
  26. public class VerticalLayoutFocusWithDOMChangesTest extends MultiBrowserTest {
  27. private String initialText = "Some";
  28. private String incrementalText = " text";
  29. @Test
  30. public void inputTextAndChangeFocus() throws InterruptedException {
  31. openTestURL();
  32. List<WebElement> textFields = getDriver().findElements(
  33. By.tagName("input"));
  34. WebElement tf1 = textFields.get(0);
  35. WebElement tf2 = textFields.get(1);
  36. tf1.sendKeys(initialText);
  37. new Actions(getDriver()).moveToElement(tf2).click().build().perform();
  38. WebElement activeElement = getFocusedElement();
  39. Assert.assertEquals("input", activeElement.getTagName());
  40. Assert.assertEquals("", activeElement.getAttribute("value"));
  41. tf1.sendKeys(incrementalText);
  42. new Actions(getDriver())
  43. .moveToElement(
  44. getDriver().findElement(By.className("v-button")))
  45. .click().build().perform();
  46. activeElement = getFocusedElement();
  47. Assert.assertEquals("Just a button", activeElement.getText());
  48. DesiredCapabilities capabilities = getDesiredCapabilities();
  49. if (BrowserUtil.isIE8(capabilities)
  50. || BrowserUtil.isIE(capabilities, 9)) {
  51. // IE8 and IE9 insert cursor in the start of input instead of end.
  52. Assert.assertEquals(incrementalText + initialText,
  53. tf1.getAttribute("value"));
  54. } else {
  55. Assert.assertEquals(initialText + incrementalText,
  56. tf1.getAttribute("value"));
  57. }
  58. }
  59. @Test
  60. public void moveFocusAndChangeFieldWithValue() {
  61. openTestURL();
  62. List<WebElement> textFields = getDriver().findElements(
  63. By.tagName("input"));
  64. WebElement tf1 = textFields.get(0);
  65. WebElement tf2 = textFields.get(1);
  66. String firstText = "This is";
  67. String secondText = " default value";
  68. tf2.sendKeys(firstText);
  69. tf1.sendKeys(initialText);
  70. new Actions(getDriver()).moveToElement(tf2).click().build().perform();
  71. WebElement activeElement = getFocusedElement();
  72. Assert.assertEquals("input", activeElement.getTagName());
  73. Assert.assertEquals(firstText, activeElement.getAttribute("value"));
  74. new Actions(getDriver()).sendKeys(secondText).build().perform();
  75. DesiredCapabilities capabilities = getDesiredCapabilities();
  76. if (BrowserUtil.isIE8(capabilities)
  77. || BrowserUtil.isIE(capabilities, 9)) {
  78. // IE8 and IE9 insert cursor in the start of input instead of end.
  79. Assert.assertEquals(secondText + firstText,
  80. tf2.getAttribute("value"));
  81. } else {
  82. Assert.assertEquals(firstText + secondText,
  83. tf2.getAttribute("value"));
  84. }
  85. }
  86. }