2 * Copyright 2000-2016 Vaadin Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
16 package com.vaadin.v7.tests.components.nativeselect;
18 import org.junit.Assert;
19 import org.junit.Test;
20 import org.openqa.selenium.By;
21 import org.openqa.selenium.interactions.Actions;
23 import com.vaadin.testbench.parallel.BrowserUtil;
24 import com.vaadin.tests.components.nativeselect.NativeSelects;
25 import com.vaadin.tests.tb3.MultiBrowserTest;
26 import com.vaadin.v7.testbench.customelements.NativeSelectElement;
28 public class NativeSelectsFocusAndBlurListenerTests extends MultiBrowserTest {
31 public void testFocusAndBlurListener() throws InterruptedException {
37 menuSub("Focus listener");
40 menuSub("Blur listener");
42 findElement(By.tagName("body")).click();
44 NativeSelectElement s = $(NativeSelectElement.class).first();
45 s.selectByText("Item 3");
46 getDriver().findElement(By.tagName("body")).click();
48 // Somehow selectByText causes focus + blur + focus + blur on
50 if (BrowserUtil.isChrome(getDesiredCapabilities())
51 || BrowserUtil.isPhantomJS(getDesiredCapabilities())) {
52 Assert.assertEquals("4. FocusEvent", getLogRow(1));
53 Assert.assertEquals("5. BlurEvent", getLogRow(0));
55 Assert.assertEquals("2. FocusEvent", getLogRow(1));
56 Assert.assertEquals("3. BlurEvent", getLogRow(0));
62 protected Class<?> getUIClass() {
63 return NativeSelects.class;
66 private void menuSub(String string) {
67 getDriver().findElement(By.xpath("//span[text() = '" + string + "']"))
69 new Actions(getDriver()).moveByOffset(100, 0).build().perform();
72 private void menu(String string) {
73 getDriver().findElement(By.xpath("//span[text() = '" + string + "']"))