package cz.moneta.test.harness.connectors.web;

import cz.moneta.test.harness.support.web.Key;
import org.openqa.selenium.Keys;
import org.openqa.selenium.interactions.Actions;

import java.util.Arrays;
import java.util.concurrent.TimeUnit;

public class SendKeys {

    private final SeleniumWebConnector connector;

    public SendKeys(SeleniumWebConnector connector) {
        this.connector = connector;
    }

    public void sendKeysOneAtATime(Key[] keys) {
        Actions actions = new Actions(connector.getDriver());
        Arrays.stream(keys)
                .forEach(k -> {
                    actions.sendKeys(k).build().perform();
                    try {
                        TimeUnit.MILLISECONDS.sleep(100);
                    } catch (InterruptedException e) {
                        //
                    }
                });
    }

    public void sendKeysAsChord(Key[] keys) {
        Actions actions = new Actions(connector.getDriver());
        actions.sendKeys(Keys.chord(keys)).build().perform();
    }
}
