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.stream.Collectors;
import java.util.Set;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.json.JSONObject;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.Platform;
import org.openqa.selenium.Proxy.ProxyType;
import org.openqa.selenium.WebDriverException;
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.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.utils.TestNGResultUtils;
import com.seleniumtests.customexception.ConfigurationException;
import com.seleniumtests.driver.BrowserType;
import com.seleniumtests.driver.DriverExceptionListener;
import com.seleniumtests.driver.DriverMode;
import com.seleniumtests.driver.TestType;
import com.seleniumtests.driver.screenshots.VideoCaptureMode;
import com.seleniumtests.reporter.PluginsHelper;
import com.seleniumtests.reporter.logger.ArchiveMode;
import com.seleniumtests.reporter.reporters.ReportInfo;
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;
/**
* Defines TestNG context used in STF.
*/
public class SeleniumTestsContext {
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 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 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"; // profile utilisateur firefox
public static final String USE_DEFAULT_FIREFOX_PROFILE = "useFirefoxDefaultProfile";// utilisation du profile firefox par défaut
public static final String OPERA_USER_PROFILE_PATH = "operaUserProfilePath"; // profile utilisateur opéra
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 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
// selenium robot server parameters
public static final String SELENIUMROBOTSERVER_URL = "seleniumRobotServerUrl";
public static final String SELENIUMROBOTSERVER_ACTIVE = "seleniumRobotServerActive";
public static final String SELENIUMROBOTSERVER_COMPARE_SNAPSHOT = "seleniumRobotServerCompareSnapshots"; // whether we should use the snapshots created by robot to compare them to a previous execution. This option only operates when SeleniumRobot server is connected
public static final String SELENIUMROBOTSERVER_RECORD_RESULTS = "seleniumRobotServerRecordResults"; // whether we should record test results to server. This option only operates when SeleniumRobot server is connected
public static final String SELENIUMROBOTSERVER_VARIABLES_OLDER_THAN = "seleniumRobotServerVariablesOlderThan"; // whether we should get from server variables which were created at least X days ago
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 ENABLE_JAVASCRIPT = "enableJavascript"; // activation du javascrit dans le navigateur.
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 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 ENABLE_EXCEPTION_LISTENER = "enableExceptionListener"; // TODO: voir son effet, activé par défaut
public static final String DP_TAGS_INCLUDE = "dpTagsInclude"; //
public static final String DP_TAGS_EXCLUDE = "dpTagsExclude"; // Utilisé pour la lecture de fichiers CSV/XLS des DataProvider TODO: a étudier comment cela fonctionne
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 WEB_DRIVER_LISTENER = "webDriverListener";
public static final String OPTIMIZE_REPORTS = "optimizeReports";
public static final String TEST_METHOD_SIGNATURE = "testMethodSignature";
public static final String PLUGIN_CONFIG_PATH = "pluginConfigPath";
public static final String TEST_TYPE = "testType"; // configured automatically
public static final String TMS_RUN = "tmsRun"; // option for configuring test (from test management system point of view) currently running, like HP ALM or Squash TM
public static final String TMS_CONNECT = "tmsConnect"; // option for configuring test management system, like HP ALM or Squash TM (url, user, password, ...)
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 FULL_RESET = "fullReset"; // whether we should do a full reset (default is true)
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.
public static final String CLOUD_API_KEY = "cloudApiKey"; // clé d'accès (dépend des services)
public static final String TEST_NAME = "testName";
public static final String RELATIVE_OUTPUT_DIR = "relativeOutputDir";
// 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 storage
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
// default values
public static final List DEFAULT_CUSTOM_TEST_REPORTS = Arrays.asList(new ReportInfo("PERF::xml::reporter/templates/report.perf.vm"));
public 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_VIDEO_CAPTURE = "onError";
public static final int DEFAULT_SNAPSHOT_TOP_CROPPING = 0;
public static final int DEFAULT_SNAPSHOT_BOTTOM_CROPPING = 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 boolean DEFAULT_USE_DEFAULT_FIREFOX_PROFILE = true;
public static final String DEFAULT_BROWSER = "none";
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 String DEFAULT_RUN_MODE = "LOCAL";
public static final boolean DEFAULT_OVERRIDE_SELENIUM_NATIVE_ACTION = false;
public static final boolean DEFAULT_SELENIUMROBOTSERVER_RECORD_RESULTS = false;
public static final boolean DEFAULT_SELENIUMROBOTSERVER_COMPARE_SNAPSHOT = false;
public static final boolean DEFAULT_SELENIUMROBOTSERVER_ACTIVE = false;
public static final int DEFAULT_SELENIUMROBOTSERVER_VARIABLES_OLDER_THAN = 0;
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 String DEFAULT_SELENIUMROBOTSERVER_URL = null;
public static final JSONObject DEFAULT_TMS_RUN = new JSONObject();
public static final JSONObject DEFAULT_TMS_CONNECT = new JSONObject();
public static final ProxyType DEFAULT_WEB_PROXY_TYPE = ProxyType.AUTODETECT;
public static final boolean DEFAULT_OPTIMIZE_REPORTS = false;
public static final String DEFAULT_ARCHIVE= "false";
public static final String DEFAULT_NODE_TAGS = "";
public static final String DEFAULT_DEBUG = "none";
public static final ElementInfo.Mode DEFAULT_ADVANCED_ELEMENT_SEARCH = ElementInfo.Mode.FALSE;
public static final int DEFAULT_REPLAY_TIME_OUT = 30;
// 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 SeleniumGridConnector seleniumGridConnector;
private List seleniumGridConnectors;
private TestManager testManagerIntance;
private boolean driverCreationBlocked = false; // if true, inside this thread, driver creation will be forbidden
// folder config
private Map> idMapping;
public SeleniumTestsContext() {
// for test purpose only
variableServer = null;
seleniumGridConnector = null;
seleniumGridConnectors = new ArrayList<>();
testManagerIntance = null;
}
/**
* 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) {
contextDataMap = new HashMap<>(toCopy.contextDataMap);
testNGContext = toCopy.testNGContext;
testNGResult = toCopy.testNGResult;
baseOutputDirectory = toCopy.baseOutputDirectory;
verificationFailuresMap = new HashMap<>(toCopy.verificationFailuresMap);
}
public SeleniumTestsContext(final ITestContext context) {
testNGContext = context;
buildContextFromConfig();
}
private void buildContextFromConfig() {
setConfiguration(new HashMap<>());
setSeleniumRobotServerUrl(getValueForTest(SELENIUMROBOTSERVER_URL, System.getProperty(SELENIUMROBOTSERVER_URL)));
setSeleniumRobotServerActive(getBoolValueForTest(SELENIUMROBOTSERVER_ACTIVE, System.getProperty(SELENIUMROBOTSERVER_ACTIVE)));
setSeleniumRobotServerCompareSnapshot(getBoolValueForTest(SELENIUMROBOTSERVER_COMPARE_SNAPSHOT, System.getProperty(SELENIUMROBOTSERVER_COMPARE_SNAPSHOT)));
setSeleniumRobotServerRecordResults(getBoolValueForTest(SELENIUMROBOTSERVER_RECORD_RESULTS, System.getProperty(SELENIUMROBOTSERVER_RECORD_RESULTS)));
setSeleniumRobotServerVariableOlderThan(getIntValueForTest(SELENIUMROBOTSERVER_VARIABLES_OLDER_THAN, System.getProperty(SELENIUMROBOTSERVER_VARIABLES_OLDER_THAN)));
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)));
setUseDefaultFirefoxProfile(getBoolValueForTest(USE_DEFAULT_FIREFOX_PROFILE, System.getProperty(USE_DEFAULT_FIREFOX_PROFILE)));
setOperaUserProfilePath(getValueForTest(OPERA_USER_PROFILE_PATH, System.getProperty(OPERA_USER_PROFILE_PATH)));
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)));
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)));
setJavascriptEnabled(getBoolValueForTest(ENABLE_JAVASCRIPT, System.getProperty(ENABLE_JAVASCRIPT)));
setNtlmAuthTrustedUris(getValueForTest(NTLM_AUTH_TRUSTED_URIS, System.getProperty(NTLM_AUTH_TRUSTED_URIS)));
setBrowserDownloadDir(getValueForTest(BROWSER_DOWNLOAD_DIR, System.getProperty(BROWSER_DOWNLOAD_DIR)));
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)));
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)));
setEnableExceptionListener(getBoolValueForTest(ENABLE_EXCEPTION_LISTENER, System.getProperty(ENABLE_EXCEPTION_LISTENER)));
setDpTagsInclude(getValueForTest(DP_TAGS_INCLUDE, System.getProperty(DP_TAGS_INCLUDE)));
setDpTagsExclude(getValueForTest(DP_TAGS_EXCLUDE, System.getProperty(DP_TAGS_EXCLUDE)));
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)));
setTmsRun(getValueForTest(TMS_RUN, System.getProperty(TMS_RUN)));
setTmsConnect(getValueForTest(TMS_CONNECT, System.getProperty(TMS_CONNECT)));
setDeviceName(getValueForTest(DEVICE_NAME, System.getProperty(DEVICE_NAME)));
setDeviceList(getValueForTest(DEVICE_LIST, null));
setFullReset(getBoolValueForTest(FULL_RESET, System.getProperty(FULL_RESET)));
setApp(getValueForTest(APP, System.getProperty(APP)));
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
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)));
setVersion(getValueForTest(VERSION, System.getProperty(VERSION)));
setPlatform(getValueForTest(PLATFORM, System.getProperty(PLATFORM)));
setCloudApiKey(getValueForTest(CLOUD_API_KEY, System.getProperty(CLOUD_API_KEY)));
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)));
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)));
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();
if (getFirefoxBinPath() != null) {
String version = OSUtility.getFirefoxVersion(getFirefoxBinPath());
installedBrowsers.get(BrowserType.FIREFOX).add(new BrowserInfo(BrowserType.FIREFOX, version, getFirefoxBinPath()));
}
if (getChromeBinPath() != null) {
String version = OSUtility.getChromeVersion(getChromeBinPath());
installedBrowsers.get(BrowserType.CHROME).add(new BrowserInfo(BrowserType.CHROME, version, getChromeBinPath()));
}
}
/**
* 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) {
return;
} else {
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]);
return;
} 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()) { // 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()) { // a browser name should be defined
setTestType(TestType.APPIUM_WEB_IOS);
} else {
setTestType(TestType.APPIUM_APP_IOS);
}
} 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()));
}
}
// TODO: this call should be moved into postInit method as SeleniumRobotVariableServerConnector calls SeleniumTestsContextManager.getThreadContext() which may not be initialized
private SeleniumRobotVariableServerConnector connectSeleniumRobotServer() {
if (testNGResult == null) {
return null;
}
// in case we find the url of variable server and it's marked as active, use it
if (getSeleniumRobotServerActive() != null && getSeleniumRobotServerActive() && getSeleniumRobotServerUrl() != null) {
logger.info(String.format("%s key found, and set to true, trying to get variable from variable server %s [%s]",
SELENIUMROBOTSERVER_ACTIVE,
getSeleniumRobotServerUrl(),
SELENIUMROBOTSERVER_URL));
SeleniumRobotVariableServerConnector vServer = new SeleniumRobotVariableServerConnector(getSeleniumRobotServerActive(), getSeleniumRobotServerUrl(), TestNGResultUtils.getTestName(testNGResult));
if (!vServer.isAlive()) {
throw new ConfigurationException(String.format("Variable server %s could not be contacted", getSeleniumRobotServerUrl()));
}
return vServer;
} else {
logger.info(String.format("%s key not found or set to false, or url key %s has not been set", SELENIUMROBOTSERVER_ACTIVE, SELENIUMROBOTSERVER_URL));
return null;
}
}
/**
* 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