package org.getopentest.selenium;

import org.getopentest.selenium.core.CustomConditions;
import org.getopentest.selenium.core.SeleniumTestAction;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait;

public class AssertElementFocused extends SeleniumTestAction {

    @Override
    public void run() {

        super.run();

        By locator = this.readLocatorArgument("locator");
        Boolean negate = this.readBooleanArgument("negate", Boolean.FALSE);

        this.waitForAsyncCallsToFinish();

        WebElement element = this.getElement(locator);
        WebDriverWait wait = new WebDriverWait(this.driver, this.getExplicitWaitSec());

        if (!negate) {
            wait.until(CustomConditions.elementToBeActive(element));
        } else {
            wait.until(CustomConditions.elementToNotBeActive(element));
        }
    }
}
