/*
* Copyright 2017-2018 Eficode Oy
* Copyright 2018- Robot Framework Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.File;
import java.io.IOException;
import java.net.BindException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
import javafxlibrary.exceptions.JavaFXLibraryFatalException;
import javafxlibrary.exceptions.JavaFXLibraryNonFatalException;
import javafxlibrary.exceptions.JavaFXLibraryTimeoutException;
import javafxlibrary.keywords.AdditionalKeywords.RunOnFailure;
import javafxlibrary.utils.HelperFunctions;
import javafxlibrary.utils.RobotLog;
import javafxlibrary.utils.TestFxAdapter;
import javafxlibrary.utils.TestListener;
import org.apache.commons.io.FileUtils;
import org.python.google.common.base.Throwables;
import org.robotframework.javalib.annotation.Autowired;
import org.robotframework.javalib.library.AnnotationLibrary;
import org.robotframework.remoteserver.RemoteServer;
import org.testfx.util.WaitForAsyncUtils;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import static javafxlibrary.utils.HelperFunctions.*;
import static org.testfx.util.WaitForAsyncUtils.waitFor;
public class JavaFXLibrary extends AnnotationLibrary {
public static final String ROBOT_LIBRARY_SCOPE = "GLOBAL";
public static final String ROBOT_LIBRARY_VERSION = loadRobotLibraryVersion();
public static final TestListener ROBOT_LIBRARY_LISTENER = new TestListener();
static List includePatterns = new ArrayList() {{
add("javafxlibrary/keywords/AdditionalKeywords/*.class");
add("javafxlibrary/keywords/Keywords/*.class");
add("javafxlibrary/keywords/*.class");
add("javafxlibrary/tests/*.class");
}};
public JavaFXLibrary() {
this(false);
}
public JavaFXLibrary(boolean headless) {
super(includePatterns);
if (headless) {
System.setProperty("testfx.robot", "glass");
System.setProperty("testfx.headless", "true");
System.setProperty("prism.order", "sw");
System.setProperty("prism.text", "t2k");
TestFxAdapter.isHeadless = true;
} else {
//v4.0.15-alpha sets default robot as glass, which breaks rolling
//Forcing usage of awt robot as previous versions
System.setProperty("testfx.robot", "awt");
}
}
@Autowired
protected RunOnFailure runOnFailure;
// overriding the run method to catch the control in case of failure, so that desired runOnFailureKeyword
// can be executed in controlled manner.
@Override
public Object runKeyword(String keywordName, Object[] args) {
Object[] finalArgs;
// JavalibCore changes arguments of Call Method keywords to Strings after this check, so they need to handle their own objectMapping
if (!(keywordName.equals("callObjectMethod") || keywordName.equals("callObjectMethodInFxApplicationThread")))
finalArgs = HelperFunctions.useMappedObjects(args);
else
finalArgs = args;
AtomicReference