How to use getScreenSize method of org.cerberus.crud.entity.TestCaseExecution class

Best Cerberus-source code snippet using org.cerberus.crud.entity.TestCaseExecution.getScreenSize

Source:RobotServerService.java Github

copy

Full Screen

...385 getIPOfNode(tCExecution);386 /**387 * If screenSize is defined, set the size of the screen.388 */389 String targetScreensize = getScreenSizeToUse(tCExecution.getTestCaseObj().getScreenSize(), tCExecution.getScreenSize());390 LOG.debug("Selenium resolution : " + targetScreensize);391 if (!tCExecution.getBrowser().equalsIgnoreCase(BrowserType.CHROME)) {392 // For chrome the resolution has already been defined at capabilities level.393 if ((!StringUtil.isNullOrEmpty(targetScreensize)) && targetScreensize.contains("*")) {394 Integer screenWidth = Integer.valueOf(targetScreensize.split("\\*")[0]);395 Integer screenLength = Integer.valueOf(targetScreensize.split("\\*")[1]);396 setScreenSize(driver, screenWidth, screenLength);397 LOG.debug("Selenium resolution Activated : " + screenWidth + "*" + screenLength);398 }399 }400 tCExecution.setScreenSize(getScreenSize(driver));401 tCExecution.setRobotDecli(tCExecution.getRobotDecli().replace("%SCREENSIZE%", tCExecution.getScreenSize()));402 String userAgent = (String) ((JavascriptExecutor) driver).executeScript("return navigator.userAgent;");403 tCExecution.setUserAgent(userAgent);404 }405 // unlock device if deviceLockUnlock is active406 if (tCExecution.getRobotExecutorObj() != null && appiumDriver != null && appiumDriver instanceof LocksDevice407 && "Y".equals(tCExecution.getRobotExecutorObj().getDeviceLockUnlock())) {408 ((LocksDevice) appiumDriver).unlockDevice();409 }410 tCExecution.getSession().setStarted(true);411 } catch (CerberusException exception) {412 LOG.error(exception.toString(), exception);413 throw new CerberusException(exception.getMessageError(), exception);414 } catch (MalformedURLException exception) {415 LOG.error(exception.toString(), exception);416 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_URL_MALFORMED);417 mes.setDescription(mes.getDescription().replace("%URL%", tCExecution.getSession().getHost() + ":" + tCExecution.getSession().getPort()));418 throw new CerberusException(mes, exception);419 } catch (UnreachableBrowserException exception) {420 LOG.warn("Could not connect to : " + tCExecution.getSeleniumIP() + ":" + tCExecution.getSeleniumPort());421// LOG.error("UnreachableBrowserException catched.", exception);422 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_SELENIUM_COULDNOTCONNECT);423 mes.setDescription(mes.getDescription().replace("%SSIP%", tCExecution.getSeleniumIP()));424 mes.setDescription(mes.getDescription().replace("%SSPORT%", tCExecution.getSeleniumPort()));425 mes.setDescription(mes.getDescription().replace("%ERROR%", exception.toString()));426 throw new CerberusException(mes, exception);427 } catch (Exception exception) {428 LOG.error(exception.toString(), exception);429 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);430 mes.setDescription(mes.getDescription().replace("%MES%", exception.toString()));431 this.stopRemoteProxy(tCExecution);432 throw new CerberusException(mes, exception);433 } finally {434 executionThreadPoolService.executeNextInQueueAsynchroneously(false);435 }436 }437 private String getSession(WebDriver driver, String robotProvider) {438 String session = "";439 switch (robotProvider) {440 case TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK:441 session = ((RemoteWebDriver) driver).getSessionId().toString();442 break;443 case TestCaseExecution.ROBOTPROVIDER_KOBITON:444 session = ((RemoteWebDriver) driver).getCapabilities().getCapability("kobitonSessionId").toString();445 break;446 case TestCaseExecution.ROBOTPROVIDER_NONE:447 session = ((RemoteWebDriver) driver).getSessionId().toString();448 break;449 default:450 }451 return session;452 }453 private String guessRobotProvider(String host) {454 if (host.contains("browserstack")) {455 return TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK;456 }457 if (host.contains("kobiton")) {458 return TestCaseExecution.ROBOTPROVIDER_KOBITON;459 }460 return TestCaseExecution.ROBOTPROVIDER_NONE;461 }462 /**463 * Set DesiredCapabilities464 *465 * @param tCExecution466 * @return467 * @throws CerberusException468 */469 private MutableCapabilities setCapabilities(TestCaseExecution tCExecution) throws CerberusException {470 /**471 * Instanciate DesiredCapabilities472 */473 MutableCapabilities caps = new MutableCapabilities();474 // In case browser is not defined at that level, we force it to firefox.475 if (StringUtil.isNullOrEmpty(tCExecution.getBrowser())) {476 tCExecution.setBrowser("firefox");477 }478 /**479 * Set Browser Capabilities480 */481 caps = this.setCapabilityBrowser(caps, tCExecution.getBrowser(), tCExecution);482 /**483 * Loop on RobotCapabilities to feed DesiredCapabilities Capability must484 * be String, Integer or Boolean485 */486 List<RobotCapability> additionalCapabilities = new ArrayList<>();487 if (tCExecution.getRobotObj() != null) {488 additionalCapabilities = tCExecution.getRobotObj().getCapabilitiesDecoded();489 }490 if (additionalCapabilities != null) {491 for (RobotCapability additionalCapability : additionalCapabilities) {492 LOG.debug("RobotCaps on Robot : " + additionalCapability.getRobot() + " caps : " + additionalCapability.getCapability() + " Value : " + additionalCapability.getValue());493 if ((caps.getCapability(additionalCapability.getCapability()) == null)494 || ((caps.getCapability(additionalCapability.getCapability()) != null) && (caps.getCapability(additionalCapability.getCapability()).toString().equals("")))) { // caps does not already exist so we can set it.495 if (StringUtil.isBoolean(additionalCapability.getValue())) {496 caps.setCapability(additionalCapability.getCapability(), StringUtil.parseBoolean(additionalCapability.getValue()));497 } else if (StringUtil.isInteger(additionalCapability.getValue())) {498 caps.setCapability(additionalCapability.getCapability(), Integer.valueOf(additionalCapability.getValue()));499 } else {500 caps.setCapability(additionalCapability.getCapability(), additionalCapability.getValue());501 }502 }503 }504 } else {505 additionalCapabilities = new ArrayList<>();506 }507 /**508 * Feed DesiredCapabilities with values get from Robot509 */510 if (!StringUtil.isNullOrEmpty(tCExecution.getPlatform())) {511 if ((caps.getCapability("platform") == null)512 || ((caps.getCapability("platform") != null) && (caps.getCapability("platform").toString().equals("ANY") || caps.getCapability("platform").toString().equals("")))) {513 caps.setCapability("platformName", tCExecution.getPlatform());514 }515 }516 if (!StringUtil.isNullOrEmpty(tCExecution.getVersion())) {517 if ((caps.getCapability("version") == null)518 || ((caps.getCapability("version") != null) && (caps.getCapability("version").toString().equals("")))) {519 caps.setCapability("version", tCExecution.getVersion());520 }521 }522 if (tCExecution.getRobotExecutorObj() != null) {523 // Setting deviceUdid and device name from executor.524 if (!StringUtil.isNullOrEmpty(tCExecution.getRobotExecutorObj().getDeviceUuid())) {525 if ((caps.getCapability("udid") == null)526 || ((caps.getCapability("udid") != null) && (caps.getCapability("udid").toString().equals("")))) {527 caps.setCapability("udid", tCExecution.getRobotExecutorObj().getDeviceUuid());528 }529 }530 if (!StringUtil.isNullOrEmpty(tCExecution.getRobotExecutorObj().getDeviceName())) {531 if ((caps.getCapability("deviceName") == null)532 || ((caps.getCapability("deviceName") != null) && (caps.getCapability("deviceName").toString().equals("")))) {533 caps.setCapability("deviceName", tCExecution.getRobotExecutorObj().getDeviceName());534 }535 }536 if (!StringUtil.isNullOrEmpty(tCExecution.getRobotExecutorObj().getDeviceName())) {537 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {538 if ((caps.getCapability("systemPort") == null)539 || ((caps.getCapability("systemPort") != null) && (caps.getCapability("systemPort").toString().equals("")))) {540 caps.setCapability("systemPort", tCExecution.getRobotExecutorObj().getDevicePort());541 }542 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {543 if ((caps.getCapability("wdaLocalPort") == null)544 || ((caps.getCapability("wdaLocalPort") != null) && (caps.getCapability("wdaLocalPort").toString().equals("")))) {545 caps.setCapability("wdaLocalPort", tCExecution.getRobotExecutorObj().getDevicePort());546 }547 }548 }549 }550 /**551 * if application is a mobile one, then set the "app" capability to the552 * application binary path553 */554 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)555 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {556 // Set the app capability with the application path557 if (!StringUtil.isNullOrEmpty(tCExecution.getMyHost())) {558 if (isNotAlreadyDefined(caps, "app")) {559 caps.setCapability("app", tCExecution.getMyHost());560 }561 } else {562 if (isNotAlreadyDefined(caps, "app")) {563 caps.setCapability("app", tCExecution.getCountryEnvironmentParameters().getIp());564 }565 }566 if (!StringUtil.isNullOrEmpty(tCExecution.getCountryEnvironmentParameters().getMobileActivity()) && tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {567 if (isNotAlreadyDefined(caps, "appWaitActivity")) {568 caps.setCapability("appWaitActivity", tCExecution.getCountryEnvironmentParameters().getMobileActivity());569 }570 }571 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {572 if (isNotAlreadyDefined(caps, "automationName")) {573 caps.setCapability("automationName", "UIAutomator2"); // use UIAutomator2 by default574 }575 }576 }577 /**578 * We record Selenium log at the end of the execution.579 */580 switch (tCExecution.getRobotProvider()) {581 case TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK:582 if (!StringUtil.isNullOrEmpty(tCExecution.getTag()) && isNotAlreadyDefined(caps, "build")) {583 caps.setCapability("build", tCExecution.getTag()); // use UIAutomator2 by default584 }585 if (isNotAlreadyDefined(caps, "project")) {586 caps.setCapability("project", tCExecution.getApplication());587 }588 if (isNotAlreadyDefined(caps, "name")) {589 String externalExeName = parameterService.getParameterStringByKey("cerberus_browserstack_defaultexename", tCExecution.getSystem(), "Exe : %EXEID%");590 externalExeName = externalExeName.replace("%EXEID%", String.valueOf(tCExecution.getId()));591 caps.setCapability("name", externalExeName);592 }593 if (tCExecution.getVerbose() >= 2) {594 if (isNotAlreadyDefined(caps, "browserstack.debug")) {595 caps.setCapability("browserstack.debug", true);596 }597 if (isNotAlreadyDefined(caps, "browserstack.console")) {598 caps.setCapability("browserstack.console", "warnings");599 }600 if (isNotAlreadyDefined(caps, "browserstack.networkLogs")) {601 caps.setCapability("browserstack.networkLogs", true);602 }603 }604 break;605 case TestCaseExecution.ROBOTPROVIDER_KOBITON:606 if (isNotAlreadyDefined(caps, "sessionName")) {607 String externalExeName = parameterService.getParameterStringByKey("cerberus_kobiton_defaultsessionname", tCExecution.getSystem(), "%EXEID% : %TEST% - %TESTCASE%");608 externalExeName = externalExeName.replace("%EXEID%", String.valueOf(tCExecution.getId()));609 externalExeName = externalExeName.replace("%APPLI%", String.valueOf(tCExecution.getApplication()));610 externalExeName = externalExeName.replace("%TAG%", String.valueOf(tCExecution.getTag()));611 externalExeName = externalExeName.replace("%TEST%", String.valueOf(tCExecution.getTest()));612 externalExeName = externalExeName.replace("%TESTCASE%", String.valueOf(tCExecution.getTestCase()));613 externalExeName = externalExeName.replace("%TESTCASEDESC%", String.valueOf(tCExecution.getTestCaseObj().getDescription()));614 caps.setCapability("sessionName", externalExeName);615 }616 if (isNotAlreadyDefined(caps, "sessionDescription")) {617 String externalExeName = parameterService.getParameterStringByKey("cerberus_kobiton_defaultsessiondescription", tCExecution.getSystem(), "%TESTCASEDESC%");618 externalExeName = externalExeName.replace("%EXEID%", String.valueOf(tCExecution.getId()));619 externalExeName = externalExeName.replace("%APPLI%", String.valueOf(tCExecution.getApplication()));620 externalExeName = externalExeName.replace("%TAG%", String.valueOf(tCExecution.getTag()));621 externalExeName = externalExeName.replace("%TEST%", String.valueOf(tCExecution.getTest()));622 externalExeName = externalExeName.replace("%TESTCASE%", String.valueOf(tCExecution.getTestCase()));623 externalExeName = externalExeName.replace("%TESTCASEDESC%", String.valueOf(tCExecution.getTestCaseObj().getDescription()));624 caps.setCapability("sessionDescription", externalExeName);625 }626 if (isNotAlreadyDefined(caps, "deviceGroup")) {627 caps.setCapability("deviceGroup", "KOBITON"); // use UIAutomator2 by default628 }629 break;630 case TestCaseExecution.ROBOTPROVIDER_NONE:631 break;632 default:633 }634 return caps;635 }636 private boolean isNotAlreadyDefined(MutableCapabilities caps, String capability) {637 return ((caps.getCapability(capability) == null)638 || ((caps.getCapability(capability) != null) && (caps.getCapability(capability).toString().equals(""))));639 }640 /**641 * Instanciate DesiredCapabilities regarding the browser642 *643 * @param capabilities644 * @param browser645 * @param tCExecution646 * @return647 * @throws CerberusException648 */649 private MutableCapabilities setCapabilityBrowser(MutableCapabilities capabilities, String browser, TestCaseExecution tCExecution) throws CerberusException {650 try {651 if (browser.equalsIgnoreCase("firefox")) {652 FirefoxOptions options = new FirefoxOptions();653// capabilities = DesiredCapabilities.firefox();654 FirefoxProfile profile = new FirefoxProfile();655 profile.setPreference("app.update.enabled", false);656 try {657 Invariant invariant = invariantService.convert(invariantService.readByKey("COUNTRY", tCExecution.getCountry()));658 if (invariant.getGp2() == null) {659 LOG.warn("Country selected (" + tCExecution.getCountry() + ") has no value of GP2 in Invariant table, default language set to English (en)");660 profile.setPreference("intl.accept_languages", "en");661 } else {662 profile.setPreference("intl.accept_languages", invariant.getGp2());663 }664 } catch (CerberusException ex) {665 LOG.warn("Country selected (" + tCExecution.getCountry() + ") not in Invariant table, default language set to English (en)");666 profile.setPreference("intl.accept_languages", "en");667 }668 // Set UserAgent if testCaseUserAgent or robotUserAgent is defined669 String usedUserAgent = getUserAgentToUse(tCExecution.getTestCaseObj().getUserAgent(), tCExecution.getUserAgent());670 if (!StringUtil.isNullOrEmpty(usedUserAgent)) {671 profile.setPreference("general.useragent.override", usedUserAgent);672 }673// capabilities.setCapability(FirefoxDriver.PROFILE, profile);674 if (tCExecution.getVerbose() <= 0) {675 options.setHeadless(true);676 }677 // Add the WebDriver proxy capability.678 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {679 Proxy proxy = new Proxy();680 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());681 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());682 options.setProxy(proxy);683 }684 options.setProfile(profile);685 return options;686// capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);687 } else if (browser.equalsIgnoreCase("IE")) {688 InternetExplorerOptions options = new InternetExplorerOptions();689 // Add the WebDriver proxy capability.690 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {691 Proxy proxy = new Proxy();692 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());693 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());694 options.setCapability("proxy", proxy);695 }696 return options;697// capabilities = DesiredCapabilities.internetExplorer();698 } else if (browser.equalsIgnoreCase("chrome")) {699 /**700 * Add custom capabilities701 */702 ChromeOptions options = new ChromeOptions();703// capabilities = DesiredCapabilities.chrome();704 // Maximize windows for chrome browser705 String targetScreensize = getScreenSizeToUse(tCExecution.getTestCaseObj().getScreenSize(), tCExecution.getScreenSize());706 if ((!StringUtil.isNullOrEmpty(targetScreensize)) && targetScreensize.contains("*")) {707 Integer screenWidth = Integer.valueOf(targetScreensize.split("\\*")[0]);708 Integer screenLength = Integer.valueOf(targetScreensize.split("\\*")[1]);709 String sizeOpts = "--window-size=" + screenWidth + "," + screenLength;710 options.addArguments(sizeOpts);711 LOG.debug("Selenium resolution (for Chrome) Activated : " + screenWidth + "*" + screenLength);712 }713 options.addArguments("start-maximized");714 if (tCExecution.getVerbose() <= 0) {715 options.addArguments("--headless");716 }717 // Set UserAgent if necessary718 String usedUserAgent = getUserAgentToUse(tCExecution.getTestCaseObj().getUserAgent(), tCExecution.getUserAgent());719 if (!StringUtil.isNullOrEmpty(usedUserAgent)) {720 options.addArguments("--user-agent=" + usedUserAgent);721 }722 // Add the WebDriver proxy capability.723 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {724 Proxy proxy = new Proxy();725 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());726 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());727 options.setCapability("proxy", proxy);728 }729 return options;730// capabilities.setCapability(ChromeOptions.CAPABILITY, options);731// additionalCapabilities.add(factoryRobotCapability.create(0, "", ChromeOptions.CAPABILITY, options.toString()));732 } else if (browser.contains("android")) {733 // Launch the proxy with the settings specified in the robot options (executor)734 // since proxy Settings is out the Appium's scope, you must set it manually on your device735 // set the same port on device and robot736 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {737 this.startRemoteProxy(tCExecution);738 Proxy proxy = new Proxy();739 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());740 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());741 }742 capabilities = DesiredCapabilities.android();743 } else if (browser.contains("ipad")) {744 capabilities = DesiredCapabilities.ipad();745 } else if (browser.contains("iphone")) {746 capabilities = DesiredCapabilities.iphone();747 } else if (browser.contains("safari")) {748 SafariOptions options = new SafariOptions();749 return options;750// capabilities = DesiredCapabilities.safari();751 } else {752 LOG.warn("Not supported Browser : " + browser);753 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);754 mes.setDescription(mes.getDescription().replace("%MES%", "Browser '" + browser + "' is not supported"));755 mes.setDescription("Not supported Browser : " + browser);756 throw new CerberusException(mes);757 }758 } catch (CerberusException ex) {759 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);760 mes.setDescription(mes.getDescription().replace("%MES%", "Failed to set capability on the browser '" + browser + "' due to " + ex.getMessageError().getDescription()));761 throw new CerberusException(mes);762 }763 return capabilities;764 }765 /**766 * This method determine which user agent to use.767 *768 * @param userAgentTestCase769 * @param userAgentRobot770 * @return String containing the userAgent to use771 */772 private String getUserAgentToUse(String userAgentTestCase, String userAgentRobot) {773 if (StringUtil.isNullOrEmpty(userAgentRobot) && StringUtil.isNullOrEmpty(userAgentTestCase)) {774 return "";775 } else {776 return StringUtil.isNullOrEmpty(userAgentTestCase) ? userAgentRobot : userAgentTestCase;777 }778 }779 /**780 * This method determine which screenSize to use.781 *782 * @param screenSizeTestCase783 * @param screenSizeRobot784 * @return String containing the screensize to use785 */786 private String getScreenSizeToUse(String screenSizeTestCase, String screenSizeRobot) {787 if (StringUtil.isNullOrEmpty(screenSizeRobot) && StringUtil.isNullOrEmpty(screenSizeTestCase)) {788 return "";789 } else {790 return StringUtil.isNullOrEmpty(screenSizeTestCase) ? screenSizeRobot : screenSizeTestCase;791 }792 }793 @Override794 public boolean stopServer(TestCaseExecution tce) {795 Session session = tce.getSession();796 if (session.isStarted()) {797 try {798 // Wait 2 sec till HAR is exported799 Thread.sleep(2000);800 } catch (InterruptedException ex) {801 LOG.error(ex.toString(), ex);802 }803 /**804 * We remove manually the package if it is defined.805 */806 if (session.getAppiumDriver() != null && tce.getCountryEnvironmentParameters() != null807 && !StringUtil.isNullOrEmpty(tce.getCountryEnvironmentParameters().getMobilePackage())) {808 session.getAppiumDriver().removeApp(tce.getCountryEnvironmentParameters().getMobilePackage());809 }810 /**811 * We lock device if deviceLockUnlock is active.812 */813 // 814 if (tce.getRobotExecutorObj() != null && session.getAppiumDriver() != null && session.getAppiumDriver() instanceof LocksDevice815 && "Y".equals(tce.getRobotExecutorObj().getDeviceLockUnlock())) {816 ((LocksDevice) session.getAppiumDriver()).lockDevice();817 }818 /**819 * We record Selenium log at the end of the execution.820 */821 switch (tce.getRobotProvider()) {822 case TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK:823 try {824 tce.addFileList(recorderService.recordSeleniumLog(tce));825 } catch (Exception ex) {826 LOG.error("Exception Getting Selenium Logs " + tce.getId(), ex);827 }828// try {829// tce.addFileList(recorderService.recordBrowserstackSeleniumLog(tce));830// } catch (Exception ex) {831// LOG.error("Exception Getting Browserstack Selenium Logs " + tce.getId(), ex);832// }833// break;834 case TestCaseExecution.ROBOTPROVIDER_NONE:835 try {836 tce.addFileList(recorderService.recordSeleniumLog(tce));837 } catch (Exception ex) {838 LOG.error("Exception Getting Selenium Logs " + tce.getId(), ex);839 }840 break;841 default:842 }843 /**844 * We record Har log at the end of the execution.845 */846 switch (tce.getRobotProvider()) {847 case TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK:848// try {849// String url = "http://api.bs.com/getHar?uuid=" + tce.getRobotSessionID();850// tce.addFileList(recorderService.recordBrowserstackHarLog(tce, url));851// } catch (Exception ex) {852// LOG.error("Exception Getting Browserstack HAR File " + tce.getId(), ex);853// }854 break;855 case TestCaseExecution.ROBOTPROVIDER_NONE:856 break;857 default:858 }859 try {860 // Get Har File when Cerberus Executor is activated.861 // If proxy started and parameter verbose >= 1 activated862 if ("Y".equals(tce.getRobotExecutorObj().getExecutorProxyActive())863 && tce.getVerbose() >= 1) {864 String url = "http://" + tce.getRobotExecutorObj().getHost() + ":" + tce.getRobotExecutorObj().getExecutorExtensionPort() + "/getHar?uuid=" + tce.getRemoteProxyUUID();865 LOG.debug("Url to get HAR : " + url);866 tce.addFileList(recorderService.recordHarLog(tce, url));867 LOG.debug("Retrieved Har file by calling : " + url);868 }869 } catch (Exception ex) {870 LOG.error("Exception Getting Har File from Cerberus Executor " + tce.getId(), ex);871 }872 /**873 * We Stop the Robot Session (Selenium or Appium).874 */875 LOG.info("Stop execution robot session");876 if (tce.getRobotProvider().equals(TestCaseExecution.ROBOTPROVIDER_KOBITON)) {877 // For Kobiton, we should first close Appium session.878 if (session.getAppiumDriver() != null) {879 session.getAppiumDriver().close();880 }881 if (session.getDriver() != null) {882 session.getDriver().quit();883 }884 } else {885 session.quit();886 }887 return true;888 }889 return false;890 }891 private static void getIPOfNode(TestCaseExecution tCExecution) {892 try {893 Session session = tCExecution.getSession();894 HttpCommandExecutor ce = (HttpCommandExecutor) ((RemoteWebDriver) session.getDriver()).getCommandExecutor();895 SessionId sessionId = ((RemoteWebDriver) session.getDriver()).getSessionId();896 String hostName = ce.getAddressOfRemoteServer().getHost();897 int port = ce.getAddressOfRemoteServer().getPort();898 HttpHost host = new HttpHost(hostName, port);899 HttpClient client = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();900 URL sessionURL = new URL(RobotServerService.getBaseUrl(session.getHost(), session.getPort()) + "/grid/api/testsession?session=" + sessionId);901 BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", sessionURL.toExternalForm());902 HttpResponse response = client.execute(host, r);903 if (!response.getStatusLine().toString().contains("403")904 && !response.getEntity().getContentType().getValue().contains("text/html")) {905 InputStream contents = response.getEntity().getContent();906 StringWriter writer = new StringWriter();907 IOUtils.copy(contents, writer, "UTF8");908 JSONObject object = new JSONObject(writer.toString());909 if (object.has("proxyId")) {910 URL myURL = new URL(object.getString("proxyId"));911 if ((myURL.getHost() != null) && (myURL.getPort() != -1)) {912 tCExecution.setRobotHost(myURL.getHost());913 tCExecution.setRobotPort(String.valueOf(myURL.getPort()));914 }915 } else {916 LOG.debug("'proxyId' json data not available from remote Selenium Server request : " + writer.toString());917 }918 }919 } catch (IOException | JSONException ex) {920 LOG.error(ex.toString(), ex);921 }922 }923 @Override924 public Capabilities getUsedCapabilities(Session session) {925 Capabilities caps = ((RemoteWebDriver) session.getDriver()).getCapabilities();926 return caps;927 }928 private void setScreenSize(WebDriver driver, Integer width, Integer length) {929 driver.manage().window().setPosition(new Point(0, 0));930 driver.manage().window().setSize(new Dimension(width, length));931 }932 private String getScreenSize(WebDriver driver) {933 return driver.manage().window().getSize().width + "*" + driver.manage().window().getSize().height;934 }935 private static String getBaseUrl(String host, String port) {936 String baseurl = "";937 if (!StringUtil.isNullOrEmpty(host) && (host.contains("https://") || host.contains("http://"))) {938 baseurl = host;939 } else {940 baseurl = "http://" + host;941 }942 if (!StringUtil.isNullOrEmpty(port) && Integer.valueOf(port) > 0) {943 baseurl += ":" + port;944 }945 return baseurl;946 }...

Full Screen

Full Screen

getScreenSize

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.TestCaseExecution;2import org.cerberus.crud.service.ITestCaseExecutionService;3import org.cerberus.engine.entity.MessageEvent;4import org.cerberus.engine.entity.MessageGeneral;5import org.cerberus.engine.execution.impl.TestCaseExecutionService;6import org.cerberus.engine.queuemanagement.entity.MessageEventBatch;7import org.cerberus.engine.queuemanagement.entity.MessageEventBatchAction;8import org.cerberus.engine.queuemanagement.entity.MessageEventBatchActionControl;9import org.cerberus.engine.queuemanagement.entity.MessageEventBatchActionControlExecution;10import org.cerberus.engine.queuemanagement.entity.MessageEventBatchActionControlExecutionStep;11import org.cerberus.engine.queuemanagement.entity.MessageEventBatchActionControlExecutionStepAction;12import org.cerberus.engine.queuemanagement.entity.MessageEventBatchActionControlExecutionStepActionControl;13import org.cerberus.engine.queuemanagement.entity.MessageEventBatchActionControlExecutionStepActionControlExecution;14import org.cerberus.engine.queuemanagement.entity.MessageEventBatchActionControlExecutionStepActionControlExecutionObject;15import org.cerberus.engine.queuemanagement.entity.MessageEventBatchActionControlExecutionStepActionControlExecutionObjectProperty;16import org.cerberus.engine.queuemanagement.entity.MessageEventBatchActionControlExecutionStepActionControlExecutionObjectPropertyExecution;17import org.cerberus.engine.queuemanagement.entity.MessageEventBatchActionControlExecutionStepActionControlExecutionObjectPropertyExecutionStep;18import org.cerberus.engine.queuemanagement.entity.MessageEventBatchActionControlExecutionStepActionControlExecutionObjectPropertyExecutionStepAction;19import org.cerberus.engine.queuemanagement.entity.MessageEventBatchActionControlExecutionStepActionControlExecutionObjectPropertyExecutionStepActionControl;20import org.cerberus.engine.queuemanagement.entity.MessageEventBatchActionControlExecutionStepActionControlExecutionObjectPropertyExecutionStepActionControlExecution;21import org.cerberus.engine.queuemanagement.entity.MessageEventBatchActionControlExecutionStepActionControlExecutionObjectPropertyExecutionStepActionControlExecutionObject;22import org.cerberus.engine.queuemanagement.entity.MessageEventBatchActionControlExecutionStepActionControlExecutionObjectPropertyExecutionStepActionControlExecutionObjectProperty;23import org.cerberus.engine.queueman

Full Screen

Full Screen

getScreenSize

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.TestCaseExecution;2public class getScreenSize {3 public static void main(String[] args) {4 TestCaseExecution tce = new TestCaseExecution();5 String screenSize = tce.getScreenSize();6 System.out.println(screenSize);7 }8}

Full Screen

Full Screen

getScreenSize

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.TestCaseExecution;2import org.cerberus.engine.entity.MessageEvent;3import org.cerberus.engine.entity.MessageGeneral;4import org.cerberus.engine.execution.IExecution;5import org.cerberus.engine.execution.impl.ExecutionFactory;6import org.cerberus.util.answer.AnswerItem;7import org.openqa.selenium.Dimension;8import org.openqa.selenium.WebDriver;9public class SetScreenSize {10 private WebDriver driver;11 public SetScreenSize(WebDriver driver) {12 this.driver = driver;13 }14 public MessageEvent execute(String screenSize) {15 MessageEvent message = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_SETSCREENSIZE);16 message.setDescription(message.getDescription().replace("%SCREENSIZE%", screenSize));17 try {18 TestCaseExecution tCExecution = new TestCaseExecution();19 tCExecution.setScreenSize(driver.manage().window().getSize());20 tCExecution.setScreenSize(new Dimension(Integer.parseInt(screenSize.split("x")[0]), Integer.parseInt(screenSize.split("x")[1])));21 driver.manage().window().setSize(tCExecution.getScreenSize());22 } catch (Exception ex) {23 message = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SETSCREENSIZE);24 message.setDescription(message.getDescription().replace("%SCREENSIZE%", screenSize));25 }26 return message;27 }28}

Full Screen

Full Screen

getScreenSize

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.TestCaseExecution;2String screenSize = TestCaseExecution.getScreenSize();3setProperty("screenSize", screenSize);4log(screenSize);5logEvent("Screen size: " + screenSize);6logEvent("Screen size: " + screenSize, "Link to report");7logEvent("Screen size: " + screenSize, "Link to report", "Description of the link");8logEvent("Screen size: " + screenSize, "Link to report", "Description of the link", true);9logEvent("Screen size: " + screenSize, "Link to report", "Description of the link", true, true);10logEvent("Screen size: " + screenSize, "Link to report", "Description of the link", true, true, true);11logEvent("Screen size: " + screenSize, "Link to report", "Description of the link", true, true, true, true);

Full Screen

Full Screen

getScreenSize

Using AI Code Generation

copy

Full Screen

1String screenSize = execution.getScreenSize();2String[] screenSizeArray = screenSize.split("x");3execution.setScreenSizeHeight(screenSizeArray[0]);4execution.setScreenSizeWidth(screenSizeArray[1]);5String screenSize = execution.getScreenSize();6String[] screenSizeArray = screenSize.split("x");7execution.setScreenSizeHeight(screenSizeArray[0]);8execution.setScreenSizeWidth(screenSizeArray[1]);9String screenSize = execution.getScreenSize();10String[] screenSizeArray = screenSize.split("x");11execution.setScreenSizeHeight(screenSizeArray[0]);12execution.setScreenSizeWidth(screenSizeArray[1]);13String screenSize = execution.getScreenSize();14String[] screenSizeArray = screenSize.split("x");15execution.setScreenSizeHeight(screenSizeArray[0]);16execution.setScreenSizeWidth(screenSizeArray[1]);

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 TestCaseExecution

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful