Browse Source

Convert EmbeddedClickListenerRelativeCoordinates test to TB4

Change-Id: Iaac3a80428a9b58ba82e814d8665dd17920ab2bd
tags/7.6.0.alpha3
Henri Sara 9 years ago
parent
commit
8755b91e50

+ 9
- 4
uitest/src/com/vaadin/tests/components/embedded/EmbeddedClickListenerRelativeCoordinates.java View File

@@ -5,6 +5,7 @@ import com.vaadin.event.MouseEvents.ClickListener;
import com.vaadin.server.ThemeResource;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.Label;

public class EmbeddedClickListenerRelativeCoordinates extends TestBase {

@@ -12,17 +13,21 @@ public class EmbeddedClickListenerRelativeCoordinates extends TestBase {
protected void setup() {
Embedded e = new Embedded("Embedded caption", new ThemeResource(
"../runo/icons/64/ok.png"));
final Label xLabel = new Label();
xLabel.setId("x");
final Label yLabel = new Label();
yLabel.setId("y");
e.addListener(new ClickListener() {

@Override
public void click(ClickEvent event) {
getMainWindow()
.showNotification(
"" + event.getRelativeX() + ", "
+ event.getRelativeY());
xLabel.setValue("" + event.getRelativeX());
yLabel.setValue("" + event.getRelativeY());
}
});
addComponent(e);
addComponent(xLabel);
addComponent(yLabel);
}

@Override

+ 86
- 0
uitest/src/com/vaadin/tests/components/embedded/EmbeddedClickListenerRelativeCoordinatesTest.java View File

@@ -0,0 +1,86 @@
/*
* Copyright 2000-2014 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.tests.components.embedded;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;

import com.vaadin.testbench.elements.EmbeddedElement;
import com.vaadin.testbench.elements.LabelElement;
import com.vaadin.testbench.parallel.BrowserUtil;
import com.vaadin.tests.tb3.MultiBrowserTest;

public class EmbeddedClickListenerRelativeCoordinatesTest extends
MultiBrowserTest {

@Before
@Override
public void setup() throws Exception {
super.setup();
openTestURL();
waitForElementPresent(By.className("v-embedded"));
}

@Test
public void testRelativeClick() {
clickAt(41, 22);
checkLocation(41, 22);

clickAt(0, 0);
checkLocation(0, 0);
}

private void clickAt(int x, int y) {
EmbeddedElement embedded = $(EmbeddedElement.class).first();

// IE8 consistently clicks two pixels left and above of the given
// position
if (isIE8()) {
x += 2;
y += 2;
}
embedded.click(x, y);
}

private void checkLocation(int expectedX, int expectedY) {
LabelElement xLabel = $(LabelElement.class).id("x");
LabelElement yLabel = $(LabelElement.class).id("y");

int x = Integer.parseInt(xLabel.getText());
int y = Integer.parseInt(yLabel.getText());

Assert.assertEquals(
"Reported X-coordinate from Embedded does not match click location",
expectedX, x);

// IE10 and IE11 sometimes click one pixel below the given position
int tolerance = isIE() ? 1 : 0;
Assert.assertTrue(
"Reported Y-coordinate from Embedded does not match click location",
Math.abs(expectedY - y) <= tolerance);
}

private boolean isIE() {
return BrowserUtil.isIE(getDesiredCapabilities());
}

private boolean isIE8() {
return BrowserUtil.isIE8(getDesiredCapabilities());
}

}

+ 0
- 51
uitest/tb2/com/vaadin/tests/components/embedded/EmbeddedClickListenerRelativeCoordinates.html View File

@@ -1,51 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="" />
<title>EmbeddedClickListenerRelativeCoordinates</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">EmbeddedClickListenerRelativeCoordinates</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/run/com.vaadin.tests.components.embedded.EmbeddedClickListenerRelativeCoordinates?restartApplication</td>
<td></td>
</tr>
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentsembeddedEmbeddedClickListenerRelativeCoordinates::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VEmbedded[0]/domChild[0]</td>
<td>41,22</td>
</tr>
<tr>
<td>assertText</td>
<td>vaadin=runcomvaadintestscomponentsembeddedEmbeddedClickListenerRelativeCoordinates::Root/VNotification[0]/HTML[0]/domChild[1]</td>
<td>41, 22</td>
</tr>
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentsembeddedEmbeddedClickListenerRelativeCoordinates::Root/VNotification[0]</td>
<td>0,0</td>
</tr>
<tr>
<td>waitForElementNotPresent</td>
<td>vaadin=runcomvaadintestscomponentsembeddedEmbeddedClickListenerRelativeCoordinates::Root/VNotification[0]/HTML[0]/domChild[1]</td>
<td></td>
</tr>
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentsembeddedEmbeddedClickListenerRelativeCoordinates::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VEmbedded[0]/domChild[0]</td>
<td>0,0</td>
</tr>
<tr>
<td>assertText</td>
<td>vaadin=runcomvaadintestscomponentsembeddedEmbeddedClickListenerRelativeCoordinates::Root/VNotification[0]/HTML[0]/domChild[1]</td>
<td>0, 0</td>
</tr>
</tbody></table>
</body>
</html>

Loading…
Cancel
Save