blob: 6820db4d2f60fb97c9ce55b324541ac20799024f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
package com.vaadin.tests.layouts.gridlayout;
import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.GridLayoutElement;
import com.vaadin.testbench.elements.TextFieldElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import static org.junit.Assert.assertEquals;
public class GridLayoutCaptionOnBottomAlignedComponentTest
extends MultiBrowserTest {
@Test
public void captionShouldBeImmediatelyAboveItsComponent() {
openTestURL();
GridLayoutElement gridLayout = $(GridLayoutElement.class).first();
WebElement caption = gridLayout.findElement(By.className("v-caption"));
TextFieldElement component = $(TextFieldElement.class).first();
assertEquals("Caption and component have the same horizontal alignment",
caption.getLocation().x, component.getLocation().x);
// We have to do the assertion in this way because different browsers on
// different operating systems
// measure the height of the caption in different ways.
int diff = Math.abs(caption.getLocation().y - component.getLocation().y
+ caption.getSize().height);
assertLessThanOrEqual("Caption is placed directly above the component",
diff, 1);
}
@Test
public void captionShouldStillBeImmediatelyAboveItsComponentEvenWhenRealigned() {
openTestURL();
GridLayoutElement gridLayout = $(GridLayoutElement.class).first();
WebElement caption = gridLayout.findElement(By.className("v-caption"));
TextFieldElement component = $(TextFieldElement.class).first();
// Click the button, this changes the alignment of the component
$(ButtonElement.class).first().click();
assertEquals("Caption and component have the same horizontal alignment",
caption.getLocation().x, component.getLocation().x);
assertEquals("Caption is placed in the top-left corner",
gridLayout.getLocation().y, caption.getLocation().y);
}
}
|