Best Selenium code snippet using org.openqa.selenium.support.events.Interface WebDriverListener.onError
Source:SeleniumTestsContext.java
...189 public static final String DEFAULT_OUTPUT_DIRECTORY = "defaultOutputDirectory"; // folder where TestNG would write it's results if not overwritten190 public static final String CUSTOM_TEST_REPORTS = "customTestReports";191 public static final String CUSTOM_SUMMARY_REPORTS = "customSummaryReports";192 public static final String ARCHIVE_TO_FILE = "archiveToFile"; // path to the file where archive will be done.193 public static final String ARCHIVE = "archive"; // whether archiving is done. DEfault is false, other values are 'true', 'onSuccess', 'onError'194 public static final String KEEP_ALL_RESULTS = "keepAllResults"; // if true, will keep all result even if test is retried, allowing to analyze them195 196 public static final String WEB_DRIVER_LISTENER = "webDriverListener";197 public static final String OPTIMIZE_REPORTS = "optimizeReports";198199 public static final String TEST_METHOD_SIGNATURE = "testMethodSignature";200 public static final String REPORTER_PLUGIN_CLASSES = "reporterPluginClasses"; // comma-seperated list of classes to call when a custom reporter needs to be added201202 public static final String TEST_TYPE = "testType"; // configured automatically203204 public static final String CUCUMBER_TESTS = "cucumberTests"; // liste des tests en mode cucumber205 public static final String CUCUMBER_TAGS = "cucumberTags"; // liste des tags cucumber206 public static final String TEST_ENV = "env"; // environnement de test pour le SUT. Permet d'accéder aux configurations spécifiques du fichier env.ini207 public static final String CUCUMBER_IMPLEMENTATION_PKG = "cucumberPackage"; // nom du package java pour les classes cucumber, car celui-ci n'est pas accessible par testNG208 209 // Appium specific properties210 public static final String APP = "app"; // Chemin de l'application mobile (local ou distant)211 public static final String MOBILE_PLATFORM_VERSION = "mobilePlatformVersion";// Mobile OS version. It's deduced from platform name and not read directly from parameters212 public static final String DEVICE_NAME = "deviceName"; // Nom du terminal utilisé pour le test213 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 214 public static final String FULL_RESET = "fullReset"; // whether we should do a full reset (default is true)215 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.html216 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 one217 218 public static final String APP_PACKAGE = "appPackage"; // package de l'application219 public static final String APP_ACTIVITY = "appActivity"; // activité à démarrer (Android)220 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 attend221 public static final String NEW_COMMAND_TIMEOUT = "newCommandTimeout"; // Attente maximale entre 2 commandes envoyées à appium222223 // Cloud specific properties224 public static final String VERSION = "version"; // browser version225 public static final String PLATFORM = "platform"; // platform on which test should execute. Ex: Windows 7, Android, iOS, Linux, OS X 10.10. 226 public static final String CLOUD_API_KEY = "cloudApiKey"; // clé d'accès (dépend des services)227228 // Neoload specific properties229 public static final String NEOLOAD_USER_PATH = "neoloadUserPath"; // name of the neoload "user path" that will be created in Design mode230 231 public static final String REPORTPORTAL_ACTIVE = "reportPortalActive"; // whether report portal is activated232 233 // internal use234 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 file235 public static final String TEST_NAME = "testName";236 public static final String RELATIVE_OUTPUT_DIR = "relativeOutputDir";237 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.238 // this option disables the behaviour FOR TEST PURPOSE239 240 // default values241 protected static final List<ReportInfo> DEFAULT_CUSTOM_TEST_REPORTS = Arrays.asList(new ReportInfo("PERF::xml::reporter/templates/report.perf.vm"));242 protected static final List<ReportInfo> DEFAULT_CUSTOM_SUMMARY_REPORTS = Arrays.asList(new ReportInfo("results::json::reporter/templates/report.summary.json.vm"));243 public static final int DEFAULT_NEW_COMMAND_TIMEOUT = 120;244 public static final String DEFAULT_TEST_ENV = "DEV";245 public static final String DEFAULT_CUCUMBER_TESTS = "";246 public static final String DEFAULT_CUCUMBER_TAGS = "";247 public static final String DEFAULT_APP = "";248 public static final String DEFAULT_DEVICE_LIST = "{}";249 public static final boolean DEFAULT_SOFT_ASSERT_ENABLED = true;250 public static final boolean DEFAULT_ENABLE_EXCEPTION_LISTENER = true;251 public static final boolean DEFAULT_CAPTURE_SNAPSHOT = true;252 public static final boolean DEFAULT_CAPTURE_NETWORK = false;253 public static final String DEFAULT_INITIAL_URL = "about:blank";254 public static final String DEFAULT_VIDEO_CAPTURE = "onError";255 public static final Integer DEFAULT_SNAPSHOT_TOP_CROPPING = null;256 public static final Integer DEFAULT_SNAPSHOT_BOTTOM_CROPPING = null;257 public static final int DEFAULT_SNAPSHOT_SCROLL_DELAY = 0;258 public static final boolean DEFAULT_ENABLE_JAVASCRIPT = true;259 public static final boolean DEFAULT_SET_ACCEPT_UNTRUSTED_CERTIFICATES = true;260 public static final boolean DEFAULT_SET_ASSUME_UNTRUSTED_CERTIFICATE_ISSUER = true;261 public static final String DEFAULT_BROWSER = "none";262 public static final boolean DEFAULT_BETA_BROWSER = false;263 public static final boolean DEFAULT_MANUAL_TEST_STEPS = false;264 public static final boolean DEFAULT_HEADLESS_BROWSER = false;265 public static final boolean DEFAULT_MASK_PASSWORD = true;266 public static final boolean DEFAULT_FIND_ERROR_CAUSE = false;267 public static final String DEFAULT_RUN_MODE = "LOCAL";268 public static final boolean DEFAULT_OVERRIDE_SELENIUM_NATIVE_ACTION = false;269 public static final boolean DEFAULT_SELENIUMROBOTSERVER_RECORD_RESULTS = false;270 public static final boolean DEFAULT_SELENIUMROBOTSERVER_COMPARE_SNAPSHOT = false;271 public static final int DEFAULT_SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_TTL = 30;272 public static final SnapshotComparisonBehaviour DEFAULT_SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_BEHAVIOUR = SnapshotComparisonBehaviour.DISPLAY_ONLY;273 public static final boolean DEFAULT_SELENIUMROBOTSERVER_ACTIVE = false;274 public static final String DEFAULT_SELENIUMROBOTSERVER_TOKEN = null;275 public static final int DEFAULT_SELENIUMROBOTSERVER_VARIABLES_OLDER_THAN = 0;276 public static final int DEFAULT_PAGE_LOAD_TIME_OUT = 90;277 public static final PageLoadStrategy DEFAULT_PAGE_LOAD_STRATEGY = PageLoadStrategy.NORMAL;278 public static final int DEFAULT_EXPLICIT_WAIT_TIME_OUT = 15;279 public static final int DEFAULT_IMPLICIT_WAIT_TIME_OUT = 5;280 public static final int DEFAULT_WEB_SESSION_TIMEOUT = 90000;281 public static final int DEFAULT_TEST_RETRY_COUNT = 2;282 public static final String DEFAULT_SELENIUMROBOTSERVER_URL = null;283 public static final ProxyType DEFAULT_WEB_PROXY_TYPE = ProxyType.AUTODETECT;284 public static final boolean DEFAULT_OPTIMIZE_REPORTS = false;285 public static final ArchiveMode DEFAULT_ARCHIVE= ArchiveMode.NEVER;286 public static final boolean DEFAULT_KEEP_ALL_RESULTS = false;287 public static final String DEFAULT_NODE_TAGS = "";288 public static final String DEFAULT_DEBUG = "none";289 public static final String DEFAULT_AUTOMATION_NAME = "Appium";290 public static final String DEFAULT_TMS_URL = null;291 public static final String DEFAULT_TMS_TYPE = null;292 public static final String DEFAULT_BUGTRACKER_URL = null;293 public static final String DEFAULT_BUGTRACKER_TYPE = null;294 public static final String DEFAULT_STARTED_BY = null;295 public static final boolean DEFAULT_REPORTPORTAL_ACTIVE = false;296 public static final boolean DEFAULT_RANDOM_IN_ATTACHMENT_NAME = true;297 public static final ElementInfo.Mode DEFAULT_ADVANCED_ELEMENT_SEARCH = ElementInfo.Mode.FALSE;298 public static final String DEFAULT_IMAGE_FIELD_DETECTOR_SERVER_URL = null;299 public static final boolean DEFAULT_EDGE_IE_MODE = false;300 301 public static final int DEFAULT_REPLAY_TIME_OUT = 30;302 303 304305 // group of fields below must be copied in SeleniumTestsContext constructor because they are not rediscovered with 'configureContext' method306 // Data object to store all context data307 private Map<String, Object> contextDataMap = Collections.synchronizedMap(new HashMap<String, Object>());308 private String baseOutputDirectory; // the 'test-output' folder if not overridden309 private ITestContext testNGContext = null;310 private ITestResult testNGResult = null;311 private Map<ITestResult, List<Throwable>> verificationFailuresMap = new HashMap<>();312 313 private SeleniumRobotVariableServerConnector variableServer;314 private Map<String, TestVariable> variableAlreadyRequestedFromServer;315 private SeleniumGridConnector seleniumGridConnector;316 private List<SeleniumGridConnector> seleniumGridConnectors;317 private TestManager testManagerInstance;318 private BugTracker bugtrackerInstance;319 private FieldDetectorConnector fieldDetectorInstance;320 private TestStepManager testStepManager; // handles logging of test steps in this context321 private boolean driverCreationBlocked = false; // if true, inside this thread, driver creation will be forbidden322 323 // folder config324 private Map<String, HashMap<String,String>> idMapping;325 326 public SeleniumTestsContext() {327 // for test purpose only328 variableServer = null;329 seleniumGridConnector = null;330 seleniumGridConnectors = new ArrayList<>();331 testManagerInstance = null;332 bugtrackerInstance = null;333 fieldDetectorInstance = null;334 testStepManager = new TestStepManager();335 }336 337 /**338 * Create a new context from this one. This does copy only TestNG context and data map / variables339 * @param toCopy the context to copy in this one340 */341 public SeleniumTestsContext(SeleniumTestsContext toCopy) {342 this(toCopy, true);343 }344 345 /**346 * 347 * @param toCopy source context from which we copy data348 * @param allowRequestsToDependencies if true, we will request to variable server / grid hub for new session or data 349 */350 public SeleniumTestsContext(SeleniumTestsContext toCopy, boolean allowRequestsToDependencies) {351 contextDataMap = new HashMap<>(toCopy.contextDataMap); 352 testNGContext = toCopy.testNGContext;353 if (!allowRequestsToDependencies && toCopy.variableAlreadyRequestedFromServer != null) {354 variableAlreadyRequestedFromServer = new HashMap<>(toCopy.variableAlreadyRequestedFromServer);355 }356 357 // issue #291: also copy gridConnector and gridConnectors so that they can be re-used between BeforeMethod and Test Method358 if (!allowRequestsToDependencies && toCopy.seleniumGridConnector != null) {359 seleniumGridConnector = toCopy.seleniumGridConnector;360 seleniumGridConnectors = new ArrayList<>(toCopy.seleniumGridConnectors);361 }362 363 if (!allowRequestsToDependencies) {364 testManagerInstance = toCopy.testManagerInstance;365 bugtrackerInstance = toCopy.bugtrackerInstance;366 fieldDetectorInstance = toCopy.fieldDetectorInstance;367 }368 369 testNGResult = toCopy.testNGResult;370 baseOutputDirectory = toCopy.baseOutputDirectory;371 verificationFailuresMap = new HashMap<>(toCopy.verificationFailuresMap);372 testStepManager = new TestStepManager(toCopy.testStepManager);373 374 }375 376 public SeleniumTestsContext(final ITestContext context) {377 testNGContext = context;378379 testStepManager = new TestStepManager();380 buildContextFromConfig();381 }382 383 private void buildContextFromConfig() {384 setConfiguration(new HashMap<>());385 386 setImageFieldDetectorServerUrl(getValueForTest(IMAGE_FIELD_DETECTOR_SERVER_URL, System.getProperty(IMAGE_FIELD_DETECTOR_SERVER_URL)));387 setSeleniumRobotServerUrl(getValueForTest(SELENIUMROBOTSERVER_URL, System.getProperty(SELENIUMROBOTSERVER_URL)));388 setSeleniumRobotServerActive(getBoolValueForTest(SELENIUMROBOTSERVER_ACTIVE, System.getProperty(SELENIUMROBOTSERVER_ACTIVE)));389 setSeleniumRobotServerToken(getValueForTest(SELENIUMROBOTSERVER_TOKEN, System.getProperty(SELENIUMROBOTSERVER_TOKEN)));390 setSeleniumRobotServerCompareSnapshot(getBoolValueForTest(SELENIUMROBOTSERVER_COMPARE_SNAPSHOT, System.getProperty(SELENIUMROBOTSERVER_COMPARE_SNAPSHOT)));391 setSeleniumRobotServerCompareSnapshotTtl(getIntValueForTest(SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_TTL, System.getProperty(SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_TTL)));392 setSeleniumRobotServerCompareSnapshotBehaviour(getValueForTest(SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_BEHAVIOUR, System.getProperty(SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_BEHAVIOUR)));393 setSeleniumRobotServerRecordResults(getBoolValueForTest(SELENIUMROBOTSERVER_RECORD_RESULTS, System.getProperty(SELENIUMROBOTSERVER_RECORD_RESULTS)));394 setSeleniumRobotServerVariableOlderThan(getIntValueForTest(SELENIUMROBOTSERVER_VARIABLES_OLDER_THAN, System.getProperty(SELENIUMROBOTSERVER_VARIABLES_OLDER_THAN)));395 396 setFindErrorCause(getBoolValueForTest(FIND_ERROR_CAUSE, System.getProperty(FIND_ERROR_CAUSE)));397 398 setTmsType(getValueForTest(TMS_TYPE, System.getProperty(TMS_TYPE)));399 setTmsUrl(getValueForTest(TMS_URL, System.getProperty(TMS_URL)));400 setTmsUser(getValueForTest(TMS_USER, System.getProperty(TMS_USER)));401 setTmsPassword(getValueForTest(TMS_PASSWORD, System.getProperty(TMS_PASSWORD)));402 setTmsProject(getValueForTest(TMS_PROJECT, System.getProperty(TMS_PROJECT)));403 404 setBugtrackerType(getValueForTest(BUGTRACKER_TYPE, System.getProperty(BUGTRACKER_TYPE)));405 setBugtrackerUrl(getValueForTest(BUGTRACKER_URL, System.getProperty(BUGTRACKER_URL)));406 setBugtrackerUser(getValueForTest(BUGTRACKER_USER, System.getProperty(BUGTRACKER_USER)));407 setBugtrackerPassword(getValueForTest(BUGTRACKER_PASSWORD, System.getProperty(BUGTRACKER_PASSWORD)));408 setBugtrackerProject(getValueForTest(BUGTRACKER_PROJECT, System.getProperty(BUGTRACKER_PROJECT)));409 410 setWebDriverGrid(getValueForTest(WEB_DRIVER_GRID, System.getProperty(WEB_DRIVER_GRID)));411 setRunMode(getValueForTest(RUN_MODE, System.getProperty(RUN_MODE))); 412 setNodeTags(getValueForTest(NODE_TAGS, System.getProperty(NODE_TAGS))); 413 414 setMaskPassword(getBoolValueForTest(MASK_PASSWORD, System.getProperty(MASK_PASSWORD))); 415 setLoadIni(getValueForTest(LOAD_INI, System.getProperty(LOAD_INI)));416 setWebSessionTimeout(getIntValueForTest(WEB_SESSION_TIME_OUT, System.getProperty(WEB_SESSION_TIME_OUT)));417 setImplicitWaitTimeout(getIntValueForTest(IMPLICIT_WAIT_TIME_OUT, System.getProperty(IMPLICIT_WAIT_TIME_OUT)));418 setExplicitWaitTimeout(getIntValueForTest(EXPLICIT_WAIT_TIME_OUT, System.getProperty(EXPLICIT_WAIT_TIME_OUT)));419 setReplayTimeout(getIntValueForTest(REPLAY_TIME_OUT, System.getProperty(REPLAY_TIME_OUT)));420 setPageLoadTimeout(getIntValueForTest(PAGE_LOAD_TIME_OUT, System.getProperty(PAGE_LOAD_TIME_OUT)));421 setPageLoadStrategy(getValueForTest(PAGE_LOAD_STRATEGY, System.getProperty(PAGE_LOAD_STRATEGY)));422 setDebug(getValueForTest(DEBUG, System.getProperty(DEBUG)));423 setManualTestSteps(getBoolValueForTest(MANUAL_TEST_STEPS, System.getProperty(MANUAL_TEST_STEPS)));424 setBrowser(getValueForTest(BROWSER, System.getProperty(BROWSER)));425 setHeadlessBrowser(getBoolValueForTest(HEADLESS_BROWSER, System.getProperty(HEADLESS_BROWSER)));426 setBrowserVersion(getValueForTest(BROWSER_VERSION, System.getProperty(BROWSER_VERSION)));427 setFirefoxUserProfilePath(getValueForTest(FIREFOX_USER_PROFILE_PATH, System.getProperty(FIREFOX_USER_PROFILE_PATH)));428 setOperaUserProfilePath(getValueForTest(OPERA_USER_PROFILE_PATH, System.getProperty(OPERA_USER_PROFILE_PATH)));429 setChromeUserProfilePath(getValueForTest(CHROME_USER_PROFILE_PATH, System.getProperty(CHROME_USER_PROFILE_PATH)));430 setEdgeUserProfilePath(getValueForTest(EDGE_USER_PROFILE_PATH, System.getProperty(EDGE_USER_PROFILE_PATH)));431 setChromeOptions(getValueForTest(CHROME_OPTIONS, System.getProperty(CHROME_OPTIONS)));432 setFirefoxBinary(getValueForTest(FIREFOX_BINARY_PATH, System.getProperty(FIREFOX_BINARY_PATH)));433 setChromeBinary(getValueForTest(CHROME_BINARY_PATH, System.getProperty(CHROME_BINARY_PATH)));434 setChromeDriverPath(getValueForTest(CHROME_DRIVER_PATH, System.getProperty(CHROME_DRIVER_PATH)));435 setGeckoDriverPath(getValueForTest(GECKO_DRIVER_PATH, System.getProperty(GECKO_DRIVER_PATH)));436 setEdgeDriverPath(getValueForTest(EDGE_DRIVER_PATH, System.getProperty(EDGE_DRIVER_PATH)));437 setIEDriverPath(getValueForTest(IE_DRIVER_PATH, System.getProperty(IE_DRIVER_PATH)));438 setUserAgent(getValueForTest(USER_AGENT, System.getProperty(USER_AGENT)));439 setBetaBrowser(getBoolValueForTest(BETA_BROWSER, System.getProperty(BETA_BROWSER)));440 setAssumeUntrustedCertificateIssuer(getBoolValueForTest(SET_ASSUME_UNTRUSTED_CERTIFICATE_ISSUER, System.getProperty(SET_ASSUME_UNTRUSTED_CERTIFICATE_ISSUER)));441 setAcceptUntrustedCertificates(getBoolValueForTest(SET_ACCEPT_UNTRUSTED_CERTIFICATES, System.getProperty(SET_ACCEPT_UNTRUSTED_CERTIFICATES)));442 setJavascriptEnabled(getBoolValueForTest(ENABLE_JAVASCRIPT, System.getProperty(ENABLE_JAVASCRIPT)));443 setNtlmAuthTrustedUris(getValueForTest(NTLM_AUTH_TRUSTED_URIS, System.getProperty(NTLM_AUTH_TRUSTED_URIS)));444 setBrowserDownloadDir(getValueForTest(BROWSER_DOWNLOAD_DIR, System.getProperty(BROWSER_DOWNLOAD_DIR)));445 446 setOverrideSeleniumNativeAction(getBoolValueForTest(OVERRIDE_SELENIUM_NATIVE_ACTION, System.getProperty(OVERRIDE_SELENIUM_NATIVE_ACTION)));447448 setAdvancedElementSearch(getValueForTest(ADVANCED_ELEMENT_SEARCH, System.getProperty(ADVANCED_ELEMENT_SEARCH)));449 450 setWebProxyType(getValueForTest(WEB_PROXY_TYPE, System.getProperty(WEB_PROXY_TYPE)));451 setWebProxyAddress(getValueForTest(WEB_PROXY_ADDRESS, System.getProperty(WEB_PROXY_ADDRESS)));452 setWebProxyLogin(getValueForTest(WEB_PROXY_LOGIN, System.getProperty(WEB_PROXY_LOGIN)));453 setWebProxyPassword(getValueForTest(WEB_PROXY_PASSWORD, System.getProperty(WEB_PROXY_PASSWORD)));454 setWebProxyPort(getIntValueForTest(WEB_PROXY_PORT, System.getProperty(WEB_PROXY_PORT)));455 setWebProxyExclude(getValueForTest(WEB_PROXY_EXCLUDE, System.getProperty(WEB_PROXY_EXCLUDE)));456 setWebProxyPac(getValueForTest(WEB_PROXY_PAC, System.getProperty(WEB_PROXY_PAC)));457 458 setSnapshotScrollDelay(getIntValueForTest(SNAPSHOT_SCROLL_DELAY, System.getProperty(SNAPSHOT_SCROLL_DELAY)));459 setSnapshotBottomCropping(getIntValueForTest(SNAPSHOT_BOTTOM_CROPPING, System.getProperty(SNAPSHOT_BOTTOM_CROPPING)));460 setSnapshotTopCropping(getIntValueForTest(SNAPSHOT_TOP_CROPPING, System.getProperty(SNAPSHOT_TOP_CROPPING)));461 setCaptureSnapshot(getBoolValueForTest(CAPTURE_SNAPSHOT, System.getProperty(CAPTURE_SNAPSHOT)));462 setCaptureNetwork(getBoolValueForTest(CAPTURE_NETWORK, System.getProperty(CAPTURE_NETWORK)));463 setVideoCapture(getValueForTest(VIDEO_CAPTURE, System.getProperty(VIDEO_CAPTURE)));464465 setDpTagsInclude(getValueForTest(DP_TAGS_INCLUDE, System.getProperty(DP_TAGS_INCLUDE)));466 setDpTagsExclude(getValueForTest(DP_TAGS_EXCLUDE, System.getProperty(DP_TAGS_EXCLUDE)));467 setReporterPluginClasses(getValueForTest(REPORTER_PLUGIN_CLASSES, System.getProperty(REPORTER_PLUGIN_CLASSES)));468469 setSoftAssertEnabled(getBoolValueForTest(SOFT_ASSERT_ENABLED, System.getProperty(SOFT_ASSERT_ENABLED)));470 setTestRetryCount(getIntValueForTest(TEST_RETRY_COUNT, System.getProperty(TEST_RETRY_COUNT)));471472 setWebDriverListener(getValueForTest(WEB_DRIVER_LISTENER, System.getProperty(WEB_DRIVER_LISTENER)));473474 setAppiumServerUrl(getValueForTest(APPIUM_SERVER_URL, System.getProperty(APPIUM_SERVER_URL)));475 setDeviceName(getValueForTest(DEVICE_NAME, System.getProperty(DEVICE_NAME)));476 setDeviceId(getValueForTest(DEVICE_ID, System.getProperty(DEVICE_ID)));477 setDeviceList(getValueForTest(DEVICE_LIST, null));478 setFullReset(getBoolValueForTest(FULL_RESET, System.getProperty(FULL_RESET)));479480 setApp(getValueForTest(APP, System.getProperty(APP)));481 setStartedBy(getValueForTest(STARTED_BY, System.getProperty(STARTED_BY)));482 483 setCucumberTags(getValueForTest(CUCUMBER_TAGS, System.getProperty(CUCUMBER_TAGS)));484 setCucumberTests(getValueForTest(CUCUMBER_TESTS, System.getProperty(CUCUMBER_TESTS)));485 setCucumberImplementationPackage(getValueForTest(CUCUMBER_IMPLEMENTATION_PKG, System.getProperty(CUCUMBER_IMPLEMENTATION_PKG)));486 setTestEnv(getValueForTest(TEST_ENV, System.getProperty(TEST_ENV)));487488 // By default test is assumed to be executed on default browser on android emulator489 setAutomationName(getValueForTest(AUTOMATION_NAME, System.getProperty(AUTOMATION_NAME)));490 setAppPackage(getValueForTest(APP_PACKAGE, System.getProperty(APP_PACKAGE)));491 setAppActivity(getValueForTest(APP_ACTIVITY, System.getProperty(APP_ACTIVITY)));492 setAppWaitActivity(getValueForTest(APP_WAIT_ACTIVITY, System.getProperty(APP_WAIT_ACTIVITY)));493 setNewCommandTimeout(getIntValueForTest(NEW_COMMAND_TIMEOUT, System.getProperty(NEW_COMMAND_TIMEOUT)));494495 setVersion(getValueForTest(VERSION, System.getProperty(VERSION)));496 setPlatform(getValueForTest(PLATFORM, System.getProperty(PLATFORM)));497 setCloudApiKey(getValueForTest(CLOUD_API_KEY, System.getProperty(CLOUD_API_KEY)));498 499 setCustomTestReports(getValueForTest(CUSTOM_TEST_REPORTS, System.getProperty(CUSTOM_TEST_REPORTS)));500 setCustomSummaryReports(getValueForTest(CUSTOM_SUMMARY_REPORTS, System.getProperty(CUSTOM_SUMMARY_REPORTS)));501 setArchiveToFile(getValueForTest(ARCHIVE_TO_FILE, System.getProperty(ARCHIVE_TO_FILE)));502 setArchive(getValueForTest(ARCHIVE, System.getProperty(ARCHIVE)));503 setOptimizeReports(getBoolValueForTest(OPTIMIZE_REPORTS, System.getProperty(OPTIMIZE_REPORTS)));504 setKeepAllResults(getBoolValueForTest(KEEP_ALL_RESULTS, System.getProperty(KEEP_ALL_RESULTS)));505 506 setViewPortWidth(getIntValueForTest(VIEWPORT_WIDTH, System.getProperty(VIEWPORT_WIDTH)));507 setViewPortHeight(getIntValueForTest(VIEWPORT_HEIGHT, System.getProperty(VIEWPORT_HEIGHT)));508 509 setNeoloadUserPath(getValueForTest(NEOLOAD_USER_PATH, System.getProperty(NEOLOAD_USER_PATH)));510 511 setRandomInAttachmentNames(getBoolValueForTest(RANDOM_IN_ATTACHMENT_NAME, System.getProperty(RANDOM_IN_ATTACHMENT_NAME)));512 513 //setReportPortalActive(getBoolValueForTest(REPORTPORTAL_ACTIVE, System.getProperty(REPORTPORTAL_ACTIVE)));514 515 if (testNGContext != null) {516 517 // this value will be overwritten for thread context by a call to "configureContext"518 setOutputDirectory(getValueForTest(OUTPUT_DIRECTORY, System.getProperty(OUTPUT_DIRECTORY)), testNGContext, true);519 baseOutputDirectory = getOutputDirectory();520521 // parse other parameters that are defined in testng xml or as user parameters but not defined522 // in this context. Called here so that user defined parameters can be accessed inside @Before / @After annotated methods523 setTestConfiguration();524 }525 }526 527 /**528 * If chrome or firefox binary is redefined in parameter, update list of installed browser so529 * that it matches those really used530 */531 private void updateInstalledBrowsers() {532 Map<BrowserType, List<BrowserInfo>> installedBrowsers = OSUtility.getInstalledBrowsersWithVersion(getBetaBrowser());533 534 if (getFirefoxBinPath() != null) {535 String version = OSUtility.getFirefoxVersion(getFirefoxBinPath());536 installedBrowsers.get(BrowserType.FIREFOX).add(new BrowserInfo(BrowserType.FIREFOX, OSUtility.extractFirefoxVersion(version), getFirefoxBinPath()));537 }538 539 if (getChromeBinPath() != null) {540 String version = OSUtility.getChromeVersion(getChromeBinPath());541 installedBrowsers.get(BrowserType.CHROME).add(new BrowserInfo(BrowserType.CHROME, OSUtility.extractChromeOrChromiumVersion(version), getChromeBinPath()));542 }543 }544 545 /**546 * update test data according to platform547 * @param platform548 */549 public void updateTestAndMobile(String platform) {550 551 setPlatform(platform);552 553 // determines test_type according to input configuration554 configureTestType();555556 // get mobile platform version if one is defined in device list and a deviceName is set in parameters557 updateDeviceMobileVersion();558 559 // get mobile platform version560 updatePlatformVersion();561 }562 563 /**564 * From platform name, in case of Desktop platform, do nothing and in case of mobile, extract OS version from name565 * as platformName will be 'Android 5.0' for example566 *567 * @throws ConfigurationException in mobile, if version is not present568 */569 private void updatePlatformVersion() {570 try {571 Platform currentPlatform = Platform.fromString(getPlatform());572 if (!(currentPlatform.is(Platform.WINDOWS) 573 || currentPlatform.is(Platform.MAC) 574 || currentPlatform.is(Platform.UNIX)575 || currentPlatform.is(Platform.ANY) && getRunMode() == DriverMode.GRID)) {576 throw new WebDriverException("");577 578 } 579 } catch (WebDriverException e) {580 if (getPlatform().toLowerCase().startsWith("android") || getPlatform().toLowerCase().startsWith("ios")) {581 String[] pfVersion = getPlatform().split(" ", 2);582 try {583 setPlatform(pfVersion[0]);584 setMobilePlatformVersion(pfVersion[1]);585 } catch (IndexOutOfBoundsException x) {586 setMobilePlatformVersion(null);587 logger.warn("For mobile platform, platform name should contain version. Ex: 'Android 5.0' or 'iOS 9.1'. Else, first found device is used");588 }589 590 } else {591 throw new ConfigurationException(String.format("Platform %s has not been recognized as a valid platform", getPlatform()));592 }593 }594 }595 596 /**597 * Configure test type according to platform, browser and app parameters598 */599 private void configureTestType() {600 if (getPlatform().toLowerCase().startsWith("android")) {601 if (getApp().isEmpty() && getAppActivity() == null) { // a browser name should be defined602 setTestType(TestType.APPIUM_WEB_ANDROID);603 } else {604 setTestType(TestType.APPIUM_APP_ANDROID);605 }606 } else if (getPlatform().toLowerCase().startsWith("ios")) {607 if (getApp().isEmpty() && getBrowser() != BrowserType.NONE) { // a browser name should be defined608 setTestType(TestType.APPIUM_WEB_IOS);609 } else {610 setTestType(TestType.APPIUM_APP_IOS);611 }612 } else {613 if (getBrowser() == BrowserType.NONE) {614 setTestType(TestType.NON_GUI);615 } else {616 setTestType(TestType.WEB);617 }618 }619 }620 621 /**622 * Search mobile platform version according to device name if one has been defined in testConfig file623 */624 private void updateDeviceMobileVersion() {625 Map<String, String> deviceList = getDeviceList();626 if (getDeviceName() != null && !getDeviceName().isEmpty() && !deviceList.isEmpty()) {627 setPlatform(deviceList.get(getDeviceName()));628 }629 }630 631 // TODO: this call should be moved into postInit method as SeleniumRobotVariableServerConnector calls SeleniumTestsContextManager.getThreadContext() which may not be initialized632 private SeleniumRobotVariableServerConnector connectSeleniumRobotServer() {633 634 if (testNGResult == null) {635 return null;636 }637 638 // in case we find the url of variable server and it's marked as active, use it639 if (getSeleniumRobotServerActive() != null && getSeleniumRobotServerActive() && getSeleniumRobotServerUrl() != null) {640 if (System.getProperty(SeleniumRobotLogger.MAVEN_EXECUTION) == null || System.getProperty(SeleniumRobotLogger.MAVEN_EXECUTION).equals("false")) {641 logger.info(String.format("%s key found, and set to true, trying to get variable from variable server %s [%s]", 642 SELENIUMROBOTSERVER_ACTIVE, 643 getSeleniumRobotServerUrl(),644 SELENIUMROBOTSERVER_URL));645 }646 SeleniumRobotVariableServerConnector vServer = new SeleniumRobotVariableServerConnector(getSeleniumRobotServerActive(), getSeleniumRobotServerUrl(), TestNGResultUtils.getTestName(testNGResult).replaceAll("^before-", ""), getSeleniumRobotServerToken());647 648 if (!vServer.isAlive()) {649 throw new ConfigurationException(String.format("Variable server %s could not be contacted", getSeleniumRobotServerUrl()));650 }651 652 return vServer;653 654 } else {655 if (System.getProperty(SeleniumRobotLogger.MAVEN_EXECUTION) == null || System.getProperty(SeleniumRobotLogger.MAVEN_EXECUTION).equals("false")) {656 logger.info(String.format("%s key not found or set to false, or url key %s has not been set", SELENIUMROBOTSERVER_ACTIVE, SELENIUMROBOTSERVER_URL));657 }658 return null;659 }660 661 }662 663 /**664 * returns the selenium grid connector if mode requests it665 * @return666 */667 private List<SeleniumGridConnector> connectGrid() {668 if (getRunMode() == DriverMode.GRID) {669 if (getWebDriverGrid() != null && !getWebDriverGrid().isEmpty()) {670 return SeleniumGridConnectorFactory.getInstances(getWebDriverGrid());671 } else {672 throw new ConfigurationException("Test should be executed with Selenium Grid but URL is not set");673 }674 } else {675 return null;676 }677 }678679 public void addVerificationFailures(final ITestResult result, final List<Throwable> failures) {680681 this.verificationFailuresMap.put(result, failures);682 }683684 public void addVerificationFailures(final ITestResult result, final Throwable failure) {685686 if (verificationFailuresMap.get(result) != null) {687 this.verificationFailuresMap.get(result).add(failure);688 } else {689 ArrayList<Throwable> failures = new ArrayList<>();690 failures.add(failure);691 this.addVerificationFailures(result, failures);692 }693 }694695 696 /**697 * Get all JVM properties and filters the java one so that only user defined JVM arguments are returned698 * @return699 */700 public Map<String, String> getCommandLineProperties() {701 Map<String, String> props = new HashMap<>();702 for (Entry<Object,Object> entry: System.getProperties().entrySet()) {703 String key = entry.getKey().toString();704 if (key.startsWith("java.") 705 || key.startsWith("sun.")706 || key.startsWith("user.")707 || key.startsWith("os.")708 || key.startsWith("file.")709 || key.startsWith("awt.")710 || "line.separator".equals(key)711 || "jnidispatch.path".equals(key)712 ) {713 continue;714 }715 props.put(key, System.getProperty(key));716 }717 return props;718 }719 720 /**721 * Returns list of variables defined by user from command line722 * @return723 */724 private Map<String, TestVariable> getUserDefinedVariablesFromCommandLine() {725 return extractCustomVariables(getCommandLineProperties());726 }727 728 /**729 * Returns list of variables defined by user from TestNG XML file730 * @return731 */732 private Map<String, TestVariable> getUserDefinedVariablesFromXMLFile() {733 if (testNGContext != null) {734 Map<String, String> testParameters;735 if (testNGContext.getCurrentXmlTest() == null) {736 testParameters = testNGContext.getSuite().getXmlSuite().getParameters();737 } else {738 testParameters = testNGContext.getCurrentXmlTest().getAllParameters();739 }740741 return extractCustomVariables(testParameters);742 }743 return new HashMap<>();744 }745 746 /**747 * from a list of variables, extract those who are variables created by user (not seleniumRobot technical variables)748 * If parameter is already known in contextDataMap (technical parameters defined in this class), it's not added 749 * @param parameters750 */751 private Map<String, TestVariable> extractCustomVariables(Map<String, String> parameters) {752 Map<String, TestVariable> variables = new HashMap<>();753 754 for (Entry<String, String> entry : parameters.entrySet()) {755 String attributeName = entry.getKey();756757 // contextDataMap already contains all technical parameters758 if (!contextDataMap.containsKey(entry.getKey())) {759 variables.put(attributeName, new TestVariable(attributeName, entry.getValue()));760 }761 }762 763 return variables;764 }765766 /**767 * Get (in order of importance) user value (if exist), test value (if exist), suite value (if exist) or null768 *769 * @param context770 * @param attributeName771 * @param sysPropertyValue772 * @param defaultValue773 */774 private String getValueForTest(final String attributeName, final String sysPropertyValue) {775 String value = null;776 if (testNGContext != null) {777 778 // default suite value, even if currentXmlTest is null779 value = testNGContext.getSuite().getXmlSuite().getParameter(attributeName);780 781 if (testNGContext.getCurrentXmlTest() != null) {782 783 // priority given to test parameter784 String testValue = testNGContext.getCurrentXmlTest().getParameter(attributeName);785 786 if (testValue == null) {787 788 // if test parameter does not exist, look at suite parameter789 value = testNGContext.getCurrentXmlTest().getSuite().getParameter(attributeName);790 791 } else {792 value = testValue;793 }794 }795 }796 797 return sysPropertyValue != null ? sysPropertyValue : value;798 }799 800 /**801 * Return an int value from test parameters802 * @param attributeName803 * @param sysPropertyValue804 * @return805 */806 private Integer getIntValueForTest(final String attributeName, final String sysPropertyValue) {807 String value = getValueForTest(attributeName, sysPropertyValue);808 try {809 return value == null ? null: Integer.parseInt(value);810 } catch (NumberFormatException e) {811 throw new ConfigurationException(String.format("Option [%s] value should be integer or null, found [%s]", attributeName, value));812 }813 }814 815 /**816 * Return a boolean value from test parameters817 * @param attributeName818 * @param sysPropertyValue819 * @return820 */821 private Boolean getBoolValueForTest(final String attributeName, final String sysPropertyValue) {822 String value = getValueForTest(attributeName, sysPropertyValue);823 return value == null ? null: Boolean.parseBoolean(value);824 }825 826 /**827 * Connect all servers (grid, seleniumRobot server) to this context828 */829 private void createVariableServerConnectors() {830831 // create seleniumRobot server instance832 variableServer = connectSeleniumRobotServer();833 }834 835 private void createContextConnectors() {836 837 // create selenium grid connectors. They will be created if it's null838 // in this phase, we chek that grid is alive839 getSeleniumGridConnectors();840 841 // create Test Manager connector842 testManagerInstance = initTestManager();843 844 bugtrackerInstance = initBugtracker();845 846 }847 848 /**849 * Created the directory specific to this test. It must be unique even if the same test is executed twice850 * So the created directory is 'test-ouput/<test_name>-<index>'851 */852 public void createTestSpecificOutputDirectory(ITestResult testNGResult) {853 String testOutputFolderName = hashTest(testNGResult);854 855 // use base directory as it's fixed along the life of the test856 Path outputDir = Paths.get(baseOutputDirectory, testOutputFolderName);857 setRelativeOutputDir(testOutputFolderName);858 setOutputDirectory(outputDir.toString(), testNGContext, false);859860 }861 862 /**863 * Returns the name of the folder where all files (result, snapshots) will be stored inside 'test-output' folder864 * By default, folder name is the name of the test. But if the same test is executed twice, with for example DataProvider or through different suites / tests, 865 * then increment a suffix so that there is no collision between test results866 * @param testNGResult867 * @return868 */869 private String hashTest(ITestResult testNGResult) {870 871 synchronized (lock) { // issue #352: be sure we create the unique folder name once at a time872 String uniqueIdentifier = TestNGResultUtils.getHashForTest(testNGResult);873 String testNameModified = StringUtility.replaceOddCharsFromFileName(TestNGResultUtils.getTestName(testNGResult));874 875 // issue #361: handle names that end with '..'876 if (testNameModified.endsWith("..")) {877 testNameModified += "-";878 }879 880 if (!outputFolderNames.containsKey(uniqueIdentifier)) {881 if (!outputFolderNames.values().contains(testNameModified)) {882 outputFolderNames.put(uniqueIdentifier, testNameModified);883 } else {884 int i = 0;885 while (i++ < 1000) {886 if (!outputFolderNames.values().contains(testNameModified + "-" + i)) {887 outputFolderNames.put(uniqueIdentifier, testNameModified + "-" + i);888 break;889 }890 }891 }892 }893 return outputFolderNames.get(uniqueIdentifier);894 }895 }896 897 /**898 * post configuration of the context899 * This should be done only inside the test method as we need the 'Test' method result and not an 'Before' or 'After' method result900 */901 public void configureContext(ITestResult testNGResult) {902 903 // to do before creating connectors because seleniumRobot server needs it904 this.testNGResult = testNGResult; 905 906 // context may be missing from testNgResult, so add it to avoid problems when getting hash for test907 if (testNGResult.getTestContext() == null) {908 ((TestResult)testNGResult).setContext(testNGContext);909 }910911 updateTestAndMobile(getPlatform());912 913 // update browser version: replace installed one with those given in parameters914 updateInstalledBrowsers();915 916 // update ouput directory917 createTestSpecificOutputDirectory(testNGResult);918919 createVariableServerConnectors();920 921 // read and set test configuration from env.ini file and from seleniumRobot server922 setTestConfiguration();923 updateProxyConfig();924 925 // create other connectors that may use variables926 createContextConnectors();927 }928 929 /**930 * Extract proxy settings from environment configuration (env.ini) and write them to context if they are not already present in XML file or on command line931 */932 public void updateProxyConfig() {933 Map<String, TestVariable> envConfig = getConfiguration();934 for (Entry<String, TestVariable> entry: envConfig.entrySet()) {935 String key = entry.getKey();936 switch (key) {937 case WEB_PROXY_TYPE:938 setWebProxyType(getAttribute(WEB_PROXY_TYPE_FROM_USER) == null ? envConfig.get(key).getValue(): getWebProxyType().name());939 break;940 case WEB_PROXY_ADDRESS:941 setWebProxyAddress(getWebProxyAddress() == null ? envConfig.get(key).getValue(): getWebProxyAddress());942 break;943 case WEB_PROXY_PORT:944 setWebProxyPort(getWebProxyPort() == null ? Integer.valueOf(envConfig.get(key).getValue()): getWebProxyPort());945 break;946 case WEB_PROXY_LOGIN:947 setWebProxyLogin(getWebProxyLogin() == null ? envConfig.get(key).getValue(): getWebProxyLogin());948 break;949 case WEB_PROXY_PASSWORD:950 setWebProxyPassword(getWebProxyPassword() == null ? envConfig.get(key).getValue(): getWebProxyPassword());951 break;952 case WEB_PROXY_PAC:953 setWebProxyPac(getWebProxyPac() == null ? envConfig.get(key).getValue(): getWebProxyPac());954 break;955 case WEB_PROXY_EXCLUDE:956 setWebProxyExclude(getWebProxyExclude() == null ? envConfig.get(key).getValue(): getWebProxyExclude());957 break;958 default:959 continue;960 }961 }962 963 // set default value for proxy type if none as been set before964 if (getWebProxyType() == null) {965 setWebProxyType(DEFAULT_WEB_PROXY_TYPE.toString());966 }967 968 // exclude browserMobProxy if proxy type is set to PAC969 if (getCaptureNetwork() && getWebProxyType() != ProxyType.DIRECT && getWebProxyType() != ProxyType.MANUAL) {970 throw new ConfigurationException("Browsermob proxy (captureNetwork option) is only compatible with DIRECT and MANUAL");971 }972 }973 974 /**975 * Read configuration from environment specific data and undefined parameters present un testng xml file976 * these configurations will be overiden by server if it's present977 */978 public void setTestConfiguration() {979 980 // get variables from XML981 getConfiguration().putAll(getUserDefinedVariablesFromXMLFile());982 983 // get variables from env.ini984 getConfiguration().putAll(new ConfigReader(getTestEnv(), getLoadIni()).readConfig());985 986 // get variables from command line987 getConfiguration().putAll(getUserDefinedVariablesFromCommandLine());988 989 if (variableServer != null) {990 991 // get variable from server if they have never been get992 if (variableAlreadyRequestedFromServer == null) {993 variableAlreadyRequestedFromServer = variableServer.getVariables(getSeleniumRobotServerVariableOlderThan());994 }995 getConfiguration().putAll(variableAlreadyRequestedFromServer);996997 // give priority to command line parameters over those from server, so overwrite variable server if overlapping998 getConfiguration().putAll(getUserDefinedVariablesFromCommandLine());999 }1000 }1001 1002 public TestManager initTestManager() {1003 if (getTmsType() != null && getTmsUrl() != null) {1004 1005 // build configuration1006 JSONObject jsonConfig = new JSONObject();1007 jsonConfig.put(TMS_TYPE, getTmsType());1008 jsonConfig.put(TMS_URL, getTmsUrl());1009 jsonConfig.put(TMS_USER, getTmsUser());1010 jsonConfig.put(TMS_PASSWORD, getTmsPassword());1011 jsonConfig.put(TMS_PROJECT, getTmsProject());1012 1013 // add non standard configurations1014 for (String key: getConfiguration().keySet()) {1015 if (key.startsWith("tms")) {1016 jsonConfig.put(key, getConfiguration().get(key).getValue());1017 }1018 }1019 1020 TestManager tms = TestManager.getInstance(jsonConfig);1021 1022 tms.init(jsonConfig);1023 return tms;1024 }1025 return null;1026 }1027 1028 public BugTracker initBugtracker() {1029 if (getBugtrackerType() != null && getBugtrackerUrl() != null) {1030 1031 // any options specific to this bugtracker may be given in the form 'bugtracker.xxx'1032 Map<String, String> bugtrackerOptions = new HashMap<>();1033 for (TestVariable variable: getConfiguration().values()) {1034 if (variable.getName().startsWith("bugtracker.")) {1035 bugtrackerOptions.put(variable.getName().replace("bugtracker.", ""), variable.getValue());1036 }1037 }1038 1039 return BugTracker.getInstance(getBugtrackerType(), getBugtrackerUrl(), getBugtrackerProject(), getBugtrackerUser(), getBugtrackerPassword(), bugtrackerOptions);1040 }1041 return null;1042 }1043 1044 /**1045 * initialize the image field detector1046 * @return1047 */1048 public FieldDetectorConnector initFieldDetectorConnector() {1049 1050 if (getImageFieldDetectorServerUrl() != null) {1051 1052 return FieldDetectorConnector.getInstance(getImageFieldDetectorServerUrl());1053 } else {1054 return null;1055 }1056 1057 }1058 1059 // ------------------------- accessors ------------------------------------------------------1060 1061 // getters from contextManager1062 public String getApplicationName() {1063 return SeleniumTestsContextManager.getApplicationName();1064 }10651066 public String getApplicationNameWithVersion() {1067 return SeleniumTestsContextManager.getApplicationNameWithVersion();1068 }10691070 public String getApplicationVersion() {1071 return SeleniumTestsContextManager.getApplicationVersion();1072 }10731074 public String getCoreVersion() {1075 return SeleniumTestsContextManager.getCoreVersion();1076 }1077 1078 /**1079 * Returns application root path1080 * @return1081 */1082 public String getRootPath() {1083 return SeleniumTestsContextManager.getRootPath();1084 }10851086 /**1087 * Returns location of feature files1088 * /<root>/data/<app>/features/1089 * @return1090 */1091 public String getFeaturePath() {1092 return SeleniumTestsContextManager.getFeaturePath();1093 }10941095 /**1096 * Returns location of config files: /<root>/data/<app>/config/1097 * @return1098 */1099 public String getConfigPath() {1100 return SeleniumTestsContextManager.getConfigPath();1101 }1102 1103 /**1104 * Returns location of data folder: /<root>/data/1105 * @return1106 */1107 public String getDataPath() {1108 return SeleniumTestsContextManager.getDataPath();1109 }1110 1111 /**1112 * Returns location of application specific data: /<root>/data/<app>/1113 * @return1114 */1115 public String getApplicationDataPath() {1116 return SeleniumTestsContextManager.getApplicationDataPath();1117 }1118 1119 // getters for this object1120 public Boolean getFullReset() {1121 return (Boolean) getAttribute(FULL_RESET);1122 }112311241125 public Object getAttribute(final String name) {1126 return getAttribute(name, false);1127 }1128 1129 /**1130 * Returns attribute value searched in context1131 * If no value is found, search in variables1132 * @param name1133 * @param searchInVariables if true, will search in variables if attribute cannot be found in configuration. Beware that configuration only contains strings1134 * so casting may fail1135 * @return1136 */1137 public Object getAttribute(final String name, boolean searchInVariables) {1138 Object obj = contextDataMap.get(name);1139 1140 if (searchInVariables && obj == null && getConfiguration().get(name) != null) {1141 obj = getConfiguration().get(name).getValue();1142 }1143 1144 return obj == null ? null : obj;1145 }11461147 public String getBrowserDownloadDir() {1148 if (getAttribute(BROWSER_DOWNLOAD_DIR) != null) {1149 return (String) getAttribute(BROWSER_DOWNLOAD_DIR);1150 } else {1151 return this.getOutputDirectory() + "\\downloads\\";1152 }1153 }1154 1155 public Integer getSnapshotScrollDelay() {1156 return (Integer) getAttribute(SNAPSHOT_SCROLL_DELAY);1157 }1158 1159 public Integer getSnapshotBottomCropping() {1160 return (Integer) getAttribute(SNAPSHOT_BOTTOM_CROPPING);1161 }1162 1163 public Integer getSnapshotTopCropping() {1164 return (Integer) getAttribute(SNAPSHOT_TOP_CROPPING);1165 }11661167 public boolean getCaptureSnapshot() {1168 if (getAttribute(CAPTURE_SNAPSHOT) == null) {11691170 // safari grid default value set to false1171 if (this.getRunMode() == DriverMode.GRID1172 && this.getBrowser() == BrowserType.SAFARI) {1173 this.setAttribute(CAPTURE_SNAPSHOT, false);1174 } else {1175 this.setAttribute(CAPTURE_SNAPSHOT, DEFAULT_CAPTURE_SNAPSHOT);1176 }1177 }11781179 return (Boolean) getAttribute(CAPTURE_SNAPSHOT);1180 }1181 1182 public String getStartedBy() { 1183 return (String) getAttribute(STARTED_BY);1184 }1185 1186 public boolean getCaptureNetwork() { 1187 return (Boolean) getAttribute(CAPTURE_NETWORK);1188 }1189 1190 public VideoCaptureMode getVideoCapture() { 1191 return (VideoCaptureMode) getAttribute(VIDEO_CAPTURE);1192 }119311941195 public String getChromeBinPath() {1196 return (String) getAttribute(CHROME_BINARY_PATH);1197 }11981199 public String getChromeDriverPath() {1200 return (String) getAttribute(CHROME_DRIVER_PATH);1201 }1202 1203 public String getGeckoDriverPath() {1204 return (String) getAttribute(GECKO_DRIVER_PATH);1205 }1206 1207 public String getEdgeDriverPath() {1208 return (String) getAttribute(EDGE_DRIVER_PATH);1209 }1210 1211 public Boolean getEdgeIeMode() {1212 return (Boolean) getAttribute(EDGE_IE_MODE);1213 }1214 1215 public Boolean getBetaBrowser() {1216 return (Boolean) getAttribute(BETA_BROWSER);1217 }12181219 public String getDPTagsExclude() {1220 return (String) getAttribute(DP_TAGS_EXCLUDE);1221 }12221223 public String getDPTagsInclude() {1224 return (String) getAttribute(DP_TAGS_INCLUDE);1225 }1226 1227 public String getTmsType() {1228 return (String) getAttribute(TMS_TYPE);1229 }1230 1231 public String getTmsUrl() {1232 return (String) getAttribute(TMS_URL);1233 }1234 1235 public String getTmsUser() {1236 return (String) getAttribute(TMS_USER);1237 }1238 1239 public String getTmsPassword() {1240 return (String) getAttribute(TMS_PASSWORD);1241 }1242 1243 public String getTmsProject() {1244 return (String) getAttribute(TMS_PROJECT);1245 }1246 1247 public String getBugtrackerType() {1248 return (String) getAttribute(BUGTRACKER_TYPE);1249 }1250 1251 public String getBugtrackerUrl() {1252 return (String) getAttribute(BUGTRACKER_URL, true);1253 }1254 1255 public String getBugtrackerUser() {1256 return (String) getAttribute(BUGTRACKER_USER, true);1257 }1258 1259 public String getBugtrackerPassword() {1260 return (String) getAttribute(BUGTRACKER_PASSWORD, true);1261 }1262 1263 public String getBugtrackerProject() {1264 return (String) getAttribute(BUGTRACKER_PROJECT, true);1265 }1266 1267 @SuppressWarnings("unchecked")1268 public List<Class<?>> getReporterPluginClasses() {1269 List<Class<?>> userDefinedClasses = new ArrayList<>();12701271 // add core reporter classes1272 userDefinedClasses.add(BugTrackerReporter.class);1273 userDefinedClasses.add(SeleniumTestsReporter2.class);1274 userDefinedClasses.add(TestManagerReporter.class);1275 userDefinedClasses.add(SeleniumRobotServerTestRecorder.class);1276 userDefinedClasses.add(CustomReporter.class);1277 1278 userDefinedClasses.addAll((List<Class<?>>) getAttribute(REPORTER_PLUGIN_CLASSES));1279 1280 return userDefinedClasses;1281 }12821283 public String getNeoloadUserPath() {1284 return (String) getAttribute(NEOLOAD_USER_PATH);1285 }12861287 public int getExplicitWaitTimeout() {1288 Integer timeout;1289 try {1290 timeout = (Integer) getAttribute(EXPLICIT_WAIT_TIME_OUT);1291 } catch (Exception e) {1292 timeout = DEFAULT_EXPLICIT_WAIT_TIME_OUT;1293 }12941295 if (timeout < getImplicitWaitTimeout()) {1296 return getImplicitWaitTimeout();1297 } else {1298 return timeout;1299 }1300 }13011302 public String getFirefoxBinPath() {1303 return (String) getAttribute(FIREFOX_BINARY_PATH);1304 }13051306 public String getFirefoxUserProfilePath() {1307 return (String) getAttribute(FIREFOX_USER_PROFILE_PATH);1308 }13091310 public String getIEDriverPath() {1311 return (String) getAttribute(IE_DRIVER_PATH);1312 }1313 1314 public static boolean getReportPortalActive() {1315 if (System.getProperty(REPORTPORTAL_ACTIVE) != null && "true".equals(System.getProperty(REPORTPORTAL_ACTIVE))) {1316 1317 // check also report portal options (can be obtained here: https://github.com/reportportal/client-java)1318 if (System.getProperty("rp.endpoint") == null) {1319 logger.error("ReportPortal endpoint not configured (-Drp.endpoint=<rp url>). It is disabled");1320 return false;1321 }1322 if (System.getProperty("rp.api.key") == null) {1323 logger.error("ReportPortal API key not configured (-Drp.api.key=<key>). It is disabled");1324 return false;1325 }1326 if (System.getProperty("rp.launch") == null) {1327 logger.error("ReportPortal endpoint not configured (-Drp.launch=<launch name>). It is disabled");1328 return false;1329 }1330 if (System.getProperty("rp.project") == null) {1331 logger.error("ReportPortal endpoint not configured (-Drp.project=<project name>). It is disabled");1332 return false;1333 }1334 1335 return true;1336 }1337 return false;1338 }1339 1340 public String getImageFieldDetectorServerUrl() {1341 return (String) getAttribute(IMAGE_FIELD_DETECTOR_SERVER_URL);1342 }1343 1344 public String getSeleniumRobotServerUrl() {1345 return (String) getAttribute(SELENIUMROBOTSERVER_URL);1346 }1347 1348 public Boolean getSeleniumRobotServerActive() {1349 return (Boolean) getAttribute(SELENIUMROBOTSERVER_ACTIVE);1350 }1351 1352 public String getSeleniumRobotServerToken() {1353 return (String) getAttribute(SELENIUMROBOTSERVER_TOKEN);1354 }1355 1356 public boolean getSeleniumRobotServerCompareSnapshot() {1357 return (Boolean) getAttribute(SELENIUMROBOTSERVER_COMPARE_SNAPSHOT);1358 }1359 1360 public SnapshotComparisonBehaviour getSeleniumRobotServerCompareSnapshotBehaviour() {1361 return (SnapshotComparisonBehaviour) getAttribute(SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_BEHAVIOUR);1362 }1363 1364 public Integer getSeleniumRobotServerVariableOlderThan() {1365 return (Integer) getAttribute(SELENIUMROBOTSERVER_VARIABLES_OLDER_THAN);1366 }1367 1368 public Integer getSeleniumRobotServerCompareSnapshotTtl() {1369 return (Integer) getAttribute(SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_TTL);1370 }1371 1372 public boolean getSeleniumRobotServerRecordResults() {1373 return (Boolean) getAttribute(SELENIUMROBOTSERVER_RECORD_RESULTS);1374 }1375 1376 public boolean getOverrideSeleniumNativeAction() {1377 return (Boolean) getAttribute(OVERRIDE_SELENIUM_NATIVE_ACTION);1378 }13791380 public int getImplicitWaitTimeout() {1381 try {1382 return (Integer) getAttribute(IMPLICIT_WAIT_TIME_OUT);1383 } catch (Exception e) {1384 return DEFAULT_IMPLICIT_WAIT_TIME_OUT;1385 }1386 }1387 1388 public int getReplayTimeout() {1389 try {1390 return (Integer) getAttribute(REPLAY_TIME_OUT);1391 } catch (Exception e) {1392 return DEFAULT_REPLAY_TIME_OUT;1393 }1394 }1395 1396 public PageLoadStrategy getPageLoadStrategy() {1397 return (PageLoadStrategy) getAttribute(PAGE_LOAD_STRATEGY);1398 }13991400 public String getNtlmAuthTrustedUris() {1401 return (String) getAttribute(NTLM_AUTH_TRUSTED_URIS);1402 }1403 1404 public Boolean getAssumeUntrustedCertificateIssuer() {1405 return (Boolean) getAttribute(SET_ASSUME_UNTRUSTED_CERTIFICATE_ISSUER);1406 }1407 1408 public Boolean getJavascriptEnabled() {1409 return (Boolean) getAttribute(ENABLE_JAVASCRIPT);1410 }14111412 public Boolean getAcceptUntrustedCertificates() {1413 return (Boolean) getAttribute(SET_ACCEPT_UNTRUSTED_CERTIFICATES);1414 }141514161417 public String getOperaUserProfilePath() {1418 return (String) getAttribute(OPERA_USER_PROFILE_PATH);1419 }1420 1421 public String getChromeUserProfilePath() {1422 return (String) getAttribute(CHROME_USER_PROFILE_PATH);1423 }1424 1425 public String getEdgeUserProfilePath() {1426 return (String) getAttribute(EDGE_USER_PROFILE_PATH);1427 }1428 1429 public String getChromeOptions() {1430 return (String) getAttribute(CHROME_OPTIONS);1431 }14321433 public String getOutputDirectory() {1434 return (String) getAttribute(OUTPUT_DIRECTORY);1435 }1436 1437 public String getScreenshotOutputDirectory() {1438 return Paths.get((String)getAttribute(OUTPUT_DIRECTORY), ScreenshotUtil.SCREENSHOT_DIR).toString();1439 }1440 1441 public String getDefaultOutputDirectory() {1442 return (String) getAttribute(DEFAULT_OUTPUT_DIRECTORY);1443 }1444 1445 public String getInitialUrl() {1446 return (String) getAttribute(INITIAL_URL);1447 }1448 1449 public Boolean getMaskedPassword() {1450 return (Boolean) getAttribute(MASK_PASSWORD);1451 }1452 1453 public Boolean getRandomInAttachments() {1454 return (Boolean) getAttribute(RANDOM_IN_ATTACHMENT_NAME);1455 }1456 1457 public ITestResult getTestNGResult() {1458 return testNGResult;1459 }1460 1461 public String getLoadIni() {1462 return (String) getAttribute(LOAD_INI);1463 }14641465 public int getPageLoadTimeout() {1466 try {1467 return (Integer) getAttribute(PAGE_LOAD_TIME_OUT);1468 } catch (Exception e) {1469 return 90;1470 }1471 }14721473 /**1474 * Get TestNG suite parameter from testng.xml. Return System value for CI job.1475 *1476 * @param key name of the parameter1477 *1478 * @return value of the parameter1479 */1480 public String getSuiteParameter(final String key) {1481 if (System.getProperty(key) != null) {1482 return System.getProperty(key);1483 } else {1484 return getTestNGContext().getSuite().getParameter(key);1485 }1486 }14871488 @SuppressWarnings("unchecked")1489 public List<ReportInfo> getCustomTestReports() {1490 return (List<ReportInfo>) getAttribute(CUSTOM_TEST_REPORTS);1491 }1492 1493 @SuppressWarnings("unchecked")1494 public List<ReportInfo> getCustomSummaryReports() {1495 return (List<ReportInfo>) getAttribute(CUSTOM_SUMMARY_REPORTS);1496 }1497 1498 public boolean getOptimizeReports() {1499 return (Boolean) getAttribute(OPTIMIZE_REPORTS);1500 }1501 1502 public boolean getKeepAllResults() {1503 return (Boolean) getAttribute(KEEP_ALL_RESULTS);1504 }1505 1506 public String getArchiveToFile() {1507 return (String) getAttribute(ARCHIVE_TO_FILE);1508 }1509 1510 public List<ArchiveMode> getArchive() {1511 return (List<ArchiveMode>) getAttribute(ARCHIVE);1512 }1513 1514 public ElementInfo.Mode getAdvancedElementSearch() {1515 return (ElementInfo.Mode) getAttribute(ADVANCED_ELEMENT_SEARCH);1516 }15171518 public TestType getTestType() {1519 return (TestType) getAttribute(TEST_TYPE);1520 }15211522 public boolean isDriverCreationBlocked() {1523 return driverCreationBlocked;1524 }15251526 public String getCucumberTags() {1527 return (String) getAttribute(CUCUMBER_TAGS);1528 }1529 1530 public List<String> getCucumberTests() {1531 List<String> tests = new ArrayList<>();1532 if (((String)getAttribute(CUCUMBER_TESTS)).isEmpty()) {1533 return tests;1534 }1535 for (String test: ((String)getAttribute(CUCUMBER_TESTS)).replace("\"", "").replace(" ", " ").split(",")) {1536 tests.add(test.trim());1537 }1538 return tests;1539 }1540 1541 public String getCucmberPkg() {1542 return (String) getAttribute(CUCUMBER_IMPLEMENTATION_PKG);1543 }1544 1545 public String getTestEnv() {1546 return (String) getAttribute(TEST_ENV);1547 }1548 1549 public String getTestMethodSignature() {1550 return (String) getAttribute(TEST_METHOD_SIGNATURE);1551 }15521553 public ITestContext getTestNGContext() {1554 return testNGContext;1555 }15561557 public Object getTestEntity() {1558 return getAttribute(TEST_ENTITY);1559 }15601561 @SuppressWarnings("unchecked")1562 public List<String> getWebDriverListener() {1563 return (List<String>) getAttribute(WEB_DRIVER_LISTENER);1564 }15651566 public String getUserAgent() {1567 return (String) getAttribute(USER_AGENT);1568 }15691570 public List<Throwable> getVerificationFailures(final ITestResult result) {1571 List<Throwable> verificationFailures = verificationFailuresMap.get(result);1572 return verificationFailures == null ? new ArrayList<>() : verificationFailures;1573 }15741575 public String getWebBrowserVersion() {1576 return (String) getAttribute(BROWSER_VERSION);1577 }15781579 public List<String> getWebDriverGrid() {1580 return (List<String>) getAttribute(WEB_DRIVER_GRID);1581 }15821583 public String getWebProxyAddress() {1584 return (String) getAttribute(WEB_PROXY_ADDRESS);1585 }15861587 public ProxyType getWebProxyType() {1588 return (ProxyType) getAttribute(WEB_PROXY_TYPE);1589 }15901591 public Integer getWebProxyPort() {1592 return (Integer) getAttribute(WEB_PROXY_PORT);1593 }15941595 public String getWebProxyLogin() {1596 return (String) getAttribute(WEB_PROXY_LOGIN);1597 }15981599 public String getWebProxyPassword() {1600 return (String) getAttribute(WEB_PROXY_PASSWORD);1601 }16021603 public String getWebProxyExclude() {1604 return (String) getAttribute(WEB_PROXY_EXCLUDE);1605 }16061607 public String getWebProxyPac() {1608 return (String) getAttribute(WEB_PROXY_PAC);1609 }16101611 public BrowserType getBrowser() {1612 return (BrowserType) getAttribute(BROWSER);1613 }16141615 public DriverMode getRunMode() {1616 return (DriverMode) getAttribute(RUN_MODE);1617 }1618 1619 public List<String> getNodeTags() {1620 List<String> extTools = (List<String>) getAttribute(NODE_TAGS);1621 if (extTools == null) {1622 return new ArrayList<>();1623 } else {1624 return extTools;1625 }1626 }16271628 public List<DebugMode> getDebug() {1629 return (List<DebugMode>) getAttribute(DEBUG);1630 }1631 1632 public boolean isHeadlessBrowser() {1633 return (Boolean) getAttribute(HEADLESS_BROWSER);1634 }1635 1636 public boolean isManualTestSteps() {1637 return (Boolean) getAttribute(MANUAL_TEST_STEPS);1638 }16391640 public boolean isFindErrorCause() {1641 return (Boolean) getAttribute(FIND_ERROR_CAUSE);1642 }1643 1644 public Map<String, String> getDeviceList() {1645 HashMap<String, String> deviceList = new HashMap<>();1646 if (getAttribute(DEVICE_LIST) == null || DEFAULT_DEVICE_LIST.equals(getAttribute(DEVICE_LIST))) {1647 return deviceList;1648 }1649 1650 JSONObject devList = new JSONObject((String)getAttribute(DEVICE_LIST));1651 for (String key: (Set<String>)devList.keySet()) {1652 deviceList.put(key, devList.getString(key));1653 }1654 return deviceList;1655 }1656 1657 public Integer getTestRetryCount() {1658 return (Integer) getAttribute(TEST_RETRY_COUNT);1659 }16601661 public int getWebSessionTimeout() {1662 return (Integer) getAttribute(WEB_SESSION_TIME_OUT);1663 }16641665 public String getMobilePlatformVersion() {1666 return (String) getAttribute(MOBILE_PLATFORM_VERSION);1667 }16681669 public String getDeviceName() {1670 return (String) getAttribute(DEVICE_NAME);1671 }1672 1673 public String getDeviceId() {1674 return (String) getAttribute(DEVICE_ID);1675 }16761677 public String getApp() {1678 return (String) getAttribute(APP);1679 }16801681 public String getAppPackage() {1682 return (String) getAttribute(APP_PACKAGE);1683 }1684 1685 public String getAutomationName() {1686 return (String) getAttribute(AUTOMATION_NAME);1687 }1688 1689 public String getAppiumServerUrl() {1690 return (String) getAttribute(APPIUM_SERVER_URL);1691 }16921693 public String getAppActivity() {1694 return (String) getAttribute(APP_ACTIVITY);1695 }1696 1697 public String getAppWaitActivity() {1698 return (String) getAttribute(APP_WAIT_ACTIVITY);1699 }17001701 public int getNewCommandTimeout() {1702 return (Integer) getAttribute(NEW_COMMAND_TIMEOUT);1703 }17041705 public String getVersion() {1706 return (String) getAttribute(VERSION);1707 }17081709 public String getPlatform() {1710 return (String) getAttribute(PLATFORM);1711 }1712 1713 public String getCloudApiKey() {1714 return (String) getAttribute(CLOUD_API_KEY);1715 }17161717 public String getRelativeOutputDir() {1718 return (String) getAttribute(RELATIVE_OUTPUT_DIR);1719 }1720 1721 public Integer getViewPortWidth() {1722 return (Integer) getAttribute(VIEWPORT_WIDTH);1723 }1724 1725 public Integer getViewPortHeight() {1726 return (Integer) getAttribute(VIEWPORT_HEIGHT);1727 }1728 1729 @SuppressWarnings("unchecked")1730 public Map<String, TestVariable> getConfiguration() {1731 1732 Map<String, TestVariable> config = (HashMap<String, TestVariable>) getAttribute(TEST_VARIABLES);1733 if (config == null) {1734 return new HashMap<>();1735 } else {1736 return config;1737 }1738 }1739 1740 public SeleniumRobotVariableServerConnector getVariableServer() {1741 return variableServer;1742 }1743 1744 public List<SeleniumGridConnector> getSeleniumGridConnectors() {1745 if (seleniumGridConnectors == null) {1746 seleniumGridConnectors = connectGrid();1747 }1748 return seleniumGridConnectors;1749 }1750 1751 /**1752 * from the list of all grid connectors, returns the first one where a session has been created1753 * It means that the test runs on it because sessionId is get once driver is created1754 * @return1755 */1756 public SeleniumGridConnector getSeleniumGridConnector() {1757 if (seleniumGridConnector == null && seleniumGridConnectors != null) {1758 for (SeleniumGridConnector gridConnector: seleniumGridConnectors) {1759 if (gridConnector.getSessionId() != null) {1760 seleniumGridConnector = gridConnector;1761 break;1762 }1763 }1764 }1765 return seleniumGridConnector;1766 }1767 1768 public TestManager getTestManagerInstance() {1769 return testManagerInstance;1770 }1771 1772 public BugTracker getBugTrackerInstance() {1773 return bugtrackerInstance;1774 }1775 1776 public FieldDetectorConnector getFieldDetectorInstance() {1777 if (fieldDetectorInstance == null) {1778 fieldDetectorInstance = initFieldDetectorConnector();1779 }1780 return fieldDetectorInstance;1781 }1782 17831784 public Map<String, Object> getContextDataMap() {1785 return contextDataMap;1786 }17871788 //Methods for ID_Mapping1789 //get1790 public Map<String, HashMap<String, String>> getIdMapping() {1791 return idMapping;1792 }17931794 /**1795 * Returns the TestStepManager which will steps1796 * @return1797 */1798 public TestStepManager getTestStepManager() {1799 return testStepManager;1800 }18011802 //set1803 public void setIdMapping(Map<String, HashMap<String,String>> conf){1804 idMapping = conf;1805 } 18061807 public boolean isSoftAssertEnabled() {1808 try {1809 return (Boolean) getAttribute(SOFT_ASSERT_ENABLED);1810 } catch (Exception e) {1811 return false; // Default1812 }1813 }18141815 public void setAttribute(final String name, final Object value) {1816 contextDataMap.put(name, value);1817 }18181819 /**1820 * 1821 * @param timeout timeout of driver session in seconds1822 */1823 public void setWebSessionTimeout(Integer timeoutInSecs) {1824 if (timeoutInSecs != null) {1825 setAttribute(WEB_SESSION_TIME_OUT, timeoutInSecs * 1000);1826 } else {1827 setAttribute(WEB_SESSION_TIME_OUT, DEFAULT_WEB_SESSION_TIMEOUT);1828 }1829 }18301831 public void setImplicitWaitTimeout(Integer timeoutInSecs) {1832 if (timeoutInSecs != null) {1833 setAttribute(IMPLICIT_WAIT_TIME_OUT, timeoutInSecs);1834 } else {1835 setAttribute(IMPLICIT_WAIT_TIME_OUT, DEFAULT_IMPLICIT_WAIT_TIME_OUT);1836 }1837 }1838 1839 public void setExplicitWaitTimeout(Integer timeoutInSecs) {1840 if (timeoutInSecs != null) {1841 setAttribute(EXPLICIT_WAIT_TIME_OUT, timeoutInSecs);1842 } else {1843 setAttribute(EXPLICIT_WAIT_TIME_OUT, DEFAULT_EXPLICIT_WAIT_TIME_OUT);1844 }1845 }18461847 public void setPageLoadTimeout(Integer timeoutInSecs) {1848 if (timeoutInSecs != null) {1849 setAttribute(PAGE_LOAD_TIME_OUT, timeoutInSecs);1850 } else {1851 setAttribute(PAGE_LOAD_TIME_OUT, DEFAULT_PAGE_LOAD_TIME_OUT);1852 }1853 }1854 1855 public void setPageLoadStrategy(String strategy) {1856 if (strategy != null) {1857 PageLoadStrategy pls = PageLoadStrategy.fromString(strategy);1858 if (pls == null) {1859 throw new ConfigurationException("PageLoadStrategy values are 'eager', 'normal' (default one) and 'none'");1860 }1861 setAttribute(PAGE_LOAD_STRATEGY, pls);1862 } else {1863 setAttribute(PAGE_LOAD_STRATEGY, DEFAULT_PAGE_LOAD_STRATEGY);1864 }1865 }1866 1867 public void setCustomTestReports(String customReportsStr) {1868 if (customReportsStr != null) {1869 List<ReportInfo> reports = new ArrayList<>();1870 1871 // check if report is available in resources1872 for (String customReport: customReportsStr.split(",")) {1873 reports.add(new ReportInfo(customReport));1874 }1875 setAttribute(CUSTOM_TEST_REPORTS, reports);1876 } else {1877 setAttribute(CUSTOM_TEST_REPORTS, DEFAULT_CUSTOM_TEST_REPORTS);1878 }1879 }1880 1881 public void setCustomSummaryReports(String customReportsStr) {1882 if (customReportsStr != null) {1883 List<ReportInfo> reports = new ArrayList<>();1884 1885 // check if report is available in resources1886 for (String customReport: customReportsStr.split(",")) {1887 reports.add(new ReportInfo(customReport));1888 }1889 setAttribute(CUSTOM_SUMMARY_REPORTS, reports);1890 } else {1891 setAttribute(CUSTOM_SUMMARY_REPORTS, DEFAULT_CUSTOM_SUMMARY_REPORTS);1892 }1893 }1894 1895 public void setReplayTimeout(Integer timeout) {1896 if (timeout != null) {1897 setAttribute(REPLAY_TIME_OUT, timeout);1898 } else {1899 setAttribute(REPLAY_TIME_OUT, DEFAULT_REPLAY_TIME_OUT);1900 }1901 }1902 19031904 public void setStartedBy(String startedBy) {1905 if (startedBy != null) {1906 setAttribute(STARTED_BY, startedBy);1907 } else {1908 setAttribute(STARTED_BY, DEFAULT_STARTED_BY);1909 }1910 }1911 1912 public void setArchiveToFile(String filePath) {1913 if (filePath != null) {1914 if (!filePath.endsWith(".zip")) {1915 throw new ConfigurationException("You must specify a zip file");1916 }1917 new File(filePath).getParentFile().mkdirs();19181919 }1920 setAttribute(ARCHIVE_TO_FILE, filePath);1921 }1922 1923 public void setArchive(String archive) {1924 if (archive == null) {1925 setAttribute(ARCHIVE, Arrays.asList(DEFAULT_ARCHIVE));1926 } else {1927 try {1928 setAttribute(ARCHIVE, ArchiveMode.fromString(archive));1929 } catch (IllegalArgumentException e) {1930 throw new ConfigurationException(e.getMessage());1931 }1932 }1933 }1934 public void setAdvancedElementSearch(String advanceElementSearchMode) {1935 if (advanceElementSearchMode == null) {1936 setAttribute(ADVANCED_ELEMENT_SEARCH, DEFAULT_ADVANCED_ELEMENT_SEARCH);1937 } else {1938 try {1939 setAttribute(ADVANCED_ELEMENT_SEARCH, ElementInfo.Mode.valueOf(advanceElementSearchMode.toUpperCase()));1940 } catch (IllegalArgumentException e) {1941 throw new ConfigurationException(e.getMessage());1942 }1943 }1944 }1945 1946 public void setFindErrorCause(Boolean active) {1947 if (active != null) {1948 setAttribute(FIND_ERROR_CAUSE, active);1949 } else {1950 setAttribute(FIND_ERROR_CAUSE, DEFAULT_FIND_ERROR_CAUSE);1951 }1952 }1953 19541955 public void setReportPortalActive(Boolean active) {1956 if (active != null) {1957 setAttribute(REPORTPORTAL_ACTIVE, active);1958 } else {1959 setAttribute(REPORTPORTAL_ACTIVE, DEFAULT_REPORTPORTAL_ACTIVE);1960 }1961 1962 }1963 1964 public void setImageFieldDetectorServerUrl(String url) {1965 if (url != null) {1966 setAttribute(IMAGE_FIELD_DETECTOR_SERVER_URL, url);1967 } else {1968 setAttribute(IMAGE_FIELD_DETECTOR_SERVER_URL, DEFAULT_IMAGE_FIELD_DETECTOR_SERVER_URL);1969 }1970 }1971 1972 public void setSeleniumRobotServerUrl(String url) {1973 if (url != null) {1974 setAttribute(SELENIUMROBOTSERVER_URL, url);1975 } else if (System.getenv(SELENIUMROBOTSERVER_URL) != null) {1976 setAttribute(SELENIUMROBOTSERVER_URL, System.getenv(SELENIUMROBOTSERVER_URL));1977 } else {1978 setAttribute(SELENIUMROBOTSERVER_URL, DEFAULT_SELENIUMROBOTSERVER_URL);1979 }1980 }1981 1982 public void setSeleniumRobotServerActive(Boolean active) {1983 if (active != null) {1984 setAttribute(SELENIUMROBOTSERVER_ACTIVE, active);1985 } else {1986 setAttribute(SELENIUMROBOTSERVER_ACTIVE, DEFAULT_SELENIUMROBOTSERVER_ACTIVE);1987 }1988 1989 if (getSeleniumRobotServerUrl() == null && getSeleniumRobotServerActive()) {1990 throw new ConfigurationException("SeleniumRobot server is requested but URL is not found, either in parameters, command line or through environment variable");1991 }1992 }1993 1994 public void setSeleniumRobotServerToken(String token) {1995 if (token != null) {1996 setAttribute(SELENIUMROBOTSERVER_TOKEN, token);1997 } else {1998 setAttribute(SELENIUMROBOTSERVER_TOKEN, DEFAULT_SELENIUMROBOTSERVER_TOKEN);1999 }2000 }2001 2002 public void setSeleniumRobotServerCompareSnapshot(Boolean capture) {2003 if (capture != null) {2004 setAttribute(SELENIUMROBOTSERVER_COMPARE_SNAPSHOT, capture);2005 } else {2006 setAttribute(SELENIUMROBOTSERVER_COMPARE_SNAPSHOT, DEFAULT_SELENIUMROBOTSERVER_COMPARE_SNAPSHOT);2007 }2008 }2009 2010 public void setSeleniumRobotServerCompareSnapshotBehaviour(String compareSnapshotBehaviour) {2011 if (compareSnapshotBehaviour != null) {2012 setAttribute(SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_BEHAVIOUR, SnapshotComparisonBehaviour.fromString(compareSnapshotBehaviour));2013 } else {2014 setAttribute(SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_BEHAVIOUR, DEFAULT_SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_BEHAVIOUR);2015 }2016 }2017 2018 public void setSeleniumRobotServerVariableOlderThan(Integer olderThan) {2019 if (olderThan != null) {2020 setAttribute(SELENIUMROBOTSERVER_VARIABLES_OLDER_THAN, olderThan);2021 } else {2022 setAttribute(SELENIUMROBOTSERVER_VARIABLES_OLDER_THAN, DEFAULT_SELENIUMROBOTSERVER_VARIABLES_OLDER_THAN);2023 }2024 }2025 2026 /**2027 * set time to live for snapshot comparison session2028 * @param timeToLive2029 */2030 public void setSeleniumRobotServerCompareSnapshotTtl(Integer timeToLive) {2031 if (timeToLive != null) {2032 setAttribute(SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_TTL, timeToLive);2033 } else {2034 setAttribute(SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_TTL, DEFAULT_SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_TTL);2035 }2036 }2037 2038 public void setSeleniumRobotServerRecordResults(Boolean recordResult) {2039 if (recordResult != null) {2040 setAttribute(SELENIUMROBOTSERVER_RECORD_RESULTS, recordResult);2041 } else {2042 setAttribute(SELENIUMROBOTSERVER_RECORD_RESULTS, DEFAULT_SELENIUMROBOTSERVER_RECORD_RESULTS);2043 }2044 }2045 2046 public void setVariableAlreadyRequestedFromServer(Map<String, TestVariable> variableAlreadyRequestedFromServer) {2047 this.variableAlreadyRequestedFromServer = variableAlreadyRequestedFromServer;2048 }20492050 public void setOverrideSeleniumNativeAction(Boolean override) {2051 if (override != null) {2052 setAttribute(OVERRIDE_SELENIUM_NATIVE_ACTION, override);2053 } else {2054 setAttribute(OVERRIDE_SELENIUM_NATIVE_ACTION, DEFAULT_OVERRIDE_SELENIUM_NATIVE_ACTION);2055 }2056 }2057 2058 /**2059 * /!\ FOR TEST ONLY!2060 * @param seleniumGridConnector2061 */2062 public void setSeleniumGridConnector(SeleniumGridConnector seleniumGridConnector) {2063 this.seleniumGridConnector = seleniumGridConnector;2064 }20652066 public void setWebDriverGrid(final String driverGrid) {2067 if (driverGrid == null) {2068 setAttribute(WEB_DRIVER_GRID, new ArrayList<>());2069 } else {2070 String[] gridList = driverGrid.split(",");2071 for (String gridAddress: gridList) {2072 if (!gridAddress.startsWith("http")) {2073 throw new ConfigurationException("grid address should be http://<host>:<port>/wd/hub");2074 }2075 }2076 setAttribute(WEB_DRIVER_GRID, Arrays.asList(driverGrid.split(",")));2077 }2078 }2079 2080 public void setNeoloadUserPath(final String userPath) {2081 setAttribute(NEOLOAD_USER_PATH, userPath);2082 }2083 2084 public void setConfiguration(Map<String, TestVariable> variables){2085 setAttribute(TEST_VARIABLES, variables);2086 }2087 2088 public void setInitialUrl(String url) {2089 if (url != null) {2090 setAttribute(INITIAL_URL, url);2091 } else {2092 setAttribute(INITIAL_URL, DEFAULT_INITIAL_URL);2093 }2094 }2095 2096 public void setTmsUrl(String url) {2097 if (url != null) {2098 setAttribute(TMS_URL, url);2099 } else {2100 setAttribute(TMS_URL, DEFAULT_TMS_URL);2101 }2102 }2103 2104 public void setTmsType(String type) {2105 if (type != null) {2106 setAttribute(TMS_TYPE, type);2107 } else {2108 setAttribute(TMS_TYPE, DEFAULT_TMS_TYPE);2109 }2110 }2111 2112 public void setTmsUser(String user){2113 setAttribute(TMS_USER, user);2114 }2115 2116 public void setTmsPassword(String password){2117 setAttribute(TMS_PASSWORD, password);2118 }2119 2120 public void setTmsProject(String project){2121 setAttribute(TMS_PROJECT, project);2122 }2123 2124 public void setBugtrackerUrl(String url) {2125 if (url != null) {2126 setAttribute(BUGTRACKER_URL, url);2127 } else {2128 setAttribute(BUGTRACKER_URL, DEFAULT_BUGTRACKER_URL);2129 }2130 }2131 2132 public void setBugtrackerType(String type) {2133 if (type != null) {2134 setAttribute(BUGTRACKER_TYPE, type);2135 } else {2136 setAttribute(BUGTRACKER_TYPE, DEFAULT_BUGTRACKER_TYPE);2137 }2138 }2139 2140 public void setBugtrackerUser(String user){2141 setAttribute(BUGTRACKER_USER, user);2142 }2143 2144 public void setBugtrackerPassword(String password){2145 setAttribute(BUGTRACKER_PASSWORD, password);2146 }2147 2148 public void setBugtrackerProject(String project){2149 setAttribute(BUGTRACKER_PROJECT, project);2150 }2151 2152 public void setFieldDetectorInstance(FieldDetectorConnector fieldDetectorInstance) {2153 this.fieldDetectorInstance = fieldDetectorInstance;2154 }2155 2156 public void setRunMode(String runMode) {2157 String newRunMode = runMode == null ? DEFAULT_RUN_MODE: runMode;2158 setAttribute(RUN_MODE, DriverMode.fromString(newRunMode));2159 }2160 2161 public void setNodeTags(String nodeTags) {2162 if (nodeTags == null || nodeTags.isEmpty()) {2163 setAttribute(NODE_TAGS, new ArrayList<>());2164 } else {2165 setAttribute(NODE_TAGS, Arrays.asList(nodeTags.split(","))2166 .stream()2167 .map(String::trim)2168 .collect(Collectors.toList())2169 );2170 }2171 }2172 2173 public void setMaskPassword(Boolean maskPassword) {2174 if (maskPassword != null) {2175 setAttribute(MASK_PASSWORD, maskPassword);2176 } else {2177 setAttribute(MASK_PASSWORD, DEFAULT_MASK_PASSWORD);2178 }2179 }2180 2181 public void setRandomInAttachmentNames(Boolean random) {2182 if (random != null) {2183 setAttribute(RANDOM_IN_ATTACHMENT_NAME, random);2184 } else {2185 setAttribute(RANDOM_IN_ATTACHMENT_NAME, DEFAULT_RANDOM_IN_ATTACHMENT_NAME);2186 }2187 }2188 2189 /**2190 * Record DEBUG2191 * also store an INTERNAL_DEBUG System property to be used internally with SeleniumRobotLogger class2192 * @param debug2193 */2194 public void setDebug(String debug) {2195 if (debug != null) {2196 setAttribute(DEBUG, DebugMode.fromString(debug));2197 System.setProperty(INTERNAL_DEBUG, debug);2198 } else {2199 // default value depends on who starts test. If start is done through jar execution, deployed mode will be true (devMode set to false)2200 setAttribute(DEBUG, DebugMode.fromString(DEFAULT_DEBUG));2201 System.setProperty(INTERNAL_DEBUG, DEFAULT_DEBUG);2202 }2203 }2204 2205 public void setHeadlessBrowser(Boolean headless) {2206 if (headless != null) {2207 setAttribute(HEADLESS_BROWSER, headless);2208 } else {2209 setAttribute(HEADLESS_BROWSER, DEFAULT_HEADLESS_BROWSER);2210 }2211 }2212 2213 public void setManualTestSteps(Boolean manualTestSteps) {2214 if (manualTestSteps != null) {2215 setAttribute(MANUAL_TEST_STEPS, manualTestSteps);2216 } else {2217 setAttribute(MANUAL_TEST_STEPS, DEFAULT_MANUAL_TEST_STEPS);2218 }2219 }22202221 public void setBrowser(String browser) {2222 String newBrowser = browser == null ? DEFAULT_BROWSER: browser;2223 setAttribute(BROWSER, BrowserType.getBrowserType(newBrowser));2224 2225 // when reconfiguring browser, mostly from integration tests, change test type accordingly2226 if (getPlatform() != null) {2227 configureTestType();2228 }22292230 setEdgeIeMode("iexploreEdge".equals(browser));22312232 }2233 2234 public void setBrowserVersion(String browserVersion) {2235 setAttribute(BROWSER_VERSION, browserVersion);2236 }2237 2238 public void setFirefoxUserProfilePath(String path) {2239 if (path != null && getBrowser() == BrowserType.FIREFOX) {2240 if ((new File(path).exists() && getRunMode() == DriverMode.LOCAL) || getRunMode() != DriverMode.LOCAL || BrowserInfo.DEFAULT_BROWSER_PRODFILE.equals(path)) {2241 setAttribute(FIREFOX_USER_PROFILE_PATH, path);2242 } else {2243 throw new ConfigurationException(String.format("Firefox user profile does not exist at %s", path));2244 }2245 }2246 2247 }2248 2249 public void setOperaUserProfilePath(String path) {2250 setAttribute(OPERA_USER_PROFILE_PATH, path);2251 }2252 2253 public void setChromeOptions(String options) {2254 setAttribute(CHROME_OPTIONS, options);2255 }2256 2257 public void setChromeUserProfilePath(String path) {2258 if (path != null && getBrowser() == BrowserType.CHROME) {2259 if ((new File(path).exists() && getRunMode() == DriverMode.LOCAL) || getRunMode() != DriverMode.LOCAL || BrowserInfo.DEFAULT_BROWSER_PRODFILE.equals(path)) {2260 setAttribute(CHROME_USER_PROFILE_PATH, path);2261 } else {2262 throw new ConfigurationException(String.format("Chrome user profile does not exist at %s", path));2263 }2264 } 2265 }2266 2267 public void setEdgeUserProfilePath(String path) {2268 if (path != null && getBrowser() == BrowserType.EDGE) {2269 if ((new File(path).exists() && getRunMode() == DriverMode.LOCAL) || getRunMode() != DriverMode.LOCAL || BrowserInfo.DEFAULT_BROWSER_PRODFILE.equals(path)) {2270 setAttribute(EDGE_USER_PROFILE_PATH, path);2271 } else {2272 throw new ConfigurationException(String.format("Edge user profile does not exist at %s", path));2273 }2274 } 2275 }2276 2277 public void setFirefoxBinary(String path) {2278 if (path != null && !new File(path).exists()) {2279 throw new ConfigurationException("Firefox path does not exist: " + path);2280 }2281 setAttribute(FIREFOX_BINARY_PATH, path);2282 }2283 2284 public void setChromeBinary(String path) {2285 if (path != null && !new File(path).exists()) {2286 throw new ConfigurationException("Chrome path does not exist: " + path);2287 }2288 setAttribute(CHROME_BINARY_PATH, path);2289 }2290 2291 public void setChromeDriverPath(String path) {2292 setAttribute(CHROME_DRIVER_PATH, path);2293 }2294 2295 public void setGeckoDriverPath(String path) {2296 setAttribute(GECKO_DRIVER_PATH, path);2297 }2298 2299 public void setEdgeDriverPath(String path) {2300 setAttribute(EDGE_DRIVER_PATH, path);2301 }2302 2303 public void setEdgeIeMode(boolean ieMode) {2304 setAttribute(EDGE_IE_MODE, ieMode);2305 }2306 2307 public void setIEDriverPath(String path) {2308 setAttribute(IE_DRIVER_PATH, path);2309 }2310 2311 public void setUserAgent(String path) {2312 setAttribute(USER_AGENT, path);2313 }2314 2315 public void setBetaBrowser(Boolean betaBrowser) {2316 if (betaBrowser != null) {2317 setAttribute(BETA_BROWSER, betaBrowser);2318 } else {2319 setAttribute(BETA_BROWSER, DEFAULT_BETA_BROWSER);2320 }2321 }2322 2323 public void setAssumeUntrustedCertificateIssuer(Boolean assume) {2324 if (assume != null) {2325 setAttribute(SET_ASSUME_UNTRUSTED_CERTIFICATE_ISSUER, assume);2326 } else {2327 setAttribute(SET_ASSUME_UNTRUSTED_CERTIFICATE_ISSUER, DEFAULT_SET_ASSUME_UNTRUSTED_CERTIFICATE_ISSUER);2328 }2329 }2330 2331 public void setAcceptUntrustedCertificates(Boolean accept) {2332 if (accept != null) {2333 setAttribute(SET_ACCEPT_UNTRUSTED_CERTIFICATES, accept);2334 } else {2335 setAttribute(SET_ACCEPT_UNTRUSTED_CERTIFICATES, DEFAULT_SET_ACCEPT_UNTRUSTED_CERTIFICATES);2336 }2337 }2338 2339 public void setJavascriptEnabled(Boolean enabled) {2340 if (enabled != null) {2341 setAttribute(ENABLE_JAVASCRIPT, enabled);2342 } else {2343 setAttribute(ENABLE_JAVASCRIPT, DEFAULT_ENABLE_JAVASCRIPT);2344 }2345 }2346 2347 public void setNtlmAuthTrustedUris(String uris) {2348 setAttribute(NTLM_AUTH_TRUSTED_URIS, uris);2349 }2350 2351 public void setBrowserDownloadDir(String downloadDir) {2352 setAttribute(BROWSER_DOWNLOAD_DIR, downloadDir);2353 }2354 2355 public void setFullReset(Boolean enabled) {2356 if (enabled != null) {2357 setAttribute(FULL_RESET, enabled);2358 } else {2359 setAttribute(FULL_RESET, true);2360 }2361 }2362 23632364 public void setWebProxyType(String proxyType) {2365 try {2366 setAttribute(WEB_PROXY_TYPE, ProxyType.valueOf(proxyType.toUpperCase()));2367 setAttribute(WEB_PROXY_TYPE_FROM_USER, proxyType.toUpperCase());2368 } catch (NullPointerException | IllegalArgumentException e) {2369 setAttribute(WEB_PROXY_TYPE, DEFAULT_WEB_PROXY_TYPE);2370 setAttribute(WEB_PROXY_TYPE_FROM_USER, null);2371 }2372 2373 }2374 2375 public void setWebProxyAddress(String proxyAddress) {2376 setAttribute(WEB_PROXY_ADDRESS, proxyAddress);2377 }2378 2379 public void setWebProxyPort(Integer port) {2380 setAttribute(WEB_PROXY_PORT, port); 2381 }2382 2383 public void setWebProxyLogin(String login) {2384 setAttribute(WEB_PROXY_LOGIN, login);2385 }2386 2387 public void setWebProxyPassword(String password) {2388 setAttribute(WEB_PROXY_PASSWORD, password);2389 }2390 2391 public void setWebProxyPac(String pacAddress) {2392 setAttribute(WEB_PROXY_PAC, pacAddress);2393 }2394 2395 public void setWebProxyExclude(String proxyExclude) {2396 setAttribute(WEB_PROXY_EXCLUDE, proxyExclude);2397 }2398 2399 2400 2401 public void setSnapshotScrollDelay(Integer scrollDelay) {2402 if (scrollDelay != null) {2403 setAttribute(SNAPSHOT_SCROLL_DELAY, scrollDelay);2404 } else {2405 setAttribute(SNAPSHOT_SCROLL_DELAY, DEFAULT_SNAPSHOT_SCROLL_DELAY);2406 }2407 }2408 2409 public void setSnapshotBottomCropping(Integer crop) {2410 if (crop != null) {2411 setAttribute(SNAPSHOT_BOTTOM_CROPPING, crop);2412 } else {2413 setAttribute(SNAPSHOT_BOTTOM_CROPPING, DEFAULT_SNAPSHOT_BOTTOM_CROPPING);2414 }2415 }2416 2417 public void setSnapshotTopCropping(Integer crop) {2418 if (crop != null) {2419 setAttribute(SNAPSHOT_TOP_CROPPING, crop);2420 } else {2421 setAttribute(SNAPSHOT_TOP_CROPPING, DEFAULT_SNAPSHOT_TOP_CROPPING);2422 }2423 }2424 2425 public void setCaptureSnapshot(Boolean capture) {2426 if (capture != null) {2427 setAttribute(CAPTURE_SNAPSHOT, capture);2428 } else {2429 setAttribute(CAPTURE_SNAPSHOT, DEFAULT_CAPTURE_SNAPSHOT);2430 }2431 }2432 2433 public void setCaptureNetwork(Boolean capture) {2434 if (capture != null) {2435 setAttribute(CAPTURE_NETWORK, capture);2436 } else {2437 setAttribute(CAPTURE_NETWORK, DEFAULT_CAPTURE_NETWORK);2438 }2439 }2440 2441 public void setVideoCapture(String capture) {2442 String newCapture = capture == null ? DEFAULT_VIDEO_CAPTURE: capture;2443 try {2444 setAttribute(VIDEO_CAPTURE, VideoCaptureMode.fromString(newCapture));2445 } catch (IllegalArgumentException e) {2446 throw new ConfigurationException("Only 'true', 'false', 'onSuccess', 'onError' are supported for video capture");2447 }2448 }24492450 public void setDpTagsInclude(String tags) {2451 setAttribute(DP_TAGS_INCLUDE, tags);2452 }2453 2454 public void setDpTagsExclude(String tags) {2455 setAttribute(DP_TAGS_EXCLUDE, tags);2456 }2457 2458 public void setReporterPluginClasses(String classNames) {2459 if (classNames != null) {2460 List<Class<IReporter>> reporterClasses = new ArrayList<>();
...
Source:WebDriverListener.java
...41public interface WebDriverListener {42 // Global43 default void beforeAnyCall(Object target, Method method, Object[] args) {}44 default void afterAnyCall(Object target, Method method, Object[] args, Object result) {}45 default void onError(Object target, Method method, Object[] args, InvocationTargetException e) {}46 // WebDriver47 default void beforeAnyWebDriverCall(WebDriver driver, Method method, Object[] args) {}48 default void afterAnyWebDriverCall(WebDriver driver, Method method, Object[] args, Object result) {}49 default void beforeGet(WebDriver driver, String url) {}50 default void afterGet(WebDriver driver, String url) {}51 default void beforeGetCurrentUrl(WebDriver driver) {}52 default void afterGetCurrentUrl(String result, WebDriver driver) {}53 default void beforeGetTitle(WebDriver driver) {}54 default void afterGetTitle(WebDriver driver, String result) {}55 default void beforeFindElement(WebDriver driver, By locator) {}56 default void afterFindElement(WebDriver driver, By locator, WebElement result) {}57 default void beforeFindElements(WebDriver driver, By locator) {}58 default void afterFindElements(WebDriver driver, By locator, List<WebElement> result) {}59 default void beforeGetPageSource(WebDriver driver) {}...
onError
Using AI Code Generation
1public void testMethod(){2 WebDriver driver = new FirefoxDriver();3 WebDriverEventListener eventListener = new WebDriverEventListener() {4 public void beforeAlertAccept(WebDriver webDriver) {5 System.out.println("Before Alert Accept");6 }7 public void afterAlertAccept(WebDriver webDriver) {8 System.out.println("After Alert Accept");9 }10 public void afterAlertDismiss(WebDriver webDriver) {11 System.out.println("After Alert Dismiss");12 }13 public void beforeAlertDismiss(WebDriver webDriver) {14 System.out.println("Before Alert Dismiss");15 }16 public void beforeNavigateTo(String s, WebDriver webDriver) {17 System.out.println("Before Navigate To");18 }19 public void afterNavigateTo(String s, WebDriver webDriver) {20 System.out.println("After Navigate To");21 }22 public void beforeNavigateBack(WebDriver webDriver) {23 System.out.println("Before Navigate Back");24 }25 public void afterNavigateBack(WebDriver webDriver) {26 System.out.println("After Navigate Back");27 }28 public void beforeNavigateForward(WebDriver webDriver) {29 System.out.println("Before Navigate Forward");30 }31 public void afterNavigateForward(WebDriver webDriver) {32 System.out.println("After Navigate Forward");33 }34 public void beforeNavigateRefresh(WebDriver webDriver) {35 System.out.println("Before Navigate Refresh");36 }37 public void afterNavigateRefresh(WebDriver webDriver) {38 System.out.println("After Navigate Refresh");39 }40 public void beforeFindBy(By by, WebElement webElement, WebDriver webDriver) {41 System.out.println("Before Find By");42 }43 public void afterFindBy(By by, WebElement webElement, WebDriver webDriver) {44 System.out.println("After Find By");45 }46 public void beforeClickOn(WebElement webElement, WebDriver webDriver) {47 System.out.println("Before Click On");48 }49 public void afterClickOn(WebElement webElement, WebDriver webDriver) {50 System.out.println("After Click On");51 }52 public void beforeChangeValueOf(WebElement webElement, WebDriver webDriver, CharSequence[] charSequences)
onError
Using AI Code Generation
1public class Test implements WebDriverListener {2public void onError(WebDriver driver) {3System.out.println("Error in driver");4}5}6WebDriver driver = new FirefoxDriver();7Test test = new Test();8EventFiringWebDriver eventDriver = new EventFiringWebDriver(driver);9eventDriver.register(test);10public class Test implements WebDriverEventListener {11public void beforeNavigateTo(String url, WebDriver driver) {12System.out.println("beforeNavigateTo");13}14public void afterNavigateTo(String url, WebDriver driver) {15System.out.println("afterNavigateTo");16}17public void beforeNavigateBack(WebDriver driver) {18System.out.println("beforeNavigateBack");19}20public void afterNavigateBack(WebDriver driver) {21System.out.println("afterNavigateBack");22}23public void beforeNavigateForward(WebDriver driver) {24System.out.println("beforeNavigateForward");25}26public void afterNavigateForward(WebDriver driver) {27System.out.println("afterNavigateForward");28}29public void beforeNavigateRefresh(WebDriver driver) {30System.out.println("beforeNavigateRefresh");31}32public void afterNavigateRefresh(WebDriver driver) {33System.out.println("afterNavigateRefresh");34}35public void beforeFindBy(By by, WebElement element, WebDriver driver) {36System.out.println("beforeFindBy");37}38public void afterFindBy(By by, WebElement element, WebDriver driver) {39System.out.println("afterFindBy");40}41public void beforeClickOn(WebElement element, WebDriver driver) {42System.out.println("beforeClickOn");43}44public void afterClickOn(WebElement element, WebDriver driver) {45System.out.println("afterClickOn");46}47public void beforeChangeValueOf(WebElement element, WebDriver driver, CharSequence[] keysToSend) {48System.out.println("beforeChangeValueOf");49}50public void afterChangeValueOf(WebElement element, WebDriver driver, CharSequence[] keysToSend) {51System.out.println("afterChangeValueOf");52}53public void beforeScript(String script, WebDriver driver) {54System.out.println("beforeScript");55}56public void afterScript(String script, WebDriver driver) {57System.out.println("afterScript");58}59public void beforeSwitchToWindow(String windowName, WebDriver driver) {60System.out.println("beforeSwitchToWindow");61}62public void afterSwitchToWindow(String windowName, WebDriver driver) {63System.out.println("afterSwitchToWindow");64}65public void onException(Throwable throwable, WebDriver driver) {66System.out.println("onException");67}68}
LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.
Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.
What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.
Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.
Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.
How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.
Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.
Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.
LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!