Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* The MIT License
*
* Copyright 2020 Intuit Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.intuit.karate.robot;
import com.intuit.karate.core.Config;
import com.intuit.karate.Logger;
import com.intuit.karate.StringUtils;
import com.intuit.karate.core.Plugin;
import com.intuit.karate.driver.Keys;
import com.intuit.karate.KarateException;
import com.intuit.karate.core.ScenarioEngine;
import com.intuit.karate.core.ScenarioRuntime;
import com.intuit.karate.core.StepResult;
import com.intuit.karate.core.Variable;
import com.intuit.karate.http.ResourceType;
import com.intuit.karate.shell.Command;
import java.awt.Dimension;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.event.InputEvent;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.function.Supplier;
/**
*
* @author pthomas3
*/
public abstract class RobotBase implements Robot, Plugin {
private static final int CLICK_POST_DELAY = 500;
public final java.awt.Robot robot;
public final Toolkit toolkit;
public final Dimension dimension;
public final Map options;
public final boolean autoClose;
public final boolean screenshotOnFailure;
public final int autoDelay;
public final Region screen;
public final String tessData;
public final String tessLang;
// mutables
private String basePath;
protected Command command;
protected ScenarioEngine engine;
protected Logger logger;
protected Element currentWindow;
// retry
private boolean retryEnabled;
private Integer retryIntervalOverride = null;
private Integer retryCountOverride = null;
// debug
protected boolean debug;
public boolean highlight;
public int highlightDuration;
public void setDebug(boolean debug) {
this.debug = debug;
}
public void setHighlight(boolean highlight) {
this.highlight = highlight;
}
public void setHighlightDuration(int highlightDuration) {
this.highlightDuration = highlightDuration;
}
public void disableRetry() {
retryEnabled = false;
retryCountOverride = null;
retryIntervalOverride = null;
}
public void enableRetry(Integer count, Integer interval) {
retryEnabled = true;
retryCountOverride = count; // can be null
retryIntervalOverride = interval; // can be null
}
private int getRetryCount() {
return retryCountOverride == null ? engine.getConfig().getRetryCount() : retryCountOverride;
}
private int getRetryInterval() {
return retryIntervalOverride == null ? engine.getConfig().getRetryInterval() : retryIntervalOverride;
}
private T get(String key, T defaultValue) {
T temp = (T) options.get(key);
return temp == null ? defaultValue : temp;
}
public Logger getLogger() {
return logger;
}
public RobotBase(ScenarioRuntime runtime) {
this(runtime, Collections.EMPTY_MAP);
}
public RobotBase(ScenarioRuntime runtime, Map options) {
this.engine = runtime.engine;
this.logger = runtime.logger;
try {
this.options = options;
basePath = get("basePath", null);
highlight = get("highlight", false);
highlightDuration = get("highlightDuration", Config.DEFAULT_HIGHLIGHT_DURATION);
autoDelay = get("autoDelay", 0);
tessData = get("tessData", "tessdata");
tessLang = get("tessLang", "eng");
toolkit = Toolkit.getDefaultToolkit();
dimension = toolkit.getScreenSize();
screen = new Region(this, 0, 0, dimension.width, dimension.height);
logger.debug("screen dimensions: {}", screen);
robot = new java.awt.Robot();
robot.setAutoDelay(autoDelay);
robot.setAutoWaitForIdle(true);
//==================================================================
screenshotOnFailure = get("screenshotOnFailure", true);
autoClose = get("autoClose", true);
boolean attach = get("attach", true);
String window = get("window", null);
if (window != null) {
currentWindow = window(window, false, false); // don't retry
}
if (currentWindow != null && attach) {
logger.debug("window found, will re-use: {}", window);
} else {
Variable v = new Variable(options.get("fork"));
if (v.isString()) {
command = engine.fork(true, v.getAsString());
} else if (v.isList()) {
command = engine.fork(true, v.getValue());
} else if (v.isMap()) {
command = engine.fork(true, v.