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.
/**
* Orignal work: Copyright 2015 www.seleniumtests.com
* Modified work: Copyright 2016 www.infotel.com
* Copyright 2017-2019 B.Hecquet
*
* 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.
*/
package com.seleniumtests.core;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.logging.log4j.Logger;
import org.json.JSONObject;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.Platform;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.Proxy.ProxyType;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.support.events.WebDriverListener;
import org.testng.IReporter;
import org.testng.ITestContext;
import org.testng.ITestResult;
import org.testng.TestRunner;
import org.testng.internal.TestResult;
import com.seleniumtests.browserfactory.BrowserInfo;
import com.seleniumtests.browserfactory.SeleniumRobotCapabilityType;
import com.seleniumtests.connectors.bugtracker.BugTracker;
import com.seleniumtests.connectors.selenium.SeleniumGridConnector;
import com.seleniumtests.connectors.selenium.SeleniumGridConnectorFactory;
import com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector;
import com.seleniumtests.connectors.tms.TestManager;
import com.seleniumtests.core.config.ConfigReader;
import com.seleniumtests.core.contexts.BugTrackerContext;
import com.seleniumtests.core.contexts.SeleniumRobotServerContext;
import com.seleniumtests.core.contexts.TestManagerContext;
import com.seleniumtests.core.utils.TestNGResultUtils;
import com.seleniumtests.customexception.ConfigurationException;
import com.seleniumtests.driver.BrowserType;
import com.seleniumtests.driver.DriverMode;
import com.seleniumtests.driver.TestType;
import com.seleniumtests.driver.screenshots.ScreenshotUtil;
import com.seleniumtests.driver.screenshots.SnapshotComparisonBehaviour;
import com.seleniumtests.reporter.logger.ArchiveMode;
import com.seleniumtests.reporter.reporters.BugTrackerReporter;
import com.seleniumtests.reporter.reporters.CustomReporter;
import com.seleniumtests.reporter.reporters.ReportInfo;
import com.seleniumtests.reporter.reporters.SeleniumRobotServerTestRecorder;
import com.seleniumtests.reporter.reporters.SeleniumTestsReporter2;
import com.seleniumtests.reporter.reporters.TestManagerReporter;
import com.seleniumtests.uipage.htmlelements.ElementInfo;
import com.seleniumtests.util.StringUtility;
import com.seleniumtests.util.logging.DebugMode;
import com.seleniumtests.util.logging.SeleniumRobotLogger;
import com.seleniumtests.util.osutility.OSUtility;
import com.seleniumtests.util.video.VideoCaptureMode;
import org.testng.internal.thread.ThreadUtil;
/**
* Defines TestNG context used in STF.
*/
public class SeleniumTestsContext {
private static final Object lock = new Object();
private static final Logger logger = SeleniumRobotLogger.getLogger(SeleniumTestsContext.class);
private static Map outputFolderNames = Collections.synchronizedMap(new HashMap<>());
/* configuration defined in testng.xml */
public static final String TEST_CONFIGURATION = "testConfig"; // parameter name for additional configuration to load (should only be used in XML)
public static final String LOAD_INI = "loadIni"; // comma separated list of files to load. They are searched in data//config folder. They will append to env.ini file with variable overwriting. Last file will overwrite previous ones
public static final String STARTED_BY = "startedBy"; // any string saying who started the test. It may be a URL where to find result, for reports in bugtrackers
public static final String INITIAL_URL = "initialUrl"; // the initial URL the browser will connect to
public static final String DEVICE_LIST = "deviceList"; // List of known devices in json format (internal use only)
public static final String WEB_SESSION_TIME_OUT = "webSessionTimeOut"; // timeout de la session du navigateur
public static final String IMPLICIT_WAIT_TIME_OUT = "implicitWaitTimeOut"; // attente implicite du navigateur
public static final String EXPLICIT_WAIT_TIME_OUT = "explicitWaitTimeOut"; // attente explicite du navigateur
public static final String HEADLESS_BROWSER = "headless";
public static final String REPLAY_TIME_OUT = "replayTimeOut"; // time during which an action is replayed. By default 30 secs
public static final String ACTION_DELAY = "actionDelay"; // time in milliseconds between 2 actions (e.g: 2 clicks). It allows to slow down or speed up tests
public static final String PAGE_LOAD_TIME_OUT = "pageLoadTimeout"; // temps d'attente de chargement d'une page
public static final String PAGE_LOAD_STRATEGY = "pageLoadStrategy"; // page load strategy as defined in selenium spec. Will be applied to driver
public static final String WEB_DRIVER_GRID = "webDriverGrid"; // adresse du serveur seleniumGrid
public static final String RUN_MODE = "runMode"; // local ou grid. Pourrait également contenir sauceLabs / testDroid
public static final String NODE_TAGS = "nodeTags"; // Comma seperated list of strings. Requests that this test should execute only on a node (grid mode only) announcing all of these tags (issue #190)
public static final String MASK_PASSWORD = "maskPassword"; // whether seleniumRobot should hide passwords or not
public static final String MANUAL_TEST_STEPS = "manualTestSteps"; // set test steps manual (default is false) for creating them inside tests
public static final String DEBUG = "debug"; // whether to debug test (logs from browser / core). Valid values are: 'none', 'core', 'driver' or 'core,driver'
public static final String INTERNAL_DEBUG = "internalDebug";
public static final String BROWSER = "browser"; // navigateur utilisé. Sur Android, le navigateur par défaut est "Browser"
public static final String BROWSER_VERSION = "browserVersion"; // version de navigateur utilisé
public static final String FIREFOX_USER_PROFILE_PATH = "firefoxUserProfilePath"; // firefox user profile
public static final String CHROME_USER_PROFILE_PATH = "chromeUserProfilePath"; // chrome user profile
public static final String EDGE_USER_PROFILE_PATH = "edgeUserProfilePath"; // edge user profile
public static final String CHROME_OPTIONS = "chromeOptions"; // options to give to chrome at startup
public static final String EDGE_OPTIONS = "edgeOptions"; // options to give to edge at startup
public static final String FIREFOX_BINARY_PATH = "firefoxBinaryPath"; // chemin vers le binaire firefox (firefox portable ou pour utiliser une version spécifique
public static final String CHROME_DRIVER_PATH = "chromeDriverPath"; // chemin vers chromeDriver si on souhaite utiliser une version différente
public static final String GECKO_DRIVER_PATH = "geckoDriverPath"; // chemin vers chromeDriver si on souhaite utiliser une version différente
public static final String EDGE_DRIVER_PATH = "edgeDriverPath"; // path to Edge driver binary if we want to use an other version than the provided one
public static final String CHROME_BINARY_PATH = "chromeBinaryPath"; // chemin vers le binaire chrome lorsque celui-ci n'est pas installé de manière normale
public static final String IE_DRIVER_PATH = "ieDriverPath"; // chemin vers le driver Internet Explorer
public static final String USER_AGENT = "userAgent"; // user agent utilisé pour les tests. Permet d'écraser le user-agent par défaut du navigateur, sur firefox et chrome uniquement
public static final String BETA_BROWSER = "betaBrowser"; // enable usage of beta browsers
public static final String EDGE_IE_MODE = "edgeIeMode"; // if true, Edge is started in IE mode
public static final String CAPABILITIES = "capabilities"; // The capability to add to driver. `-Dcapabilities==,=`
public static final String VIEWPORT_WIDTH = "viewPortWidth"; // width of viewport
public static final String VIEWPORT_HEIGHT = "viewPortHeight"; // height of viewport
public static final String ADVANCED_ELEMENT_SEARCH = "advancedElementSearch"; // 'false' (default), 'full', 'dom'. if 'dom', store and possibly use found element information to adapt to changes in DOM, using only DOM information. If element is not found, it will try to use other element information to find it
// if 'full', search will also be done using element picture, if available
public static final String FIND_ERROR_CAUSE = "findErrorCause"; // if 'true', try to find why the test failed
public static final String SET_ASSUME_UNTRUSTED_CERTIFICATE_ISSUER = "setAssumeUntrustedCertificateIssuer"; // Firefox uniquement pour qu'il ne prenne pas en compte les certificats invalides
public static final String SET_ACCEPT_UNTRUSTED_CERTIFICATES = "setAcceptUntrustedCertificates"; // Firefox uniquement pour qu'il ne prenne pas en compte les certificats invalides
public static final String NTLM_AUTH_TRUSTED_URIS = "ntlmAuthTrustedUris"; // Firefox uniquement
public static final String BROWSER_DOWNLOAD_DIR = "browserDownloadDir"; // répertoire où seront enregistrés les fichiers
public static final String SNAPSHOT_TOP_CROPPING = "snapshotTopCropping";
public static final String SNAPSHOT_BOTTOM_CROPPING = "snapshotBottomCropping";
public static final String SNAPSHOT_SCROLL_DELAY = "snapshotScrollDelay"; // time in ms between the browser scrolling (when it's needed) and effective capture. A higher value means we have chance all picture have been loaded (with progressive loading) but capture take more time. This is only valid when captures are done for image comparison
public static final String WEB_PROXY_TYPE = "proxyType"; // type de proxy. AUTO, MANUAL, NO
public static final String WEB_PROXY_TYPE_FROM_USER = "proxyTypeFromUser"; // issue #158: proxy type as requested by user. Store it
public static final String WEB_PROXY_ADDRESS = "proxyAddress"; // adresse du proxy.
public static final String WEB_PROXY_PORT = "proxyPort"; // port du proxy
public static final String WEB_PROXY_LOGIN = "proxyLogin"; // login du proxy (si nécessaire)
public static final String WEB_PROXY_PASSWORD = "proxyPassword"; // mot de passe du proxy (si nécessaire)
public static final String WEB_PROXY_EXCLUDE = "proxyExclude"; // exclusion des adresse de proxy
public static final String WEB_PROXY_PAC = "proxyPac"; // adresse de configuration automatique du proxy
public static final String TEST_ENTITY = "testEntity"; // Jamais utilisé
public static final String CAPTURE_SNAPSHOT = "captureSnapshot";
public static final String CAPTURE_NETWORK = "captureNetwork";
public static final String VIDEO_CAPTURE = "captureVideo";
public static final String SOFT_ASSERT_ENABLED = "softAssertEnabled"; // le test ne s'arrête pas lorsqu'une assertion est rencontrée
public static final String TEST_RETRY_COUNT = "testRetryCount"; // number of times the test can be retried
public static final String OVERRIDE_SELENIUM_NATIVE_ACTION = "overrideSeleniumNativeAction"; // intercept driver.findElement and driver.frame operations to move to HtmlElement methods
public static final String OUTPUT_DIRECTORY = "outputDirectory"; // folder where HTML report will be written
public static final String DEFAULT_OUTPUT_DIRECTORY = "defaultOutputDirectory"; // folder where TestNG would write it's results if not overwritten
public static final String CUSTOM_TEST_REPORTS = "customTestReports";
public static final String CUSTOM_SUMMARY_REPORTS = "customSummaryReports";
public static final String ARCHIVE_TO_FILE = "archiveToFile"; // path to the file where archive will be done.
public static final String ARCHIVE = "archive"; // whether archiving is done. DEfault is false, other values are 'true', 'onSuccess', 'onError'
public static final String KEEP_ALL_RESULTS = "keepAllResults"; // if true, will keep all result even if test is retried, allowing to analyze them
public static final String WEB_DRIVER_LISTENER = "webDriverListener";
public static final String OPTIMIZE_REPORTS = "optimizeReports";
public static final String TEST_METHOD_SIGNATURE = "testMethodSignature";
public static final String REPORTER_PLUGIN_CLASSES = "reporterPluginClasses"; // comma-seperated list of classes to call when a custom reporter needs to be added
public static final String TEST_TYPE = "testType"; // configured automatically
public static final String CUCUMBER_TESTS = "cucumberTests"; // liste des tests en mode cucumber
public static final String CUCUMBER_TAGS = "cucumberTags"; // liste des tags cucumber
public static final String TEST_ENV = "env"; // environnement de test pour le SUT. Permet d'accéder aux configurations spécifiques du fichier env.ini
public static final String CUCUMBER_IMPLEMENTATION_PKG = "cucumberPackage"; // nom du package java pour les classes cucumber, car celui-ci n'est pas accessible par testNG
// Appium specific properties
public static final String APP = "app"; // Chemin de l'application mobile (local ou distant)
public static final String MOBILE_PLATFORM_VERSION = "mobilePlatformVersion";// Mobile OS version. It's deduced from platform name and not read directly from parameters
public static final String DEVICE_NAME = "deviceName"; // Nom du terminal utilisé pour le test
public static final String DEVICE_ID = "deviceId"; // Id of the device on which test session will be started. This only mandatory when using a remote appium server with 'appiumServerUrl' parameter. In all other cases, deviceId is set automatically through discovery
public static final String FULL_RESET = "fullReset"; // whether we should do a full reset (default is true)
public static final String AUTOMATION_NAME = "automationName"; // Default is "Appium". The automationName to use. See http://appium.io/docs/en/writing-running-appium/caps/index.html
public static final String APPIUM_SERVER_URL = "appiumServerUrl"; // URL of an already started appium server. I set, this appium server will be used instead of starting a new one
public static final String APPIUM_CAPS = "appiumCaps"; // Set of capabilities that will be added and sent to appium. These are the capabilities that are not already handled by the framework. See: http://appium.io/docs/en/writing-running-appium/caps/
// Format is "key1=value1;key2=value2"
public static final String APP_PACKAGE = "appPackage"; // package de l'application
public static final String APP_ACTIVITY = "appActivity"; // activité à démarrer (Android)
public static final String APP_WAIT_ACTIVITY = "appWaitActivity"; // dans certains cas, l'activité qui démarre l'application n'est pas l'activité principale. C'est celle-ci qu'on attend
public static final String NEW_COMMAND_TIMEOUT = "newCommandTimeout"; // Attente maximale entre 2 commandes envoyées à appium
// Cloud specific properties
public static final String VERSION = "version"; // browser version
public static final String PLATFORM = "platform"; // platform on which test should execute. Ex: Windows 7, Android, iOS, Linux, OS X 10.10.
// Neoload specific properties
public static final String NEOLOAD_USER_PATH = "neoloadUserPath"; // name of the neoload "user path" that will be created in Design mode
// internal use
public static final String TEST_VARIABLES = "testVariables"; // configuration (aka variables, get via 'param()' method) used for the current test. It is not updated via XML file
public static final String TEST_NAME = "testName";
public static final String RELATIVE_OUTPUT_DIR = "relativeOutputDir";
public static final String RANDOM_IN_ATTACHMENT_NAME = "randomInAttachmentName"; // by default, snapshots are renamed with a random part so that if several steps have the same name, their snapshot do not overwrite.
// this option disables the behaviour FOR TEST PURPOSE
// default values
protected static final List DEFAULT_CUSTOM_TEST_REPORTS = Arrays.asList(new ReportInfo("PERF::xml::reporter/templates/report.perf.vm"));
protected static final List DEFAULT_CUSTOM_SUMMARY_REPORTS = Arrays.asList(new ReportInfo("results::json::reporter/templates/report.summary.json.vm"));
public static final int DEFAULT_NEW_COMMAND_TIMEOUT = 120;
public static final String DEFAULT_TEST_ENV = "DEV";
public static final String DEFAULT_CUCUMBER_TESTS = "";
public static final String DEFAULT_CUCUMBER_TAGS = "";
public static final String DEFAULT_APP = "";
public static final String DEFAULT_DEVICE_LIST = "{}";
public static final boolean DEFAULT_SOFT_ASSERT_ENABLED = true;
public static final boolean DEFAULT_ENABLE_EXCEPTION_LISTENER = true;
public static final boolean DEFAULT_CAPTURE_SNAPSHOT = true;
public static final boolean DEFAULT_CAPTURE_NETWORK = false;
public static final String DEFAULT_INITIAL_URL = "about:blank";
public static final String DEFAULT_VIDEO_CAPTURE = "onError";
public static final Integer DEFAULT_SNAPSHOT_TOP_CROPPING = null;
public static final Integer DEFAULT_SNAPSHOT_BOTTOM_CROPPING = null;
public static final int DEFAULT_SNAPSHOT_SCROLL_DELAY = 0;
public static final boolean DEFAULT_ENABLE_JAVASCRIPT = true;
public static final boolean DEFAULT_SET_ACCEPT_UNTRUSTED_CERTIFICATES = true;
public static final boolean DEFAULT_SET_ASSUME_UNTRUSTED_CERTIFICATE_ISSUER = true;
public static final String DEFAULT_BROWSER = "none";
public static final boolean DEFAULT_BETA_BROWSER = false;
public static final boolean DEFAULT_MANUAL_TEST_STEPS = false;
public static final boolean DEFAULT_HEADLESS_BROWSER = false;
public static final boolean DEFAULT_MASK_PASSWORD = true;
public static final boolean DEFAULT_FIND_ERROR_CAUSE = false;
public static final String DEFAULT_RUN_MODE = "LOCAL";
public static final boolean DEFAULT_OVERRIDE_SELENIUM_NATIVE_ACTION = false;
public static final int DEFAULT_PAGE_LOAD_TIME_OUT = 90;
public static final PageLoadStrategy DEFAULT_PAGE_LOAD_STRATEGY = PageLoadStrategy.NORMAL;
public static final int DEFAULT_EXPLICIT_WAIT_TIME_OUT = 15;
public static final int DEFAULT_IMPLICIT_WAIT_TIME_OUT = 5;
public static final int DEFAULT_WEB_SESSION_TIMEOUT = 90000;
public static final int DEFAULT_TEST_RETRY_COUNT = 2;
public static final ProxyType DEFAULT_WEB_PROXY_TYPE = ProxyType.SYSTEM;
public static final boolean DEFAULT_OPTIMIZE_REPORTS = false;
public static final ArchiveMode DEFAULT_ARCHIVE= ArchiveMode.NEVER;
public static final boolean DEFAULT_KEEP_ALL_RESULTS = false;
public static final String DEFAULT_NODE_TAGS = "";
public static final String DEFAULT_DEBUG = "none";
public static final String DEFAULT_AUTOMATION_NAME = "Appium";
public static final String DEFAULT_STARTED_BY = null;
public static final boolean DEFAULT_REPORTPORTAL_ACTIVE = false;
public static final boolean DEFAULT_RANDOM_IN_ATTACHMENT_NAME = true;
public static final ElementInfo.Mode DEFAULT_ADVANCED_ELEMENT_SEARCH = ElementInfo.Mode.FALSE;
public static final boolean DEFAULT_EDGE_IE_MODE = false;
public static final int DEFAULT_REPLAY_TIME_OUT = 30;
public static final int DEFAULT_ACTION_DELAY = 200;
// group of fields below must be copied in SeleniumTestsContext constructor because they are not rediscovered with 'configureContext' method
// Data object to store all context data
private Map contextDataMap = Collections.synchronizedMap(new HashMap());
private String baseOutputDirectory; // the 'test-output' folder if not overridden
private ITestContext testNGContext = null;
private ITestResult testNGResult = null;
private Map> verificationFailuresMap = new HashMap<>();
private SeleniumRobotVariableServerConnector variableServer;
private Map variableAlreadyRequestedFromServer;
private SeleniumGridConnector seleniumGridConnector;
private List seleniumGridConnectors;
private TestManager testManagerInstance;
private TestManagerContext testManagerContext;
private BugTracker bugtrackerInstance;
private BugTrackerContext bugtrackerContext;
private SeleniumRobotServerContext seleniumRobotServerContext;
private TestStepManager testStepManager; // handles logging of test steps in this context
private boolean driverCreationBlocked = false; // if true, inside this thread, driver creation will be forbidden
private String threadId;
// folder config
private Map> idMapping;
public SeleniumTestsContext() {
// for test purpose only
variableServer = null;
seleniumGridConnector = null;
seleniumGridConnectors = new ArrayList<>();
testManagerInstance = null;
bugtrackerInstance = null;
testManagerContext = null;
testStepManager = new TestStepManager();
threadId = ThreadUtil.currentThreadInfo();
}
/**
* Create a new context from this one. This does copy only TestNG context and data map / variables
* @param toCopy the context to copy in this one
*/
public SeleniumTestsContext(SeleniumTestsContext toCopy) {
this(toCopy, true);
}
/**
*
* @param toCopy source context from which we copy data
* @param allowRequestsToDependencies if true, we will request to variable server / grid hub for new session or data
*/
public SeleniumTestsContext(SeleniumTestsContext toCopy, boolean allowRequestsToDependencies) {
contextDataMap = new HashMap<>(toCopy.contextDataMap);
testNGContext = toCopy.testNGContext;
if (!allowRequestsToDependencies && toCopy.variableAlreadyRequestedFromServer != null) {
variableAlreadyRequestedFromServer = new HashMap<>(toCopy.variableAlreadyRequestedFromServer);
}
// issue #291: also copy gridConnector and gridConnectors so that they can be re-used between BeforeMethod and Test Method
if (!allowRequestsToDependencies && toCopy.seleniumGridConnector != null) {
seleniumGridConnector = toCopy.seleniumGridConnector;
seleniumGridConnectors = new ArrayList<>(toCopy.seleniumGridConnectors);
}
if (!allowRequestsToDependencies) {
testManagerInstance = toCopy.testManagerInstance;
bugtrackerInstance = toCopy.bugtrackerInstance;
}
testNGResult = toCopy.testNGResult;
baseOutputDirectory = toCopy.baseOutputDirectory;
verificationFailuresMap = new HashMap<>(toCopy.verificationFailuresMap);
testStepManager = new TestStepManager(toCopy.testStepManager);
initSubContexts();
threadId = ThreadUtil.currentThreadInfo();
}
private void initSubContexts() {
testManagerContext = new TestManagerContext(this);
bugtrackerContext = new BugTrackerContext(this);
seleniumRobotServerContext = new SeleniumRobotServerContext(this);
}
public SeleniumTestsContext(final ITestContext context) {
testNGContext = context;
testStepManager = new TestStepManager();
initSubContexts();
buildContextFromConfig();
}
private void buildContextFromConfig() {
setConfiguration(new HashMap<>());
testManagerContext.init();
bugtrackerContext.init();
seleniumRobotServerContext.init();
setFindErrorCause(getBoolValueForTest(FIND_ERROR_CAUSE, System.getProperty(FIND_ERROR_CAUSE)));
setWebDriverGrid(getValueForTest(WEB_DRIVER_GRID, System.getProperty(WEB_DRIVER_GRID)));
setRunMode(getValueForTest(RUN_MODE, System.getProperty(RUN_MODE)));
setNodeTags(getValueForTest(NODE_TAGS, System.getProperty(NODE_TAGS)));
setMaskPassword(getBoolValueForTest(MASK_PASSWORD, System.getProperty(MASK_PASSWORD)));
setLoadIni(getValueForTest(LOAD_INI, System.getProperty(LOAD_INI)));
setWebSessionTimeout(getIntValueForTest(WEB_SESSION_TIME_OUT, System.getProperty(WEB_SESSION_TIME_OUT)));
setImplicitWaitTimeout(getIntValueForTest(IMPLICIT_WAIT_TIME_OUT, System.getProperty(IMPLICIT_WAIT_TIME_OUT)));
setExplicitWaitTimeout(getIntValueForTest(EXPLICIT_WAIT_TIME_OUT, System.getProperty(EXPLICIT_WAIT_TIME_OUT)));
setReplayTimeout(getIntValueForTest(REPLAY_TIME_OUT, System.getProperty(REPLAY_TIME_OUT)));
setPageLoadTimeout(getIntValueForTest(PAGE_LOAD_TIME_OUT, System.getProperty(PAGE_LOAD_TIME_OUT)));
setPageLoadStrategy(getValueForTest(PAGE_LOAD_STRATEGY, System.getProperty(PAGE_LOAD_STRATEGY)));
setDebug(getValueForTest(DEBUG, System.getProperty(DEBUG)));
setManualTestSteps(getBoolValueForTest(MANUAL_TEST_STEPS, System.getProperty(MANUAL_TEST_STEPS)));
setBrowser(getValueForTest(BROWSER, System.getProperty(BROWSER)));
setHeadlessBrowser(getBoolValueForTest(HEADLESS_BROWSER, System.getProperty(HEADLESS_BROWSER)));
setBrowserVersion(getValueForTest(BROWSER_VERSION, System.getProperty(BROWSER_VERSION)));
setFirefoxUserProfilePath(getValueForTest(FIREFOX_USER_PROFILE_PATH, System.getProperty(FIREFOX_USER_PROFILE_PATH)));
setChromeUserProfilePath(getValueForTest(CHROME_USER_PROFILE_PATH, System.getProperty(CHROME_USER_PROFILE_PATH)));
setEdgeUserProfilePath(getValueForTest(EDGE_USER_PROFILE_PATH, System.getProperty(EDGE_USER_PROFILE_PATH)));
setChromeOptions(getValueForTest(CHROME_OPTIONS, System.getProperty(CHROME_OPTIONS)));
setFirefoxBinary(getValueForTest(FIREFOX_BINARY_PATH, System.getProperty(FIREFOX_BINARY_PATH)));
setChromeBinary(getValueForTest(CHROME_BINARY_PATH, System.getProperty(CHROME_BINARY_PATH)));
setChromeDriverPath(getValueForTest(CHROME_DRIVER_PATH, System.getProperty(CHROME_DRIVER_PATH)));
setGeckoDriverPath(getValueForTest(GECKO_DRIVER_PATH, System.getProperty(GECKO_DRIVER_PATH)));
setEdgeDriverPath(getValueForTest(EDGE_DRIVER_PATH, System.getProperty(EDGE_DRIVER_PATH)));
setIEDriverPath(getValueForTest(IE_DRIVER_PATH, System.getProperty(IE_DRIVER_PATH)));
setUserAgent(getValueForTest(USER_AGENT, System.getProperty(USER_AGENT)));
setBetaBrowser(getBoolValueForTest(BETA_BROWSER, System.getProperty(BETA_BROWSER)));
setAssumeUntrustedCertificateIssuer(getBoolValueForTest(SET_ASSUME_UNTRUSTED_CERTIFICATE_ISSUER, System.getProperty(SET_ASSUME_UNTRUSTED_CERTIFICATE_ISSUER)));
setAcceptUntrustedCertificates(getBoolValueForTest(SET_ACCEPT_UNTRUSTED_CERTIFICATES, System.getProperty(SET_ACCEPT_UNTRUSTED_CERTIFICATES)));
setNtlmAuthTrustedUris(getValueForTest(NTLM_AUTH_TRUSTED_URIS, System.getProperty(NTLM_AUTH_TRUSTED_URIS)));
setBrowserDownloadDir(getValueForTest(BROWSER_DOWNLOAD_DIR, System.getProperty(BROWSER_DOWNLOAD_DIR)));
setCapabilities(getValueForTest(CAPABILITIES, System.getProperty(CAPABILITIES)));
setOverrideSeleniumNativeAction(getBoolValueForTest(OVERRIDE_SELENIUM_NATIVE_ACTION, System.getProperty(OVERRIDE_SELENIUM_NATIVE_ACTION)));
setAdvancedElementSearch(getValueForTest(ADVANCED_ELEMENT_SEARCH, System.getProperty(ADVANCED_ELEMENT_SEARCH)));
setWebProxyType(getValueForTest(WEB_PROXY_TYPE, System.getProperty(WEB_PROXY_TYPE)));
setWebProxyAddress(getValueForTest(WEB_PROXY_ADDRESS, System.getProperty(WEB_PROXY_ADDRESS)));
setWebProxyLogin(getValueForTest(WEB_PROXY_LOGIN, System.getProperty(WEB_PROXY_LOGIN)));
setWebProxyPassword(getValueForTest(WEB_PROXY_PASSWORD, System.getProperty(WEB_PROXY_PASSWORD)));
setWebProxyPort(getIntValueForTest(WEB_PROXY_PORT, System.getProperty(WEB_PROXY_PORT)));
setWebProxyExclude(getValueForTest(WEB_PROXY_EXCLUDE, System.getProperty(WEB_PROXY_EXCLUDE)));
setWebProxyPac(getValueForTest(WEB_PROXY_PAC, System.getProperty(WEB_PROXY_PAC)));
setSnapshotScrollDelay(getIntValueForTest(SNAPSHOT_SCROLL_DELAY, System.getProperty(SNAPSHOT_SCROLL_DELAY)));
setSnapshotBottomCropping(getIntValueForTest(SNAPSHOT_BOTTOM_CROPPING, System.getProperty(SNAPSHOT_BOTTOM_CROPPING)));
setSnapshotTopCropping(getIntValueForTest(SNAPSHOT_TOP_CROPPING, System.getProperty(SNAPSHOT_TOP_CROPPING)));
setCaptureSnapshot(getBoolValueForTest(CAPTURE_SNAPSHOT, System.getProperty(CAPTURE_SNAPSHOT)));
setCaptureNetwork(getBoolValueForTest(CAPTURE_NETWORK, System.getProperty(CAPTURE_NETWORK)));
setVideoCapture(getValueForTest(VIDEO_CAPTURE, System.getProperty(VIDEO_CAPTURE)));
setReporterPluginClasses(getValueForTest(REPORTER_PLUGIN_CLASSES, System.getProperty(REPORTER_PLUGIN_CLASSES)));
setSoftAssertEnabled(getBoolValueForTest(SOFT_ASSERT_ENABLED, System.getProperty(SOFT_ASSERT_ENABLED)));
setTestRetryCount(getIntValueForTest(TEST_RETRY_COUNT, System.getProperty(TEST_RETRY_COUNT)));
setWebDriverListener(getValueForTest(WEB_DRIVER_LISTENER, System.getProperty(WEB_DRIVER_LISTENER)));
setAppiumCapabilities(getValueForTest(APPIUM_CAPS, System.getProperty(APPIUM_CAPS)));
setAppiumServerUrl(getValueForTest(APPIUM_SERVER_URL, System.getProperty(APPIUM_SERVER_URL)));
setDeviceName(getValueForTest(DEVICE_NAME, System.getProperty(DEVICE_NAME)));
setDeviceId(getValueForTest(DEVICE_ID, System.getProperty(DEVICE_ID)));
setDeviceList(getValueForTest(DEVICE_LIST, null));
setFullReset(getBoolValueForTest(FULL_RESET, System.getProperty(FULL_RESET)));
setApp(getValueForTest(APP, System.getProperty(APP)));
setStartedBy(getValueForTest(STARTED_BY, System.getProperty(STARTED_BY)));
setCucumberTags(getValueForTest(CUCUMBER_TAGS, System.getProperty(CUCUMBER_TAGS)));
setCucumberTests(getValueForTest(CUCUMBER_TESTS, System.getProperty(CUCUMBER_TESTS)));
setCucumberImplementationPackage(getValueForTest(CUCUMBER_IMPLEMENTATION_PKG, System.getProperty(CUCUMBER_IMPLEMENTATION_PKG)));
setTestEnv(getValueForTest(TEST_ENV, System.getProperty(TEST_ENV)));
// By default test is assumed to be executed on default browser on android emulator
setAutomationName(getValueForTest(AUTOMATION_NAME, System.getProperty(AUTOMATION_NAME)));
setAppPackage(getValueForTest(APP_PACKAGE, System.getProperty(APP_PACKAGE)));
setAppActivity(getValueForTest(APP_ACTIVITY, System.getProperty(APP_ACTIVITY)));
setAppWaitActivity(getValueForTest(APP_WAIT_ACTIVITY, System.getProperty(APP_WAIT_ACTIVITY)));
setNewCommandTimeout(getIntValueForTest(NEW_COMMAND_TIMEOUT, System.getProperty(NEW_COMMAND_TIMEOUT)));
setActionDelay(getIntValueForTest(ACTION_DELAY, System.getProperty(ACTION_DELAY)));
setVersion(getValueForTest(VERSION, System.getProperty(VERSION)));
setPlatform(getValueForTest(PLATFORM, System.getProperty(PLATFORM)));
setCustomTestReports(getValueForTest(CUSTOM_TEST_REPORTS, System.getProperty(CUSTOM_TEST_REPORTS)));
setCustomSummaryReports(getValueForTest(CUSTOM_SUMMARY_REPORTS, System.getProperty(CUSTOM_SUMMARY_REPORTS)));
setArchiveToFile(getValueForTest(ARCHIVE_TO_FILE, System.getProperty(ARCHIVE_TO_FILE)));
setArchive(getValueForTest(ARCHIVE, System.getProperty(ARCHIVE)));
setOptimizeReports(getBoolValueForTest(OPTIMIZE_REPORTS, System.getProperty(OPTIMIZE_REPORTS)));
setKeepAllResults(getBoolValueForTest(KEEP_ALL_RESULTS, System.getProperty(KEEP_ALL_RESULTS)));
setViewPortWidth(getIntValueForTest(VIEWPORT_WIDTH, System.getProperty(VIEWPORT_WIDTH)));
setViewPortHeight(getIntValueForTest(VIEWPORT_HEIGHT, System.getProperty(VIEWPORT_HEIGHT)));
setNeoloadUserPath(getValueForTest(NEOLOAD_USER_PATH, System.getProperty(NEOLOAD_USER_PATH)));
setRandomInAttachmentNames(getBoolValueForTest(RANDOM_IN_ATTACHMENT_NAME, System.getProperty(RANDOM_IN_ATTACHMENT_NAME)));
//setReportPortalActive(getBoolValueForTest(REPORTPORTAL_ACTIVE, System.getProperty(REPORTPORTAL_ACTIVE)));
if (testNGContext != null) {
// this value will be overwritten for thread context by a call to "configureContext"
setOutputDirectory(getValueForTest(OUTPUT_DIRECTORY, System.getProperty(OUTPUT_DIRECTORY)), testNGContext, true);
baseOutputDirectory = getOutputDirectory();
// parse other parameters that are defined in testng xml or as user parameters but not defined
// in this context. Called here so that user defined parameters can be accessed inside @Before / @After annotated methods
setTestConfiguration();
}
}
/**
* If chrome or firefox binary is redefined in parameter, update list of installed browser so
* that it matches those really used
*/
private void updateInstalledBrowsers() {
Map> installedBrowsers = OSUtility.getInstalledBrowsersWithVersion(getBetaBrowser());
if (getFirefoxBinPath() != null) {
String version = OSUtility.getFirefoxVersion(getFirefoxBinPath());
List infos = installedBrowsers.getOrDefault(BrowserType.FIREFOX, new ArrayList<>());
infos.add(new BrowserInfo(BrowserType.FIREFOX, OSUtility.extractFirefoxVersion(version), getFirefoxBinPath()));
installedBrowsers.put(BrowserType.FIREFOX, infos);
}
if (getChromeBinPath() != null) {
String version = OSUtility.getChromeVersion(getChromeBinPath());
List infos = installedBrowsers.getOrDefault(BrowserType.CHROME, new ArrayList<>());
infos.add(new BrowserInfo(BrowserType.CHROME, OSUtility.extractChromeOrChromiumVersion(version), getChromeBinPath()));
installedBrowsers.put(BrowserType.CHROME, infos);
}
}
/**
* update test data according to platform
* @param platform
*/
public void updateTestAndMobile(String platform) {
setPlatform(platform);
// determines test_type according to input configuration
configureTestType();
// get mobile platform version if one is defined in device list and a deviceName is set in parameters
updateDeviceMobileVersion();
// get mobile platform version
updatePlatformVersion();
}
/**
* From platform name, in case of Desktop platform, do nothing and in case of mobile, extract OS version from name
* as platformName will be 'Android 5.0' for example
*
* @throws ConfigurationException in mobile, if version is not present
*/
private void updatePlatformVersion() {
try {
Platform currentPlatform = Platform.fromString(getPlatform());
if (!(currentPlatform.is(Platform.WINDOWS)
|| currentPlatform.is(Platform.MAC)
|| currentPlatform.is(Platform.UNIX)
|| currentPlatform.is(Platform.ANY) && getRunMode() == DriverMode.GRID)) {
throw new WebDriverException("");
}
} catch (WebDriverException e) {
if (getPlatform().toLowerCase().startsWith("android") || getPlatform().toLowerCase().startsWith("ios")) {
String[] pfVersion = getPlatform().split(" ", 2);
try {
setPlatform(pfVersion[0]);
setMobilePlatformVersion(pfVersion[1]);
} catch (IndexOutOfBoundsException x) {
setMobilePlatformVersion(null);
logger.warn("For mobile platform, platform name should contain version. Ex: 'Android 5.0' or 'iOS 9.1'. Else, first found device is used");
}
} else {
throw new ConfigurationException(String.format("Platform %s has not been recognized as a valid platform", getPlatform()));
}
}
}
/**
* Configure test type according to platform, browser and app parameters
*/
private void configureTestType() {
if (getPlatform().toLowerCase().startsWith("android")) {
if (getApp().isEmpty() && getAppActivity() == null) { // a browser name should be defined
setTestType(TestType.APPIUM_WEB_ANDROID);
} else {
setTestType(TestType.APPIUM_APP_ANDROID);
}
} else if (getPlatform().toLowerCase().startsWith("ios")) {
if (getApp().isEmpty() && getBrowser() != BrowserType.NONE) { // a browser name should be defined
setTestType(TestType.APPIUM_WEB_IOS);
} else {
setTestType(TestType.APPIUM_APP_IOS);
}
} else if (getPlatform().toLowerCase().startsWith("windows") && !((getApp() == null || getApp().isEmpty()) && (getAppActivity() == null || getAppActivity().isEmpty()))) {
setTestType(TestType.APPIUM_APP_WINDOWS);
} else {
if (getBrowser() == BrowserType.NONE) {
setTestType(TestType.NON_GUI);
} else {
setTestType(TestType.WEB);
}
}
}
/**
* Search mobile platform version according to device name if one has been defined in testConfig file
*/
private void updateDeviceMobileVersion() {
Map deviceList = getDeviceList();
if (getDeviceName() != null && !getDeviceName().isEmpty() && !deviceList.isEmpty()) {
setPlatform(deviceList.get(getDeviceName()));
}
}
/**
* returns the selenium grid connector if mode requests it
* @return
*/
private List connectGrid() {
if (getRunMode() == DriverMode.GRID) {
if (getWebDriverGrid() != null && !getWebDriverGrid().isEmpty()) {
return SeleniumGridConnectorFactory.getInstances(getWebDriverGrid());
} else {
throw new ConfigurationException("Test should be executed with Selenium Grid but URL is not set");
}
} else {
return null;
}
}
public void addVerificationFailures(final ITestResult result, final List failures) {
this.verificationFailuresMap.put(result, failures);
}
public void addVerificationFailures(final ITestResult result, final Throwable failure) {
if (verificationFailuresMap.get(result) != null) {
this.verificationFailuresMap.get(result).add(failure);
} else {
ArrayList failures = new ArrayList<>();
failures.add(failure);
this.addVerificationFailures(result, failures);
}
}
/**
* Get all JVM properties and filters the java one so that only user defined JVM arguments are returned
* @return
*/
public Map getCommandLineProperties() {
Map props = new HashMap<>();
for (Entry