All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.epam.jdi.uitests.web.selenium.elements.actions.ActionInvoker Maven / Gradle / Ivy

There is a newer version: 1.1.34
Show newest version
package com.epam.jdi.uitests.web.selenium.elements.actions;
/*
 * Copyright 2004-2016 EPAM Systems
 *
 * This file is part of JDI project.
 *
 * JDI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JDI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with JDI. If not, see .
 */


import com.epam.commons.Timer;
import com.epam.commons.linqinterfaces.JAction;
import com.epam.jdi.uitests.core.logger.LogLevels;
import com.epam.jdi.uitests.core.settings.JDISettings;
import com.epam.jdi.uitests.web.selenium.elements.base.BaseElement;
import com.epam.jdi.uitests.web.selenium.elements.base.Element;

import java.util.function.Function;
import java.util.function.Supplier;

import static com.epam.commons.ReflectionUtils.isClass;
import static com.epam.jdi.uitests.core.logger.LogLevels.STEP;
import static com.epam.jdi.uitests.core.settings.JDISettings.exception;
import static com.epam.jdi.uitests.web.selenium.elements.base.BaseElement.actionScenrios;

/**
 * Created by Roman_Iovlev on 9/3/2015.
 */
public class ActionInvoker {
    private BaseElement element;

    public ActionInvoker(BaseElement element) {
        this.element = element;
    }

    public final  TResult doJActionResult(String actionName, Supplier action) {
        return doJActionResult(actionName, action, null, STEP);
    }

    public final  TResult doJActionResult(String actionName, Supplier action, Function logResult) {
        return doJActionResult(actionName, action, logResult, STEP);
    }

    public final  TResult doJActionResult(String actionName, Supplier action, LogLevels level) {
        return doJActionResult(actionName, action, null, level);
    }

    public final  TResult doJActionResult(String actionName, Supplier action,
                                                   Function logResult, LogLevels level) {
        try {
            processDemoMode();
            return actionScenrios.setElement(element).resultScenario(actionName, action, logResult, level);
        } catch (Exception | Error ex) {
            throw exception("Failed to do '%s' action. Reason: %s", actionName, ex);
        }
    }

    public final void doJAction(String actionName, JAction action) {
        doJAction(actionName, action, STEP);
    }

    public final void doJAction(String actionName, JAction action, LogLevels level) {
        Timer.alwaysDoneAction(() -> {
            processDemoMode();
            actionScenrios.setElement(element).actionScenario(actionName, action, level);
        });
    }

    public void processDemoMode() {
        if (JDISettings.isDemoMode)
            if (isClass(element.getClass(), Element.class))
                ((Element) element).highlight(JDISettings.highlightSettings);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy