How to use setCerberus_sikuli_wait_element method of org.cerberus.engine.entity.Session class

Best Cerberus-source code snippet using org.cerberus.engine.entity.Session.setCerberus_sikuli_wait_element

Source:RobotServerService.java Github

copy

Full Screen

...170 session.setCerberus_selenium_setScriptTimeout(cerberus_selenium_setScriptTimeout);171 // _wait_element parameters172 session.setCerberus_selenium_wait_element(cerberus_selenium_wait_element);173 session.setCerberus_selenium_wait_element_default(cerberus_selenium_wait_element);174 session.setCerberus_sikuli_wait_element(cerberus_sikuli_wait_element);175 session.setCerberus_sikuli_wait_element_default(cerberus_sikuli_wait_element);176 session.setCerberus_appium_wait_element(cerberus_appium_wait_element);177 session.setCerberus_appium_wait_element_default(cerberus_appium_wait_element);178 // minSimilarity parameters179 session.setCerberus_sikuli_minSimilarity(cerberus_sikuli_minSimilarity);180 session.setCerberus_sikuli_minSimilarity_default(cerberus_sikuli_minSimilarity);181 // highlightElement parameters182 session.setCerberus_selenium_highlightElement(cerberus_selenium_highlightElement);183 session.setCerberus_selenium_highlightElement_default(cerberus_selenium_highlightElement);184 session.setCerberus_sikuli_highlightElement(cerberus_sikuli_highlightElement);185 session.setCerberus_sikuli_highlightElement_default(cerberus_sikuli_highlightElement);186 // auto scroll parameters187 session.setCerberus_selenium_autoscroll(cerberus_selenium_autoscroll);188 session.setCerberus_selenium_autoscroll_vertical_offset(cerberus_selenium_autoscroll_vertical_offset);189 session.setCerberus_selenium_autoscroll_horizontal_offset(cerberus_selenium_autoscroll_horizontal_offset);190 session.setCerberus_selenium_action_click_timeout(cerberus_selenium_action_click_timeout);191 session.setCerberus_appium_action_longpress_wait(cerberus_appium_action_longpress_wait);192 session.setHost(tCExecution.getSeleniumIP());193 session.setPort(tCExecution.getRobotPort());194 session.setHostUser(tCExecution.getSeleniumIPUser());195 session.setHostPassword(tCExecution.getSeleniumIPPassword());196 session.setNodeHost(tCExecution.getSeleniumIP());197 session.setNodePort(tCExecution.getSeleniumPort());198 if (tCExecution.getRobotExecutorObj() != null) {199 LOG.debug("Session node proxy set : {}", tCExecution.getRobotExecutorObj().getNodeProxyPort());200 session.setNodeProxyPort(tCExecution.getRobotExecutorObj().getNodeProxyPort());201 } else {202 session.setNodeProxyPort(0);203 }204 session.setConsoleLogs(new JSONArray());205 tCExecution.setSession(session);206 tCExecution.setRobotProvider(guessRobotProvider(session.getHost()));207 LOG.debug("Session is set.");208 /*209 * Starting Cerberus Executor Proxy if it has been activated at210 * robot level.211 */212 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {213 LOG.debug("Start Remote Proxy");214 executorService.startRemoteProxy(tCExecution);215 LOG.debug("Started Remote Proxy on port: {}", tCExecution.getRemoteProxyPort());216 }217 // SetUp Capabilities218 LOG.debug("Set Capabilities");219 MutableCapabilities caps = this.setCapabilities(tCExecution);220 session.setDesiredCapabilities(caps);221 LOG.debug("Set Capabilities - retrieved");222 // We record Caps list at the execution level.223 try {224 // Init additionalFinalCapabilities and set it from real caps.225 List<RobotCapability> additionalFinalCapabilities = new ArrayList<>();226 for (Map.Entry<String, Object> cap : caps.asMap().entrySet()) {227 additionalFinalCapabilities.add(factoryRobotCapability.create(0, "", cap.getKey(), cap.getValue().toString()));228 }229 // Init inputCapabilities and set it from Robot values.230 List<RobotCapability> inputCapabilities = new ArrayList<>();231 if (tCExecution.getRobotObj() != null) {232 inputCapabilities = tCExecution.getRobotObj().getCapabilities();233 }234 tCExecution.addFileList(recorderService.recordCapabilities(tCExecution, inputCapabilities, additionalFinalCapabilities));235 } catch (Exception ex) {236 LOG.error("Exception Saving Robot Caps {} Exception: {}", tCExecution.getId(), ex.toString(), ex);237 }238 // SetUp Proxy239 String hubUrl = StringUtil.cleanHostURL(RobotServerService.getBaseUrl(StringUtil.formatURLCredential(240 tCExecution.getSession().getHostUser(),241 tCExecution.getSession().getHostPassword(), session.getHost()),242 session.getPort())) + "/wd/hub";243 LOG.debug("Hub URL :{}", hubUrl);244 URL url = new URL(hubUrl);245 HttpCommandExecutor executor = null;246 boolean isProxy = proxyService.useProxy(hubUrl, system);247 Factory factory = new OkHttpClient.Factory();248 // Timeout Management249 int robotTimeout = parameterService.getParameterIntegerByKey("cerberus_robot_timeout", system, 60000);250 Duration rbtTimeOut = Duration.ofMillis(robotTimeout);251 factory.builder().connectionTimeout(rbtTimeOut);252 if (isProxy) {253 // Proxy Management254 String proxyHost = parameterService.getParameterStringByKey("cerberus_proxy_host", system, DEFAULT_PROXY_HOST);255 int proxyPort = parameterService.getParameterIntegerByKey("cerberus_proxy_port", system, DEFAULT_PROXY_PORT);256 java.net.Proxy myproxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));257 if (parameterService.getParameterBooleanByKey("cerberus_proxyauthentification_active", system, DEFAULT_PROXYAUTHENT_ACTIVATE)) {258 String proxyUser = parameterService.getParameterStringByKey("cerberus_proxyauthentification_user", system, DEFAULT_PROXYAUTHENT_USER);259 String proxyPassword = parameterService.getParameterStringByKey("cerberus_proxyauthentification_password", system, DEFAULT_PROXYAUTHENT_PASSWORD);260 // TODO delete if comment bellow has no impact on the non reg campaign261/*262 Authenticator proxyAuthenticator = new Authenticator() {263 public Request authenticate(Route route, Response response) throws IOException {264 String credential = Credentials.basic(proxyUser, proxyPassword);265 return response.request().newBuilder()266 .header("Proxy-Authorization", credential)267 .build();268 }269 };270*/271 }272 factory.builder().proxy(myproxy);273 } else {274 factory.builder().proxy(java.net.Proxy.NO_PROXY);275 }276 executor = new HttpCommandExecutor(new HashMap<>(), url, factory);277 // SetUp Driver278 LOG.debug("Set Driver");279 WebDriver driver = null;280 AppiumDriver appiumDriver = null;281 switch (tCExecution.getApplicationObj().getType().toUpperCase()) {282 case Application.TYPE_GUI:283 if (caps.getPlatform() != null && caps.getPlatform().is(Platform.ANDROID)) {284 // Appium does not support connection from HTTPCommandExecutor. When connecting from Executor, it stops to work after a couple of instructions.285 appiumDriver = new AndroidDriver(url, caps);286 } else if (caps.getPlatform() != null && (caps.getPlatform().is(Platform.IOS) || caps.getPlatform().is(Platform.MAC))) {287 appiumDriver = new IOSDriver(url, caps);288 }289 driver = appiumDriver == null ? new RemoteWebDriver(executor, caps) : appiumDriver;290 tCExecution.setRobotProviderSessionID(getSession(driver, tCExecution.getRobotProvider()));291 tCExecution.setRobotSessionID(getSession(driver));292 break;293 case Application.TYPE_APK:294 // add a lock on app path this part of code, because we can't install 2 apk with the same name simultaneously295 String appUrl = null;296 if (caps.getCapability("app") != null) {297 appUrl = caps.getCapability("app").toString();298 }299 if (appUrl != null) { // FIX : appium can't install 2 apk simultaneously, so implement a litle latency between execution300 synchronized (this) {301 // with appium 1.7.2, we can't install 2 fresh apk simultaneously. Appium have to prepare the apk (transformation) on the first execution before (see this topic https://discuss.appium.io/t/execute-2-android-test-simultaneously-problem-during-install-apk/22030)302 // provoque a latency if first test is already running and apk don't finish to be prepared303 if (apkAlreadyPrepare.containsKey(appUrl) && Boolean.TRUE.equals(!apkAlreadyPrepare.get(appUrl))) {304 Thread.sleep(10000);305 } else {306 apkAlreadyPrepare.put(appUrl, false);307 }308 }309 }310 appiumDriver = new AndroidDriver(url, caps);311 if (apkAlreadyPrepare.containsKey(appUrl)) {312 apkAlreadyPrepare.put(appUrl, true);313 }314 driver = appiumDriver;315 tCExecution.setRobotProviderSessionID(getSession(driver, tCExecution.getRobotProvider()));316 tCExecution.setRobotSessionID(getSession(driver));317 break;318 case Application.TYPE_IPA:319 appiumDriver = new IOSDriver(url, caps);320 driver = appiumDriver;321 tCExecution.setRobotProviderSessionID(getSession(driver, tCExecution.getRobotProvider()));322 tCExecution.setRobotSessionID(getSession(driver));323 break;324 case Application.TYPE_FAT:325 // Check sikuli extension is reachable326 if (!sikuliService.isSikuliServerReachableOnRobot(session)) {327 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_SIKULI_COULDNOTCONNECT);328 mes.setDescription(mes.getDescription().replace("%SSIP%", tCExecution.getSession().getHost()));329 mes.setDescription(mes.getDescription().replace("%SSPORT%", tCExecution.getSession().getPort()));330 throw new CerberusException(mes);331 }332 // If CountryEnvParameter IP is set, open the App333 if (!tCExecution.getCountryEnvironmentParameters().getIp().isEmpty()) {334 sikuliService.doSikuliActionOpenApp(session, tCExecution.getCountryEnvironmentParameters().getIp());335 }336 break;337 }338 // We record Server Side Caps.339 if (driver != null) {340 try {341 // Init additionalFinalCapabilities and set it from real caps.342 List<RobotCapability> serverCapabilities = new ArrayList<>();343 for (Map.Entry<String, Object> cap : ((HasCapabilities) driver).getCapabilities().asMap().entrySet()) {344 serverCapabilities.add(factoryRobotCapability.create(0, "", cap.getKey(), cap.getValue().toString()));345 }346 tCExecution.addFileList(recorderService.recordServerCapabilities(tCExecution, serverCapabilities));347 } catch (Exception ex) {348 LOG.error("Exception Saving Server Robot Caps " + tCExecution.getId(), ex);349 }350 }351 /*352 * Defining the timeout at the driver level. Only in case of no353 * Appium Driver (see354 * https://github.com/vertigo17/Cerberus/issues/754)355 */356 if (driver != null && appiumDriver == null) {357 driver.manage().timeouts().pageLoadTimeout(cerberus_selenium_pageLoadTimeout, TimeUnit.MILLISECONDS);358 driver.manage().timeouts().implicitlyWait(cerberus_selenium_implicitlyWait, TimeUnit.MILLISECONDS);359 driver.manage().timeouts().setScriptTimeout(cerberus_selenium_setScriptTimeout, TimeUnit.MILLISECONDS);360 }361 if (appiumDriver != null) {362 appiumDriver.manage().timeouts().implicitlyWait(cerberus_appium_wait_element, TimeUnit.MILLISECONDS);363 }364 tCExecution.getSession().setDriver(driver);365 tCExecution.getSession().setAppiumDriver(appiumDriver);366 /*367 * If Gui application, maximize window Get IP of Node in case of368 * remote Server. Maximize does not work for chrome browser We also369 * get the Real UserAgent from the browser.370 */371 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)372 && !caps.getPlatform().equals(Platform.ANDROID) && !caps.getPlatform().equals(Platform.IOS)373 && !caps.getPlatform().equals(Platform.MAC)) {374 // Maximize is not supported on Opera.375 if (!caps.getBrowserName().equals(BrowserType.CHROME) && !tCExecution.getBrowser().equalsIgnoreCase("opera")) {376 driver.manage().window().maximize();377 }378 getIPOfNode(tCExecution);379 // If screenSize is defined, set the size of the screen.380 String targetScreensize = getScreenSizeToUse(tCExecution.getTestCaseObj().getScreenSize(), tCExecution.getScreenSize());381 LOG.debug("Selenium resolution : {}", targetScreensize);382 if (!tCExecution.getBrowser().equalsIgnoreCase(BrowserType.CHROME)) {383 // For chrome the resolution has already been defined at capabilities level.384 if ((!StringUtil.isNullOrEmpty(targetScreensize)) && targetScreensize.contains("*")) {385 Integer screenWidth = Integer.valueOf(targetScreensize.split("\\*")[0]);386 Integer screenLength = Integer.valueOf(targetScreensize.split("\\*")[1]);387 setScreenSize(driver, screenWidth, screenLength);388 LOG.debug("Selenium resolution Activated : {}*{}", screenWidth, screenLength);389 }390 }391 // Getting windows size Not supported on Opera.392 if (!tCExecution.getBrowser().equalsIgnoreCase("opera")) {393 tCExecution.setScreenSize(getScreenSize(driver));394 }395 tCExecution.setRobotDecli(tCExecution.getRobotDecli().replace("%SCREENSIZE%", tCExecution.getScreenSize()));396 String userAgent = (String) ((JavascriptExecutor) driver).executeScript("return navigator.userAgent;");397 tCExecution.setUserAgent(userAgent);398 }399 // unlock device if deviceLockUnlock is active400 if (tCExecution.getRobotExecutorObj() != null && appiumDriver instanceof LocksDevice401 && "Y".equals(tCExecution.getRobotExecutorObj().getDeviceLockUnlock())) {402 ((LocksDevice) appiumDriver).unlockDevice();403 }404 // Check if Sikuli is available on node.405 if (driver != null) {406 tCExecution.getSession().setSikuliAvailable(sikuliService.isSikuliServerReachableOnNode(tCExecution.getSession()));407 }408 tCExecution.getSession().setStarted(true);409 } catch (CerberusException exception) {410 LOG.error(exception.toString(), exception);411 throw new CerberusException(exception.getMessageError(), exception);412 } catch (MalformedURLException exception) {413 LOG.error(exception.toString(), exception);414 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_URL_MALFORMED);415 mes.setDescription(mes.getDescription().replace("%URL%", tCExecution.getSession().getHost() + ":" + tCExecution.getSession().getPort()));416 throw new CerberusException(mes, exception);417 } catch (UnreachableBrowserException exception) {418 LOG.warn("Could not connect to : {}:{}", tCExecution.getSeleniumIP(), tCExecution.getSeleniumPort());419 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_SELENIUM_COULDNOTCONNECT);420 mes.setDescription(mes.getDescription().replace("%SSIP%", tCExecution.getSeleniumIP()));421 mes.setDescription(mes.getDescription().replace("%SSPORT%", tCExecution.getSeleniumPort()));422 mes.setDescription(mes.getDescription().replace("%ERROR%", exception.toString()));423 throw new CerberusException(mes, exception);424 } catch (Exception exception) {425 LOG.error(exception.toString(), exception);426 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);427 mes.setDescription(mes.getDescription().replace("%MES%", exception.toString()));428 executorService.stopRemoteProxy(tCExecution);429 throw new CerberusException(mes, exception);430 } finally {431 executionThreadPoolService.executeNextInQueueAsynchroneously(false);432 }433 }434 private String getSession(WebDriver driver, String robotProvider) {435 String session = "";436 switch (robotProvider) {437 case TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK:438 case TestCaseExecution.ROBOTPROVIDER_LAMBDATEST: // For LambdaTest we get the exeid not here but by service call at the end of the execution.439 case TestCaseExecution.ROBOTPROVIDER_NONE:440 session = ((RemoteWebDriver) driver).getSessionId().toString();441 break;442 case TestCaseExecution.ROBOTPROVIDER_KOBITON:443 session = ((HasCapabilities) driver).getCapabilities().getCapability("kobitonSessionId").toString();444 break;445 default:446 }447 return session;448 }449 private String getSession(WebDriver driver) {450 String session = "";451 session = ((RemoteWebDriver) driver).getSessionId().toString();452 return session;453 }454 private String guessRobotProvider(String host) {455 if (host.contains("browserstack")) {456 return TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK;457 }458 if (host.contains("kobiton")) {459 return TestCaseExecution.ROBOTPROVIDER_KOBITON;460 }461 if (host.contains("lambdatest")) {462 return TestCaseExecution.ROBOTPROVIDER_LAMBDATEST;463 }464 return TestCaseExecution.ROBOTPROVIDER_NONE;465 }466 /**467 * Set DesiredCapabilities468 *469 * @param tCExecution470 * @return471 * @throws CerberusException472 */473 private MutableCapabilities setCapabilities(TestCaseExecution tCExecution) throws CerberusException {474 // Instanciate DesiredCapabilities475 MutableCapabilities caps = new MutableCapabilities();476 // In case browser is not defined at that level, we force it to firefox.477 if (StringUtil.isNullOrEmpty(tCExecution.getBrowser())) {478 tCExecution.setBrowser("");479 }480 // Set Browser Capabilities481 caps = this.setCapabilityBrowser(caps, tCExecution.getBrowser(), tCExecution);482 // Loop on RobotCapabilities to feed DesiredCapabilities Capability must be String, Integer or Boolean483 List<RobotCapability> additionalCapabilities = new ArrayList<>();484 if (tCExecution.getRobotObj() != null) {485 additionalCapabilities = tCExecution.getRobotObj().getCapabilitiesDecoded();486 }487 if (additionalCapabilities != null) {488 for (RobotCapability additionalCapability : additionalCapabilities) {489 LOG.debug("RobotCaps on Robot : {} caps: {} Value: {}", additionalCapability.getRobot(), additionalCapability.getCapability(), additionalCapability.getValue());490 if ((caps.getCapability(additionalCapability.getCapability()) == null)491 || ((caps.getCapability(additionalCapability.getCapability()) != null) && (caps.getCapability(additionalCapability.getCapability()).toString().isEmpty()))) { // caps does not already exist so we can set it.492 if (StringUtil.isBoolean(additionalCapability.getValue())) {493 caps.setCapability(additionalCapability.getCapability(), StringUtil.parseBoolean(additionalCapability.getValue()));494 } else if (StringUtil.isInteger(additionalCapability.getValue())) {495 caps.setCapability(additionalCapability.getCapability(), Integer.valueOf(additionalCapability.getValue()));496 } else {497 caps.setCapability(additionalCapability.getCapability(), additionalCapability.getValue());498 }499 }500 }501 } else {502 additionalCapabilities = new ArrayList<>();503 }504 // Feed DesiredCapabilities with values get from Robot505 if (!StringUtil.isNullOrEmpty(tCExecution.getPlatform())506 && ((caps.getCapability("platform") == null)507 || ((caps.getCapability("platform") != null)508 && (caps.getCapability("platform").toString().equals("ANY")509 || caps.getCapability("platform").toString().isEmpty())))) {510 caps.setCapability("platformName", tCExecution.getPlatform());511 }512 if (!StringUtil.isNullOrEmpty(tCExecution.getVersion())513 && ((caps.getCapability("version") == null)514 || ((caps.getCapability("version") != null)515 && (caps.getCapability("version").toString().isEmpty())))) {516 caps.setCapability("version", tCExecution.getVersion());517 }518 if (tCExecution.getRobotExecutorObj() != null) {519 // Setting deviceUdid and device name from executor.520 if (!StringUtil.isNullOrEmpty(tCExecution.getRobotExecutorObj().getDeviceUuid())521 && ((caps.getCapability("udid") == null)522 || ((caps.getCapability("udid") != null)523 && (caps.getCapability("udid").toString().isEmpty())))) {524 caps.setCapability("udid", tCExecution.getRobotExecutorObj().getDeviceUuid());525 }526 if (!StringUtil.isNullOrEmpty(tCExecution.getRobotExecutorObj().getDeviceName())527 && ((caps.getCapability("deviceName") == null)528 || ((caps.getCapability("deviceName") != null)529 && (caps.getCapability("deviceName").toString().isEmpty())))) {530 caps.setCapability("deviceName", tCExecution.getRobotExecutorObj().getDeviceName());531 }532 if (!StringUtil.isNullOrEmpty(tCExecution.getRobotExecutorObj().getDeviceName())) {533 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)534 && ((caps.getCapability("systemPort") == null)535 || ((caps.getCapability("systemPort") != null)536 && (caps.getCapability("systemPort").toString().isEmpty())))) {537 caps.setCapability("systemPort", tCExecution.getRobotExecutorObj().getDevicePort());538 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)539 && ((caps.getCapability("wdaLocalPort") == null)540 || ((caps.getCapability("wdaLocalPort") != null)541 && (caps.getCapability("wdaLocalPort").toString().isEmpty())))) {542 caps.setCapability("wdaLocalPort", tCExecution.getRobotExecutorObj().getDevicePort());543 }544 }545 }546 // if application is a mobile one, then set the "app" capability to theapplication binary path547 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)548 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {549 // Set the app capability with the application path550 if (!StringUtil.isNullOrEmpty(tCExecution.getMyHost())551 && (isNotAlreadyDefined(caps, "app"))) {552 caps.setCapability("app", tCExecution.getMyHost());553 } else if (isNotAlreadyDefined(caps, "app")) {554 caps.setCapability("app", tCExecution.getCountryEnvironmentParameters().getIp());555 }556 if (!StringUtil.isNullOrEmpty(tCExecution.getCountryEnvironmentParameters().getMobileActivity())557 && (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)558 && isNotAlreadyDefined(caps, "appWaitActivity"))) {559 caps.setCapability("appWaitActivity", tCExecution.getCountryEnvironmentParameters().getMobileActivity());560 }561 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)562 && (isNotAlreadyDefined(caps, "automationName"))) {563 caps.setCapability("automationName", "UIAutomator2"); // use UIAutomator2 by default564 }565 }566 // Setting specific capabilities of external cloud providers.567 switch (tCExecution.getRobotProvider()) {568 case TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK:569 if (!StringUtil.isNullOrEmpty(tCExecution.getTag()) && isNotAlreadyDefined(caps, "build")) {570 caps.setCapability("build", tCExecution.getTag());571 }572 if (isNotAlreadyDefined(caps, "project")) {573 caps.setCapability("project", tCExecution.getApplication());574 }575 if (isNotAlreadyDefined(caps, "name")) {576 String externalExeName = parameterService.getParameterStringByKey("cerberus_browserstack_defaultexename", tCExecution.getSystem(), "Exe : %EXEID%");577 externalExeName = externalExeName.replace("%EXEID%", String.valueOf(tCExecution.getId()));578 caps.setCapability("name", externalExeName);579 }580 if (tCExecution.getVerbose() >= 2) {581 if (isNotAlreadyDefined(caps, "browserstack.debug")) {582 caps.setCapability("browserstack.debug", true);583 }584 if (isNotAlreadyDefined(caps, "browserstack.console")) {585 caps.setCapability("browserstack.console", "warnings");586 }587 if (isNotAlreadyDefined(caps, "browserstack.networkLogs")) {588 caps.setCapability("browserstack.networkLogs", true);589 }590 }591 //Create or override these capabilities if proxy required.592 if (StringUtil.parseBoolean(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {593 caps.setCapability("browserstack.local", true);594 caps.setCapability("browserstack.user", tCExecution.getRobotExecutorObj().getHostUser());595 caps.setCapability("browserstack.key", tCExecution.getRobotExecutorObj().getHostPassword());596 caps.setCapability("browserstack.localIdentifier", tCExecution.getExecutionUUID());597 }598 break;599 case TestCaseExecution.ROBOTPROVIDER_LAMBDATEST:600 if (!StringUtil.isNullOrEmpty(tCExecution.getTag()) && isNotAlreadyDefined(caps, "build")) {601 caps.setCapability("build", tCExecution.getTag());602 }603 if (isNotAlreadyDefined(caps, "name")) {604 String externalExeName = parameterService.getParameterStringByKey("cerberus_lambdatest_defaultexename", tCExecution.getSystem(), "Exe : %EXEID% - %TESTDESCRIPTION%");605 externalExeName = externalExeName.replace("%EXEID%", String.valueOf(tCExecution.getId()));606 externalExeName = externalExeName.replace("%TESTFOLDER%", String.valueOf(tCExecution.getTest()));607 externalExeName = externalExeName.replace("%TESTID%", String.valueOf(tCExecution.getTestCase()));608 externalExeName = externalExeName.replace("%TESTDESCRIPTION%", String.valueOf(tCExecution.getDescription()));609 caps.setCapability("name", externalExeName);610 }611 if (tCExecution.getVerbose() >= 2) {612 if (isNotAlreadyDefined(caps, "video")) {613 caps.setCapability("video", true);614 }615 if (isNotAlreadyDefined(caps, "visual")) {616 caps.setCapability("visual", true);617 }618 if (isNotAlreadyDefined(caps, "network")) {619 caps.setCapability("network", true);620 }621 if (isNotAlreadyDefined(caps, "console")) {622 caps.setCapability("console", true);623 }624 }625 break;626 case TestCaseExecution.ROBOTPROVIDER_KOBITON:627 if (isNotAlreadyDefined(caps, "sessionName")) {628 String externalExeName = parameterService.getParameterStringByKey("cerberus_kobiton_defaultsessionname", tCExecution.getSystem(), "%EXEID% : %TEST% - %TESTCASE%");629 externalExeName = externalExeName.replace("%EXEID%", String.valueOf(tCExecution.getId()));630 externalExeName = externalExeName.replace("%APPLI%", String.valueOf(tCExecution.getApplication()));631 externalExeName = externalExeName.replace("%TAG%", String.valueOf(tCExecution.getTag()));632 externalExeName = externalExeName.replace("%TEST%", String.valueOf(tCExecution.getTest()));633 externalExeName = externalExeName.replace("%TESTCASE%", String.valueOf(tCExecution.getTestCase()));634 externalExeName = externalExeName.replace("%TESTCASEDESC%", String.valueOf(tCExecution.getTestCaseObj().getDescription()));635 caps.setCapability("sessionName", externalExeName);636 }637 if (isNotAlreadyDefined(caps, "sessionDescription")) {638 String externalExeName = parameterService.getParameterStringByKey("cerberus_kobiton_defaultsessiondescription", tCExecution.getSystem(), "%TESTCASEDESC%");639 externalExeName = externalExeName.replace("%EXEID%", String.valueOf(tCExecution.getId()));640 externalExeName = externalExeName.replace("%APPLI%", String.valueOf(tCExecution.getApplication()));641 externalExeName = externalExeName.replace("%TAG%", String.valueOf(tCExecution.getTag()));642 externalExeName = externalExeName.replace("%TEST%", String.valueOf(tCExecution.getTest()));643 externalExeName = externalExeName.replace("%TESTCASE%", String.valueOf(tCExecution.getTestCase()));644 externalExeName = externalExeName.replace("%TESTCASEDESC%", String.valueOf(tCExecution.getTestCaseObj().getDescription()));645 caps.setCapability("sessionDescription", externalExeName);646 }647 if (isNotAlreadyDefined(caps, "deviceGroup")) {648 caps.setCapability("deviceGroup", "KOBITON"); // use UIAutomator2 by default649 }650 break;651 case TestCaseExecution.ROBOTPROVIDER_NONE:652 break;653 default:654 }655 return caps;656 }657 private boolean isNotAlreadyDefined(MutableCapabilities caps, String capability) {658 return ((caps.getCapability(capability) == null)659 || ((caps.getCapability(capability) != null)660 && (caps.getCapability(capability).toString().isEmpty())));661 }662 /**663 * Instantiate DesiredCapabilities regarding the browser664 *665 * @param capabilities666 * @param browser667 * @param tCExecution668 * @return669 * @throws CerberusException670 */671 private MutableCapabilities setCapabilityBrowser(MutableCapabilities capabilities, String browser, TestCaseExecution tCExecution) throws CerberusException {672 try {673 // Get User Agent to use.674 String usedUserAgent;675 usedUserAgent = getUserAgentToUse(tCExecution.getTestCaseObj().getUserAgent(), tCExecution.getUserAgent());676 LoggingPreferences logPrefs = new LoggingPreferences();677 logPrefs.enable(LogType.BROWSER, Level.ALL);678 switch (browser) {679 case "firefox":680 FirefoxOptions optionsFF = new FirefoxOptions();681 FirefoxProfile profile = new FirefoxProfile();682 profile.setPreference("app.update.enabled", false);683 // Language684 try {685 Invariant invariant = invariantService.convert(invariantService.readByKey("COUNTRY", tCExecution.getCountry()));686 if (invariant.getGp2() == null) {687 LOG.warn("Country selected ({}) has no value of GP2 in Invariant table, default language set to English (en)", tCExecution.getCountry());688 profile.setPreference("intl.accept_languages", "en");689 } else {690 profile.setPreference("intl.accept_languages", invariant.getGp2());691 }692 } catch (CerberusException ex) {693 LOG.warn("Country selected ({}) not in Invariant table, default language set to English (en)", tCExecution.getCountry());694 profile.setPreference("intl.accept_languages", "en");695 }696 // Force a specific profile for that session (allows reusing cookies and browser preferences).697 if (tCExecution.getRobotObj() != null && !StringUtil.isNullOrEmpty(tCExecution.getRobotObj().getProfileFolder())) {698 optionsFF.addArguments("--profile");699 optionsFF.addArguments(tCExecution.getRobotObj().getProfileFolder());700 }701 // Set UserAgent if testCaseUserAgent or robotUserAgent is defined702 if (!StringUtil.isNullOrEmpty(usedUserAgent)) {703 profile.setPreference("general.useragent.override", usedUserAgent);704 }705 // Verbose level and Headless706 if (tCExecution.getVerbose() <= 0) {707 optionsFF.setHeadless(true);708 }709 // Add the WebDriver proxy capability.710 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {711 Proxy proxy = new Proxy();712 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());713 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());714 proxy.setProxyType(Proxy.ProxyType.MANUAL);715 LOG.debug("Setting Firefox proxy to : {}", proxy);716 optionsFF.setProxy(proxy);717 }718 optionsFF.setProfile(profile);719 // Accept Insecure Certificates.720 optionsFF.setAcceptInsecureCerts(tCExecution.getRobotObj() == null || tCExecution.getRobotObj().isAcceptInsecureCerts());721 // Collect Logs on Selenium side.722 optionsFF.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);723 return optionsFF;724 case "chrome":725 ChromeOptions optionsCH = new ChromeOptions();726 // Maximize windows for chrome browser727 String targetScreensize = getScreenSizeToUse(tCExecution.getTestCaseObj().getScreenSize(), tCExecution.getScreenSize());728 if ((!StringUtil.isNullOrEmpty(targetScreensize)) && targetScreensize.contains("*")) {729 Integer screenWidth = Integer.valueOf(targetScreensize.split("\\*")[0]);730 Integer screenLength = Integer.valueOf(targetScreensize.split("\\*")[1]);731 String sizeOpts = "--window-size=" + screenWidth + "," + screenLength;732 optionsCH.addArguments(sizeOpts);733 LOG.debug("Selenium resolution (for Chrome) Activated : " + screenWidth + "*" + screenLength);734 } else {735 optionsCH.addArguments("start-maximized");736 }737 // Language738 try {739 Invariant invariant = invariantService.convert(invariantService.readByKey("COUNTRY", tCExecution.getCountry()));740 if (invariant.getGp2() == null) {741 LOG.warn("Country selected ({}) has no value of GP2 in Invariant table, default language set to English (en)", tCExecution.getCountry());742 optionsCH.addArguments("--lang=en");743 } else {744 optionsCH.addArguments("--lang=" + invariant.getGp2());745 }746 } catch (CerberusException ex) {747 LOG.warn("Country selected ({}) not in Invariant table, default language set to English (en)", tCExecution.getCountry());748 optionsCH.addArguments("--lang=en");749 }750 // Force a specific profile for that session (allows reusing cookies and browser preferences).751 if (tCExecution.getRobotObj() != null && !StringUtil.isNullOrEmpty(tCExecution.getRobotObj().getProfileFolder())) {752 optionsCH.addArguments("user-data-dir=" + tCExecution.getRobotObj().getProfileFolder());753 }754 // Set UserAgent if necessary755 if (!StringUtil.isNullOrEmpty(usedUserAgent)) {756 optionsCH.addArguments("--user-agent=" + usedUserAgent);757 }758 // Verbose level and Headless759 if (tCExecution.getVerbose() <= 0) {760 optionsCH.addArguments("--headless");761 }762 // Add the WebDriver proxy capability.763 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {764 Proxy proxy = new Proxy();765 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());766 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());767 proxy.setNoProxy("");768 proxy.setProxyType(Proxy.ProxyType.MANUAL);769 LOG.debug("Setting Chrome proxy to : {}", proxy);770 optionsCH.setCapability(DEFAULT_PROXY_HOST, proxy);771 }772 // Accept Insecure Certificates.773 if (tCExecution.getRobotObj() != null && !tCExecution.getRobotObj().isAcceptInsecureCerts()) {774 optionsCH.setAcceptInsecureCerts(false);775 } else {776 optionsCH.setAcceptInsecureCerts(true);777 }778 // Extra Browser Parameters.779 if (tCExecution.getRobotObj() != null && !StringUtil.isNullOrEmpty(tCExecution.getRobotObj().getExtraParam())) {780 optionsCH.addArguments(tCExecution.getRobotObj().getExtraParam());781 }782 // Collect Logs on Selenium side.783 optionsCH.setCapability("goog:loggingPrefs", logPrefs);784 return optionsCH;785 case "safari":786 SafariOptions optionsSA = new SafariOptions();787 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {788 Proxy proxy = new Proxy();789 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());790 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());791 optionsSA.setProxy(proxy);792 }793 return optionsSA;794 case "IE":795 InternetExplorerOptions optionsIE = new InternetExplorerOptions();796 // Add the WebDriver proxy capability.797 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {798 Proxy proxy = new Proxy();799 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());800 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());801 proxy.setProxyType(Proxy.ProxyType.MANUAL);802 LOG.debug("Setting IE proxy to : " + proxy.toString());803 optionsIE.setCapability(DEFAULT_PROXY_HOST, proxy);804 }805 return optionsIE;806 case "edge":807 EdgeOptions optionsED = new EdgeOptions();808 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {809 Proxy proxy = new Proxy();810 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());811 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());812 optionsED.setProxy(proxy);813 }814 return optionsED;815 case "opera":816 OperaOptions optionsOP = new OperaOptions();817 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {818 Proxy proxy = new Proxy();819 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());820 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());821 optionsOP.setProxy(proxy);822 }823 optionsOP.setCapability("browser", "opera");824 // Forcing a profile in order to force UserAgent. This has been commented because it fail when using BrowserStack that does not allow to create the correcponding profile folder.825// if (!StringUtil.isNullOrEmpty(usedUserAgent)) {826// optionsOP.setCapability("opera.profile", "{profileName: \"foo\",userAgent: \"" + usedUserAgent + "\"}");827// }828 return optionsOP;829 case "android":830 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {831 Proxy proxy = new Proxy();832 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());833 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());834 }835 capabilities = DesiredCapabilities.android();836 break;837 case "ipad":838 capabilities = DesiredCapabilities.ipad();839 break;840 case "iphone":841 capabilities = DesiredCapabilities.iphone();842 break;843 case "":844 // We allow to start a Selenium session without any browser defined. This is used to support bundleId capability.845 break;846 // Unfortunatly Yandex is not yet supported on BrowserStack. Once it will be it should look like that:847// case "yandex":848// capabilities = new DesiredCapabilities();849// capabilities.setCapability("browser", "Yandex");850// capabilities.setCapability("browser_version", "14.12");851// break;852 default:853 LOG.warn("Not supported Browser : " + browser);854 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);855 mes.setDescription(mes.getDescription().replace("%MES%", "Browser '" + browser + "' is not supported"));856 mes.setDescription("Not supported Browser : " + browser);857 throw new CerberusException(mes);858 }859 } catch (CerberusException ex) {860 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);861 mes.setDescription(mes.getDescription().replace("%MES%", "Failed to set capability on the browser '" + browser + "' due to " + ex.getMessageError().getDescription()));862 throw new CerberusException(mes);863 }864 return capabilities;865 }866 /**867 * This method determine which user agent to use.868 *869 * @param userAgentTestCase870 * @param userAgentRobot871 * @return String containing the userAgent to use872 */873 private String getUserAgentToUse(String userAgentTestCase, String userAgentRobot) {874 if (StringUtil.isNullOrEmpty(userAgentRobot) && StringUtil.isNullOrEmpty(userAgentTestCase)) {875 return "";876 } else {877 return StringUtil.isNullOrEmpty(userAgentTestCase) ? userAgentRobot : userAgentTestCase;878 }879 }880 /**881 * This method determine which screenSize to use.882 *883 * @param screenSizeTestCase884 * @param screenSizeRobot885 * @return String containing the screensize to use886 */887 private String getScreenSizeToUse(String screenSizeTestCase, String screenSizeRobot) {888 if (StringUtil.isNullOrEmpty(screenSizeRobot) && StringUtil.isNullOrEmpty(screenSizeTestCase)) {889 return "";890 } else {891 return StringUtil.isNullOrEmpty(screenSizeTestCase) ? screenSizeRobot : screenSizeTestCase;892 }893 }894 @Override895 public boolean stopServer(TestCaseExecution tce) {896 Session session = tce.getSession();897 if (session != null && session.isStarted()) {898 try {899 // Wait 2 sec till HAR is exported900 Thread.sleep(2000);901 } catch (InterruptedException ex) {902 LOG.error(ex.toString(), ex);903 }904 // We remove manually the package if it is defined.905 if (session.getAppiumDriver() != null && tce.getCountryEnvironmentParameters() != null906 && !StringUtil.isNullOrEmpty(tce.getCountryEnvironmentParameters().getMobilePackage())) {907 session.getAppiumDriver().removeApp(tce.getCountryEnvironmentParameters().getMobilePackage());908 }909 // We lock device if deviceLockUnlock is active.910 if (tce.getRobotExecutorObj() != null && session.getAppiumDriver() != null && session.getAppiumDriver() instanceof LocksDevice911 && "Y".equals(tce.getRobotExecutorObj().getDeviceLockUnlock())) {912 ((LocksDevice) session.getAppiumDriver()).lockDevice();913 }914 // We record Selenium log at the end of the execution.915 switch (tce.getRobotProvider()) {916 case TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK:917 case TestCaseExecution.ROBOTPROVIDER_NONE:918 try {919 tce.addFileList(recorderService.recordSeleniumLog(tce));920 } catch (Exception ex) {921 LOG.error("Exception Getting Selenium Logs {}", tce.getId(), ex);922 }923 break;924 default:925 }926 // We record Console log at the end of the execution.927 switch (tce.getRobotProvider()) {928 case TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK:929 case TestCaseExecution.ROBOTPROVIDER_NONE:930 try {931 tce.addFileList(recorderService.recordConsoleLog(tce));932 } catch (Exception ex) {933 LOG.error("Exception Getting Console Logs " + tce.getId(), ex);934 }935 break;936 default:937 }938 // We record Har log at the end of the execution.939 switch (tce.getRobotProvider()) {940 case TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK:941// try {942// String url = "http://api.bs.com/getHar?uuid=" + tce.getRobotSessionID();943// tce.addFileList(recorderService.recordBrowserstackHarLog(tce, url));944// } catch (Exception ex) {945// LOG.error("Exception Getting Browserstack HAR File " + tce.getId(), ex);946// }947 break;948 case TestCaseExecution.ROBOTPROVIDER_NONE:949 break;950 default:951 }952 try {953 // Get Har File when Cerberus Executor is activated.954 // If proxy started and parameter verbose >= 1 activated955 if ("Y".equals(tce.getRobotExecutorObj().getExecutorProxyActive())956 && tce.getVerbose() >= 1 && (parameterService.getParameterBooleanByKey("cerberus_networkstatsave_active", tce.getSystem(), false))) {957 // Before collecting the stats, we wait the network idles for few minutes958 executorService.waitForIdleNetwork(tce.getRobotExecutorObj().getExecutorExtensionHost(), tce.getRobotExecutorObj().getExecutorExtensionPort(), tce.getRemoteProxyUUID(), tce.getSystem());959 // We now get the har data.960 JSONObject har = executorService.getHar(null, false, tce.getRobotExecutorObj().getExecutorExtensionHost(), tce.getRobotExecutorObj().getExecutorExtensionPort(), tce.getRemoteProxyUUID(), tce.getSystem(), 0);961 // and enrich it with stat entry.962 har = harService.enrichWithStats(har, tce.getCountryEnvironmentParameters().getDomain(), tce.getSystem(), tce.getNetworkTrafficIndexList());963 // We convert the har to database record HttpStat and save it to database.964 try {965 AnswerItem<TestCaseExecutionHttpStat> answHttpStat = testCaseExecutionHttpStatService.convertFromHarWithStat(tce, har);966 tce.setHttpStat(answHttpStat.getItem());967 testCaseExecutionHttpStatService.create(answHttpStat.getItem());968 } catch (Exception ex) {969 LOG.warn("Exception collecting and saving stats for execution {} Exception : {}", tce.getId(), ex.toString());970 }971 }972 } catch (Exception ex) {973 LOG.error("Exception Getting Har File from Cerberus Executor {}", tce.getId(), ex);974 }975 // We Stop the Robot Session (Selenium or Appium).976 LOG.info("Stop execution robot session");977 if (tce.getRobotProvider().equals(TestCaseExecution.ROBOTPROVIDER_KOBITON)) {978 // For Kobiton, we should first close Appium session.979 if (session.getAppiumDriver() != null) {980 session.getAppiumDriver().close();981 }982 if (session.getDriver() != null) {983 session.getDriver().quit();984 }985 } else {986 session.quit();987 }988 return true;989 }990 return false;991 }992 private static void getIPOfNode(TestCaseExecution tCExecution) {993 try {994 Session session = tCExecution.getSession();995 HttpCommandExecutor ce = (HttpCommandExecutor) ((RemoteWebDriver) session.getDriver()).getCommandExecutor();996 SessionId sessionId = ((RemoteWebDriver) session.getDriver()).getSessionId();997 String hostName = ce.getAddressOfRemoteServer().getHost();998 int port = ce.getAddressOfRemoteServer().getPort();999 HttpHost host = new HttpHost(hostName, port);1000 HttpClient client = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();1001 URL sessionURL = new URL(RobotServerService.getBaseUrl(session.getHost(), session.getPort()) + "/grid/api/testsession?session=" + sessionId);1002 BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("GET", sessionURL.toExternalForm());1003 LOG.debug("Calling Hub to get the node information. {}", sessionURL);1004 HttpResponse response = client.execute(host, r);1005 if (!response.getStatusLine().toString().contains("403")1006 && !response.getEntity().getContentType().getValue().contains("text/html")) {1007 InputStream contents = response.getEntity().getContent();1008 StringWriter writer = new StringWriter();1009 IOUtils.copy(contents, writer, "UTF8");1010 JSONObject object = new JSONObject(writer.toString());1011 if (object.has("proxyId")) {1012 URL myURL = new URL(object.getString("proxyId"));1013 if ((myURL.getHost() != null) && (myURL.getPort() != -1)) {1014 LOG.debug("Get remote node information : {} - {}", myURL.getHost(), myURL.getPort());1015 tCExecution.setRobotHost(myURL.getHost());1016 tCExecution.setRobotPort(String.valueOf(myURL.getPort()));1017 // Node information at session level is now overwrite with real values.1018 tCExecution.getSession().setNodeHost(myURL.getHost());1019 tCExecution.getSession().setNodePort(String.valueOf(myURL.getPort()));1020 }1021 } else {1022 LOG.debug("'proxyId' json data not available from remote Selenium Server request : {}", writer);1023 }1024 }1025 } catch (IOException | JSONException ex) {1026 LOG.error(ex.toString(), ex);1027 }1028 }1029 @Override1030 public Capabilities getUsedCapabilities(Session session) {1031 return ((HasCapabilities) session.getDriver()).getCapabilities();1032 }1033 private void setScreenSize(WebDriver driver, Integer width, Integer length) {1034 driver.manage().window().setPosition(new Point(0, 0));1035 driver.manage().window().setSize(new Dimension(width, length));1036 }1037 private String getScreenSize(WebDriver driver) {1038 return driver.manage().window().getSize().width + "*" + driver.manage().window().getSize().height;1039 }1040 private static String getBaseUrl(String host, String port) {1041 String baseurl = "";1042 if (!StringUtil.isNullOrEmpty(host) && (host.contains("https://") || host.contains("http://"))) {1043 baseurl = host;1044 } else {1045 baseurl = "http://" + host;1046 }1047 if (!StringUtil.isNullOrEmpty(port) && Integer.valueOf(port) > 0) {1048 baseurl += ":" + port;1049 }1050 return baseurl;1051 }1052 @Override1053 public HashMap<String, String> getMapFromOptions(JSONArray options) {1054 HashMap<String, String> result = new HashMap<>();1055 if (options.length() > 0) {1056 LOG.debug("Converting {} To Map.", options);1057 for (int i = 0; i < options.length(); i++) {1058 try {1059 JSONObject option = options.getJSONObject(i);1060 if (option.getBoolean("act")) {1061 result.put(option.getString("option"), option.getString("value"));1062 }1063 } catch (JSONException ex) {1064 LOG.error(ex, ex);1065 return result;1066 }1067 }1068 }1069 return result;1070 }1071 @Override1072 public void setOptionsTimeout(Session session, Integer timeout) {1073 if (session != null) {1074 LOG.debug("Setting Robot Options timeout to : {}", timeout);1075 session.setCerberus_selenium_wait_element(timeout);1076 session.setCerberus_appium_wait_element(timeout);1077 session.setCerberus_sikuli_wait_element(timeout);1078 }1079 }1080 @Override1081 public void setOptionsHighlightElement(Session session, Integer highlightElement) {1082 if (session != null) {1083 LOG.debug("Setting Robot Option highlightElement to : {}", highlightElement);1084 session.setCerberus_selenium_highlightElement(highlightElement);1085 session.setCerberus_sikuli_highlightElement(highlightElement);1086 }1087 }1088 @Override1089 public void setOptionsMinSimilarity(Session session, String minSimilarity) {1090 if (session != null) {1091 LOG.debug("Setting Robot Option minSimilarity to : {}", minSimilarity);1092 session.setCerberus_sikuli_minSimilarity(minSimilarity);1093 }1094 }1095 @Override1096 public void setOptionsToDefault(Session session) {1097 if (session != null) {1098 LOG.debug("Setting Robot Timeout back to default values : Selenium {} Appium {} Sikuli {}",1099 session.getCerberus_selenium_wait_element_default(),1100 session.getCerberus_appium_wait_element_default(),1101 session.getCerberus_sikuli_wait_element_default());1102 session.setCerberus_selenium_wait_element(session.getCerberus_selenium_wait_element_default());1103 session.setCerberus_appium_wait_element(session.getCerberus_appium_wait_element_default());1104 session.setCerberus_sikuli_wait_element(session.getCerberus_sikuli_wait_element_default());1105 LOG.debug("Setting Robot highlightElement back to default values : Selenium {} Sikuli {}",1106 session.getCerberus_selenium_highlightElement_default(),1107 session.getCerberus_sikuli_highlightElement_default());1108 session.setCerberus_selenium_highlightElement(session.getCerberus_selenium_highlightElement_default());1109 session.setCerberus_sikuli_highlightElement(session.getCerberus_sikuli_highlightElement_default());1110 LOG.debug("Setting Robot minSimilarity back to default values : {}", session.getCerberus_sikuli_minSimilarity_default());1111 session.setCerberus_sikuli_minSimilarity(session.getCerberus_sikuli_minSimilarity_default());1112 }1113 }1114}...

Full Screen

Full Screen

Source:Session.java Github

copy

Full Screen

...156 }157 public Integer getCerberus_sikuli_wait_element_default() {158 return cerberus_sikuli_wait_element_default;159 }160 public void setCerberus_sikuli_wait_element_default(Integer cerberus_sikuli_wait_element_default) {161 this.cerberus_sikuli_wait_element_default = cerberus_sikuli_wait_element_default;162 }163 public Integer getCerberus_sikuli_wait_element() {164 return cerberus_sikuli_wait_element;165 }166 public void setCerberus_sikuli_wait_element(Integer cerberus_sikuli_wait_element) {167 this.cerberus_sikuli_wait_element = cerberus_sikuli_wait_element;168 }169 public Integer getCerberus_selenium_wait_element_default() {170 return cerberus_selenium_wait_element_default;171 }172 public void setCerberus_selenium_wait_element_default(Integer cerberus_selenium_wait_element_default) {173 this.cerberus_selenium_wait_element_default = cerberus_selenium_wait_element_default;174 }175 public Integer getCerberus_selenium_wait_element() {176 return cerberus_selenium_wait_element;177 }178 public void setCerberus_selenium_wait_element(Integer cerberus_selenium_wait_element) {179 this.cerberus_selenium_wait_element = cerberus_selenium_wait_element;180 }...

Full Screen

Full Screen

setCerberus_sikuli_wait_element

Using AI Code Generation

copy

Full Screen

1package org.cerberus.engine.entity;2import org.cerberus.engine.entity.Session;3public class TestSetCerberus_sikuli_wait_element {4 public static void main(String[] args) {5 Session session = new Session();6 session.setCerberus_sikuli_wait_element(10);7 System.out.println("Cerberus_sikuli_wait_element is : " + session.getCerberus_sikuli_wait_element());8 }9}

Full Screen

Full Screen

setCerberus_sikuli_wait_element

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.entity.Session;2import org.cerberus.engine.entity.Testcase;3import org.cerberus.engine.entity.TestcaseExecution;4public class 3 {5 public static void main(String[] args) {6 Session session = new Session();7 TestcaseExecution testcaseExecution = new TestcaseExecution();8 session.setCerberus_sikuli_wait_element(10);9 }10}11import org.cerberus.engine.entity.Session;12import org.cerberus.engine.entity.Testcase;13import org.cerberus.engine.entity.TestcaseExecution;14public class 4 {15 public static void main(String[] args) {16 Session session = new Session();17 TestcaseExecution testcaseExecution = new TestcaseExecution();18 session.setCerberus_sikuli_wait_element(10);19 }20}21import org.cerberus.engine.entity.Session;22import org.cerberus.engine.entity.Testcase;23import org.cerberus.engine.entity.TestcaseExecution;24public class 5 {25 public static void main(String[] args) {26 Session session = new Session();27 TestcaseExecution testcaseExecution = new TestcaseExecution();28 session.setCerberus_sikuli_wait_element(10);29 }30}31import org.cerberus.engine.entity.Session;32import org.cerberus.engine.entity.Testcase;33import org.cerberus.engine.entity.TestcaseExecution;34public class 6 {35 public static void main(String[] args) {36 Session session = new Session();37 TestcaseExecution testcaseExecution = new TestcaseExecution();38 session.setCerberus_sikuli_wait_element(10);39 }40}

Full Screen

Full Screen

setCerberus_sikuli_wait_element

Using AI Code Generation

copy

Full Screen

1package org.cerberus.engine.entity;2import org.cerberus.engine.entity.Session;3import org.sikuli.script.App;4import org.sikuli.script.FindFailed;5import org.sikuli.script.Screen;6public class 3 {7 public static void main(String[] args) throws FindFailed {8 Screen s = new Screen();9 Session session = new Session();10 App app = new App("C:\\Program Files\\Mozilla Firefox\\firefox.exe");11 app.open();12 s.wait("C:\\Users\\Public\\Pictures\\Sample Pictures\\Penguins.jpg", 2);13 s.click("C:\\Users\\Public\\Pictures\\Sample Pictures\\Penguins.jpg");14 s.wait("C:\\Users\\Public\\Pictures\\Sample Pictures\\Tulips.jpg", 2);15 s.click("C:\\Users\\Public\\Pictures\\Sample Pictures\\Tulips.jpg");16 s.wait("C:\\Users\\Public\\Pictures\\Sample Pictures\\Jellyfish.jpg", 2);17 s.click("C:\\Users\\Public\\Pictures\\Sample Pictures\\Jellyfish.jpg");18 s.wait("C:\\Users\\Public\\Pictures\\Sample Pictures\\Hydrangeas.jpg", 2);19 s.click("C:\\Users\\Public\\Pictures\\Sample Pictures\\Hydrangeas.jpg");20 session.setCerberus_sikuli_wait_element(10);21 System.out.println(session.getCerberus_sikuli_wait_element());22 }23}24package org.cerberus.engine.entity;25import org.cerberus.engine.entity.Session;26import org.sikuli.script.App;27import org.sikuli.script.FindFailed;28import org.sikuli.script.Screen;29public class 4 {30 public static void main(String[] args) throws FindFailed {

Full Screen

Full Screen

setCerberus_sikuli_wait_element

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.entity.Session;2public class 3 {3 public static void main(String[] args) {4 Session session = new Session();5 session.setCerberus_sikuli_wait_element(5);6 }7}

Full Screen

Full Screen

setCerberus_sikuli_wait_element

Using AI Code Generation

copy

Full Screen

1package org.cerberus;2import org.cerberus.engine.entity.Session;3import org.sikuli.script.FindFailed;4import org.sikuli.script.Pattern;5import org.sikuli.script.Screen;6public class 3 {7 public static void main(String[] args) throws FindFailed {8 Session session = new Session();9 session.setCerberus_sikuli_wait_element(20);10 Screen screen = new Screen();11 Pattern pattern = new Pattern("C:\\Users\\Dell\\Desktop\\cerberus\\cerberus\\cerberus\\org\\cerberus\\images\\calculator.png");12 screen.wait(pattern, 0);13 screen.click(pattern);14 screen.type("2+3");15 Pattern pattern1 = new Pattern("C:\\Users\\Dell\\Desktop\\cerberus\\cerberus\\cerberus\\org\\cerberus\\images\\equals.png");16 screen.wait(pattern1, 0);17 screen.click(pattern1);18 }19}

Full Screen

Full Screen

setCerberus_sikuli_wait_element

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.entity.Session;2import org.cerberus.engine.entity.WaitElement;3import org.sikuli.script.FindFailed;4import org.sikuli.script.Key;5import org.sikuli.script.Match;6import org.sikuli.script.Pattern;7import org.sikuli.script.Region;8import org.sikuli.script.Screen;9public class 3 {10 public static void main(String[] args) throws FindFailed, InterruptedException {11 Screen s = new Screen();12 Match m;13 Pattern p;14 Region r;15 WaitElement we;16 we = new WaitElement();17 we.setWaitElement(new Pattern("wait_element.png"));18 we.setWaitElementTimeout(10);19 Session.setCerberus_sikuli_wait_element(we);20 p = new Pattern("google.png");21 m = s.find(p);22 m.click();23 s.type("cerberus");24 s.type(Key.ENTER);25 Session.setCerberus_sikuli_wait_element(null);26 }27}28import org.cerberus.engine.entity.Session;29import org.cerberus.engine.entity.WaitElement;30import org.sikuli.script.FindFailed;31import org.sikuli.script.Key;32import org.sikuli.script.Match;33import org.sikuli.script.Pattern;34import

Full Screen

Full Screen

setCerberus_sikuli_wait_element

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.entity.Session;2import org.cerberus.engine.entity.TestCase;3import org.cerberus.engine.entity.TestData;4import org.cerberus.engine.entity.TestStep;5import org.cerberus.engine.entity.TestSuite;6import org.cerberus.engine.entity.TestStep.StepType;7import org.cerberus.engine.entity.TestSuite.ExecutionMode;8import org.cerberus.engine.entity.TestSuite.ExecutionStatus;9import org.cerberus.engine.entity.TestSuite.ExecutionType;10import org.cerberus.engine.entity.TestSuite.TestSuiteType;11import org.cerberus.engine.entity.TestStep.StepStatus;12import org.cerberus.engine.entity.TestSuite.TestSuiteStatus;13import org.cerberus.engine.entity.TestStep.StepExecutionMode;14import org.cerberus.engine.entity.TestStep.StepExecutionType;15import org.cerberus.engine.entity.TestStep.StepType;16import org.cerberus.engine.entity.TestStep.StepVerificationMode;17import org.cerberus.engine.entity.TestStep.StepVerificationType;18import org.cerberus.engine.entity.TestStep.StepVerificationStatus;19import org.cerberus.engine.entity.TestStep.StepExecutionStatus;20import org.cerberus.engine.entity.TestStep.StepExecutionSubStatus;21import org.cerberus.engine.entity.TestStep.StepVerificationSubStatus;22import org.cerberus.engine.entity.TestData.TestDataStatus;23import org.cerberus.engine.entity.TestData.TestDataType;24import org.cerberus.engine.entity.TestData.TestDataValueType;25import org.cerberus.engine.entity.TestData.TestDataVerificationStatus;26import org.cerberus.engine.entity.TestData.TestDataVerificationType;27import org.cerberus.engine.entity.TestData.TestDataVerificationSubStatus;28import org.cerberus.engine.entity.TestData.TestDataExecutionStatus;29import org.cerberus.engine.entity.TestData.TestDataExecutionSubStatus;30import org.cerberus.engine.entity.TestData.TestDataExecutionType;31import org.cerberus.engine.entity.TestData.TestDataExecutionMode;32import org.cerberus.engine.entity.TestData.TestDataExecutionSubStatus;33import org.cerberus.engine.entity.TestData.TestDataExecutionSubStatus;34import org

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Session

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful