aboutsummaryrefslogtreecommitdiff
path: root/e2e/lib/Console.ts
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-09-22 16:13:12 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2019-09-22 16:13:12 +0900
commit7e77e31ad64c3649888eae337e0c984fd9c2ea2a (patch)
tree4d3e630f82712abce5afd7e498d514253464a6ea /e2e/lib/Console.ts
parent91f8383ecc2f7ef3f95173ad973a74f79e277a6c (diff)
Migrate e2e tests to TypeScript
Diffstat (limited to 'e2e/lib/Console.ts')
-rw-r--r--e2e/lib/Console.ts49
1 files changed, 49 insertions, 0 deletions
diff --git a/e2e/lib/Console.ts b/e2e/lib/Console.ts
new file mode 100644
index 0000000..37b0597
--- /dev/null
+++ b/e2e/lib/Console.ts
@@ -0,0 +1,49 @@
+import { WebDriver, By } from 'selenium-webdriver';
+
+export type CompletionItem = {
+ type: string;
+ text: string;
+ highlight: boolean;
+}
+
+export class Console {
+ constructor(private webdriver: WebDriver) {
+ }
+
+ async sendKeys(...keys: string[]) {
+ let input = await this.webdriver.findElement(By.css('input'));
+ input.sendKeys(...keys);
+ }
+
+ async currentValue() {
+ return await this.webdriver.executeScript(() => {
+ let input = document.querySelector('input');
+ if (input === null) {
+ throw new Error('could not find input element');
+ }
+ return input.value;
+ });
+ }
+
+ getCompletions(): Promise<CompletionItem[]> {
+ return this.webdriver.executeScript(() => {
+ let items = document.querySelectorAll('.vimvixen-console-completion > li');
+ if (items.length === 0) {
+ throw new Error('completion items not found');
+ }
+
+ let objs = [];
+ for (let li of Array.from(items)) {
+ if (li.classList.contains('vimvixen-console-completion-title')) {
+ objs.push({ type: 'title', text: li.textContent!!.trim() });
+ } else if ('vimvixen-console-completion-item') {
+ let highlight = li.classList.contains('vimvixen-completion-selected');
+ objs.push({ type: 'item', text: li.textContent!!.trim(), highlight });
+ } else {
+ throw new Error(`unexpected class: ${li.className}`);
+ }
+ }
+ return objs;
+ });
+ }
+}