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.

NativeSelectsFocusAndBlurListenerTests.java 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.nativeselect;
  17. import org.junit.Assert;
  18. import org.junit.Test;
  19. import org.openqa.selenium.By;
  20. import org.openqa.selenium.interactions.Actions;
  21. import com.vaadin.testbench.elements.NativeSelectElement;
  22. import com.vaadin.testbench.parallel.BrowserUtil;
  23. import com.vaadin.tests.tb3.MultiBrowserTest;
  24. public class NativeSelectsFocusAndBlurListenerTests extends MultiBrowserTest {
  25. @Test
  26. public void testFocusAndBlurListener() throws InterruptedException {
  27. setDebug(true);
  28. openTestURL();
  29. Thread.sleep(200);
  30. menu("Component");
  31. menuSub("Listeners");
  32. menuSub("Focus listener");
  33. menu("Component");
  34. menuSub("Listeners");
  35. menuSub("Blur listener");
  36. findElement(By.tagName("body")).click();
  37. NativeSelectElement s = $(NativeSelectElement.class).first();
  38. s.selectByText("Item 3");
  39. getDriver().findElement(By.tagName("body")).click();
  40. // Somehow selectByText causes focus + blur + focus + blur on
  41. // Chrome/PhantomJS
  42. if (BrowserUtil.isChrome(getDesiredCapabilities())
  43. || BrowserUtil.isPhantomJS(getDesiredCapabilities())) {
  44. Assert.assertEquals("4. FocusEvent", getLogRow(1));
  45. Assert.assertEquals("5. BlurEvent", getLogRow(0));
  46. } else {
  47. Assert.assertEquals("2. FocusEvent", getLogRow(1));
  48. Assert.assertEquals("3. BlurEvent", getLogRow(0));
  49. }
  50. }
  51. @Override
  52. protected Class<?> getUIClass() {
  53. return NativeSelects.class;
  54. }
  55. private void menuSub(String string) {
  56. getDriver().findElement(By.xpath("//span[text() = '" + string + "']"))
  57. .click();
  58. new Actions(getDriver()).moveByOffset(100, 0).build().perform();
  59. }
  60. private void menu(String string) {
  61. getDriver().findElement(By.xpath("//span[text() = '" + string + "']"))
  62. .click();
  63. }
  64. }