import * as puppeteer from "puppeteer";
import { Rule } from "../rule";
import Word from "../word";
import Action from "./action";

export default class KeyupAction extends Action {
    public key: string;

    constructor(word: Word, rule: Rule, key) {
        super(word, rule);
        this.key = key;
    }

    public exec(page: puppeteer.Page): Promise<void> {
        return page.evaluateHandle(() => document.activeElement)
            .then((elementOnFocus) => elementOnFocus.asElement().press(this.key));
    }
}
