A fork of https://github.com/ueokande/vim-vixen
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.4 KiB
50 lines
1.4 KiB
5 years ago
|
import { WebDriver, By } from 'selenium-webdriver';
|
||
5 years ago
|
|
||
5 years ago
|
export type CompletionItem = {
|
||
|
type: string;
|
||
|
text: string;
|
||
|
highlight: boolean;
|
||
|
}
|
||
|
|
||
|
export class Console {
|
||
|
constructor(private webdriver: WebDriver) {
|
||
6 years ago
|
}
|
||
|
|
||
5 years ago
|
async sendKeys(...keys: string[]) {
|
||
5 years ago
|
let input = await this.webdriver.findElement(By.css('input'));
|
||
6 years ago
|
input.sendKeys(...keys);
|
||
|
}
|
||
|
|
||
6 years ago
|
async currentValue() {
|
||
5 years ago
|
return await this.webdriver.executeScript(() => {
|
||
6 years ago
|
let input = document.querySelector('input');
|
||
5 years ago
|
if (input === null) {
|
||
|
throw new Error('could not find input element');
|
||
|
}
|
||
6 years ago
|
return input.value;
|
||
|
});
|
||
|
}
|
||
|
|
||
5 years ago
|
getCompletions(): Promise<CompletionItem[]> {
|
||
|
return this.webdriver.executeScript(() => {
|
||
6 years ago
|
let items = document.querySelectorAll('.vimvixen-console-completion > li');
|
||
|
if (items.length === 0) {
|
||
|
throw new Error('completion items not found');
|
||
|
}
|
||
|
|
||
|
let objs = [];
|
||
5 years ago
|
for (let li of Array.from(items)) {
|
||
6 years ago
|
if (li.classList.contains('vimvixen-console-completion-title')) {
|
||
5 years ago
|
objs.push({ type: 'title', text: li.textContent!!.trim() });
|
||
6 years ago
|
} else if ('vimvixen-console-completion-item') {
|
||
6 years ago
|
let highlight = li.classList.contains('vimvixen-completion-selected');
|
||
5 years ago
|
objs.push({ type: 'item', text: li.textContent!!.trim(), highlight });
|
||
6 years ago
|
} else {
|
||
|
throw new Error(`unexpected class: ${li.className}`);
|
||
|
}
|
||
|
}
|
||
|
return objs;
|
||
|
});
|
||
|
}
|
||
|
}
|