|
7 | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | 8 | * you may not use this file except in compliance with the License. |
9 | 9 | * You may obtain a copy of the License at |
10 | | - * |
| 10 | + * |
11 | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | - * |
| 12 | + * |
13 | 13 | * Unless required by applicable law or agreed to in writing, software |
14 | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
19 | 19 | */ |
20 | 20 | package com.flowingcode.vaadin.addons.xterm.integration; |
21 | 21 |
|
| 22 | +import static com.flowingcode.vaadin.addons.xterm.integration.Position.at; |
22 | 23 | import static org.hamcrest.Matchers.is; |
23 | 24 | import static org.hamcrest.Matchers.isEmptyString; |
24 | 25 | import static org.junit.Assert.assertThat; |
25 | | -import com.vaadin.testbench.TestBenchElement; |
26 | 26 | import org.apache.commons.lang3.StringUtils; |
27 | 27 | import org.junit.Test; |
28 | 28 | import org.openqa.selenium.Keys; |
29 | | -import org.openqa.selenium.WebElement; |
30 | 29 |
|
31 | | -public class ConsoleFeatureIT extends AbstractXTermTest { |
| 30 | +public class ConsoleFeatureIT extends AbstractViewTest { |
32 | 31 |
|
33 | 32 | @Test |
34 | 33 | public void testFeature() throws InterruptedException { |
35 | | - TestBenchElement term = $("fc-xterm").first(); |
| 34 | + XTermElement term = $(XTermElement.class).first(); |
36 | 35 |
|
37 | | - WebElement input = |
38 | | - (WebElement) getCommandExecutor().executeScript("return document.activeElement"); |
| 36 | + int y = term.cursorPosition().y; |
39 | 37 |
|
40 | | - int y = cursorPosition(term).y; |
| 38 | + term.sendKeys("HELLO"); |
| 39 | + assertThat(term.currentLine(), is("HELLO")); |
| 40 | + assertThat(term.cursorPosition(), is(at(5, y))); |
41 | 41 |
|
42 | | - input.sendKeys("HELLO"); |
43 | | - assertThat(currentLine(term), is("HELLO")); |
44 | | - assertThat(cursorPosition(term), is(at(5, y))); |
| 42 | + term.sendKeys(Keys.ARROW_LEFT); |
| 43 | + assertThat(term.cursorPosition(), is(at(4, y))); |
45 | 44 |
|
46 | | - input.sendKeys(Keys.ARROW_LEFT); |
47 | | - assertThat(cursorPosition(term), is(at(4, y))); |
| 45 | + term.sendKeys(Keys.ARROW_RIGHT); |
| 46 | + assertThat(term.cursorPosition(), is(at(5, y))); |
48 | 47 |
|
49 | | - input.sendKeys(Keys.ARROW_RIGHT); |
50 | | - assertThat(cursorPosition(term), is(at(5, y))); |
| 48 | + term.sendKeys(Keys.HOME); |
| 49 | + assertThat(term.cursorPosition(), is(at(0, y))); |
51 | 50 |
|
52 | | - input.sendKeys(Keys.HOME); |
53 | | - assertThat(cursorPosition(term), is(at(0, y))); |
| 51 | + term.sendKeys(Keys.END); |
| 52 | + assertThat(term.cursorPosition(), is(at(5, y))); |
54 | 53 |
|
55 | | - input.sendKeys(Keys.END); |
56 | | - assertThat(cursorPosition(term), is(at(5, y))); |
| 54 | + term.sendKeys(Keys.BACK_SPACE); |
| 55 | + assertThat(term.currentLine(), is("HELL")); |
| 56 | + assertThat(term.cursorPosition(), is(at(4, y))); |
57 | 57 |
|
58 | | - input.sendKeys(Keys.BACK_SPACE); |
59 | | - assertThat(currentLine(term), is("HELL")); |
60 | | - assertThat(cursorPosition(term), is(at(4, y))); |
| 58 | + term.sendKeys(Keys.HOME, Keys.DELETE); |
| 59 | + assertThat(term.currentLine(), is("ELL")); |
| 60 | + assertThat(term.cursorPosition(), is(at(0, y))); |
61 | 61 |
|
62 | | - input.sendKeys(Keys.HOME, Keys.DELETE); |
63 | | - assertThat(currentLine(term), is("ELL")); |
64 | | - assertThat(cursorPosition(term), is(at(0, y))); |
| 62 | + term.sendKeys("A"); |
| 63 | + assertThat(term.currentLine(), is("AELL")); |
65 | 64 |
|
66 | | - input.sendKeys("A"); |
67 | | - assertThat(currentLine(term), is("AELL")); |
| 65 | + term.sendKeys(Keys.INSERT, "B"); |
| 66 | + assertThat(term.currentLine(), is("ABLL")); |
68 | 67 |
|
69 | | - input.sendKeys(Keys.INSERT, "B"); |
70 | | - assertThat(currentLine(term), is("ABLL")); |
71 | | - |
72 | | - input.sendKeys(Keys.INSERT, "C"); |
73 | | - assertThat(currentLine(term), is("ABCLL")); |
| 68 | + term.sendKeys(Keys.INSERT, "C"); |
| 69 | + assertThat(term.currentLine(), is("ABCLL")); |
74 | 70 |
|
75 | 71 | // long line |
76 | 72 |
|
77 | | - int cols = getColumnWidth(term); |
| 73 | + int cols = term.getColumnWidth(); |
78 | 74 | String text = StringUtils.repeat("0123456789", cols / 10 + 1).substring(0, cols); |
79 | 75 |
|
80 | | - input.sendKeys("\n"); |
81 | | - assertThat(currentLine(term), is("")); |
82 | | - assertThat(cursorPosition(term), is(at(0, ++y))); |
| 76 | + term.sendKeys("\n"); |
| 77 | + assertThat(term.currentLine(), is("")); |
| 78 | + assertThat(term.cursorPosition(), is(at(0, ++y))); |
83 | 79 |
|
84 | | - input.sendKeys(text); |
85 | | - input.sendKeys(Keys.HOME); |
86 | | - assertThat(cursorPosition(term), is(at(0, y))); |
87 | | - assertThat(currentLine(term), is(text)); |
| 80 | + term.sendKeys(text); |
| 81 | + term.sendKeys(Keys.HOME); |
| 82 | + assertThat(term.cursorPosition(), is(at(0, y))); |
| 83 | + assertThat(term.currentLine(), is(text)); |
88 | 84 |
|
89 | | - input.sendKeys("A"); |
90 | | - assertThat(currentLine(term), is("A" + text.substring(0, cols - 1))); |
91 | | - assertThat(lineAtOffset(term, +1), is(text.substring(cols - 1))); |
| 85 | + term.sendKeys("A"); |
| 86 | + assertThat(term.currentLine(), is("A" + text.substring(0, cols - 1))); |
| 87 | + assertThat(term.lineAtOffset(+1), is(text.substring(cols - 1))); |
92 | 88 |
|
93 | | - input.sendKeys("B"); |
94 | | - assertThat(currentLine(term), is("AB" + text.substring(0, cols - 2))); |
95 | | - assertThat(lineAtOffset(term, +1), is(text.substring(cols - 2))); |
| 89 | + term.sendKeys("B"); |
| 90 | + assertThat(term.currentLine(), is("AB" + text.substring(0, cols - 2))); |
| 91 | + assertThat(term.lineAtOffset(+1), is(text.substring(cols - 2))); |
96 | 92 |
|
97 | | - input.sendKeys(Keys.END); |
98 | | - assertThat(cursorPosition(term), is(at(2, y + 1))); |
| 93 | + term.sendKeys(Keys.END); |
| 94 | + assertThat(term.cursorPosition(), is(at(2, y + 1))); |
99 | 95 |
|
100 | | - input.sendKeys(Keys.HOME); |
101 | | - assertThat(cursorPosition(term), is(at(0, y))); |
| 96 | + term.sendKeys(Keys.HOME); |
| 97 | + assertThat(term.cursorPosition(), is(at(0, y))); |
102 | 98 |
|
103 | | - input.sendKeys(Keys.DELETE); |
104 | | - assertThat(currentLine(term), is("B" + text.substring(0, cols - 1))); |
105 | | - assertThat(lineAtOffset(term, +1), is(text.substring(cols - 1))); |
| 99 | + term.sendKeys(Keys.DELETE); |
| 100 | + assertThat(term.currentLine(), is("B" + text.substring(0, cols - 1))); |
| 101 | + assertThat(term.lineAtOffset(+1), is(text.substring(cols - 1))); |
106 | 102 |
|
107 | | - input.sendKeys(Keys.DELETE); |
108 | | - assertThat(currentLine(term), is(text)); |
109 | | - assertThat(lineAtOffset(term, +1), isEmptyString()); |
| 103 | + term.sendKeys(Keys.DELETE); |
| 104 | + assertThat(term.currentLine(), is(text)); |
| 105 | + assertThat(term.lineAtOffset(+1), isEmptyString()); |
110 | 106 | } |
111 | 107 | } |
0 commit comments