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

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

Source:RobotServerService.java Github

copy

Full Screen

...401 getIPOfNode(tCExecution);402 /**403 * If screenSize is defined, set the size of the screen.404 */405 String targetScreensize = getScreenSizeToUse(tCExecution.getTestCaseObj().getScreenSize(), tCExecution.getScreenSize());406 LOG.debug("Selenium resolution : " + targetScreensize);407 if (!tCExecution.getBrowser().equalsIgnoreCase(BrowserType.CHROME)) {408 // For chrome the resolution has already been defined at capabilities level.409 if ((!StringUtil.isNullOrEmpty(targetScreensize)) && targetScreensize.contains("*")) {410 Integer screenWidth = Integer.valueOf(targetScreensize.split("\\*")[0]);411 Integer screenLength = Integer.valueOf(targetScreensize.split("\\*")[1]);412 setScreenSize(driver, screenWidth, screenLength);413 LOG.debug("Selenium resolution Activated : " + screenWidth + "*" + screenLength);414 }415 }416 tCExecution.setScreenSize(getScreenSize(driver));417 tCExecution.setRobotDecli(tCExecution.getRobotDecli().replace("%SCREENSIZE%", tCExecution.getScreenSize()));418 String userAgent = (String) ((JavascriptExecutor) driver).executeScript("return navigator.userAgent;");419 tCExecution.setUserAgent(userAgent);420 }421 // unlock device if deviceLockUnlock is active422 if (tCExecution.getRobotExecutorObj() != null && appiumDriver != null && appiumDriver instanceof LocksDevice423 && "Y".equals(tCExecution.getRobotExecutorObj().getDeviceLockUnlock())) {424 ((LocksDevice) appiumDriver).unlockDevice();425 }426 tCExecution.getSession().setStarted(true);427 } catch (CerberusException exception) {428 LOG.error(exception.toString(), exception);429 throw new CerberusException(exception.getMessageError(), exception);430 } catch (MalformedURLException exception) {431 LOG.error(exception.toString(), exception);432 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_URL_MALFORMED);433 mes.setDescription(mes.getDescription().replace("%URL%", tCExecution.getSession().getHost() + ":" + tCExecution.getSession().getPort()));434 throw new CerberusException(mes, exception);435 } catch (UnreachableBrowserException exception) {436 LOG.warn("Could not connect to : " + tCExecution.getSeleniumIP() + ":" + tCExecution.getSeleniumPort());437// LOG.error("UnreachableBrowserException catched.", exception);438 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_SELENIUM_COULDNOTCONNECT);439 mes.setDescription(mes.getDescription().replace("%SSIP%", tCExecution.getSeleniumIP()));440 mes.setDescription(mes.getDescription().replace("%SSPORT%", tCExecution.getSeleniumPort()));441 mes.setDescription(mes.getDescription().replace("%ERROR%", exception.toString()));442 throw new CerberusException(mes, exception);443 } catch (Exception exception) {444 LOG.error(exception.toString(), exception);445 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);446 mes.setDescription(mes.getDescription().replace("%MES%", exception.toString()));447 executorService.stopRemoteProxy(tCExecution);448 throw new CerberusException(mes, exception);449 } finally {450 executionThreadPoolService.executeNextInQueueAsynchroneously(false);451 }452 }453 private String getSession(WebDriver driver, String robotProvider) {454 String session = "";455 switch (robotProvider) {456 case TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK:457 session = ((RemoteWebDriver) driver).getSessionId().toString();458 break;459 case TestCaseExecution.ROBOTPROVIDER_KOBITON:460 session = ((RemoteWebDriver) driver).getCapabilities().getCapability("kobitonSessionId").toString();461 break;462 case TestCaseExecution.ROBOTPROVIDER_NONE:463 session = ((RemoteWebDriver) driver).getSessionId().toString();464 break;465 default:466 }467 return session;468 }469 private String guessRobotProvider(String host) {470 if (host.contains("browserstack")) {471 return TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK;472 }473 if (host.contains("kobiton")) {474 return TestCaseExecution.ROBOTPROVIDER_KOBITON;475 }476 return TestCaseExecution.ROBOTPROVIDER_NONE;477 }478 /**479 * Set DesiredCapabilities480 *481 * @param tCExecution482 * @return483 * @throws CerberusException484 */485 private MutableCapabilities setCapabilities(TestCaseExecution tCExecution) throws CerberusException {486 /**487 * Instanciate DesiredCapabilities488 */489 MutableCapabilities caps = new MutableCapabilities();490 // In case browser is not defined at that level, we force it to firefox.491 if (StringUtil.isNullOrEmpty(tCExecution.getBrowser())) {492 tCExecution.setBrowser("firefox");493 }494 /**495 * Set Browser Capabilities496 */497 caps = this.setCapabilityBrowser(caps, tCExecution.getBrowser(), tCExecution);498 /**499 * Loop on RobotCapabilities to feed DesiredCapabilities Capability must500 * be String, Integer or Boolean501 */502 List<RobotCapability> additionalCapabilities = new ArrayList<>();503 if (tCExecution.getRobotObj() != null) {504 additionalCapabilities = tCExecution.getRobotObj().getCapabilitiesDecoded();505 }506 if (additionalCapabilities != null) {507 for (RobotCapability additionalCapability : additionalCapabilities) {508 LOG.debug("RobotCaps on Robot : " + additionalCapability.getRobot() + " caps : " + additionalCapability.getCapability() + " Value : " + additionalCapability.getValue());509 if ((caps.getCapability(additionalCapability.getCapability()) == null)510 || ((caps.getCapability(additionalCapability.getCapability()) != null) && (caps.getCapability(additionalCapability.getCapability()).toString().equals("")))) { // caps does not already exist so we can set it.511 if (StringUtil.isBoolean(additionalCapability.getValue())) {512 caps.setCapability(additionalCapability.getCapability(), StringUtil.parseBoolean(additionalCapability.getValue()));513 } else if (StringUtil.isInteger(additionalCapability.getValue())) {514 caps.setCapability(additionalCapability.getCapability(), Integer.valueOf(additionalCapability.getValue()));515 } else {516 caps.setCapability(additionalCapability.getCapability(), additionalCapability.getValue());517 }518 }519 }520 } else {521 additionalCapabilities = new ArrayList<>();522 }523 /**524 * Feed DesiredCapabilities with values get from Robot525 */526 if (!StringUtil.isNullOrEmpty(tCExecution.getPlatform())) {527 if ((caps.getCapability("platform") == null)528 || ((caps.getCapability("platform") != null) && (caps.getCapability("platform").toString().equals("ANY") || caps.getCapability("platform").toString().equals("")))) {529 caps.setCapability("platformName", tCExecution.getPlatform());530 }531 }532 if (!StringUtil.isNullOrEmpty(tCExecution.getVersion())) {533 if ((caps.getCapability("version") == null)534 || ((caps.getCapability("version") != null) && (caps.getCapability("version").toString().equals("")))) {535 caps.setCapability("version", tCExecution.getVersion());536 }537 }538 if (tCExecution.getRobotExecutorObj() != null) {539 // Setting deviceUdid and device name from executor.540 if (!StringUtil.isNullOrEmpty(tCExecution.getRobotExecutorObj().getDeviceUuid())) {541 if ((caps.getCapability("udid") == null)542 || ((caps.getCapability("udid") != null) && (caps.getCapability("udid").toString().equals("")))) {543 caps.setCapability("udid", tCExecution.getRobotExecutorObj().getDeviceUuid());544 }545 }546 if (!StringUtil.isNullOrEmpty(tCExecution.getRobotExecutorObj().getDeviceName())) {547 if ((caps.getCapability("deviceName") == null)548 || ((caps.getCapability("deviceName") != null) && (caps.getCapability("deviceName").toString().equals("")))) {549 caps.setCapability("deviceName", tCExecution.getRobotExecutorObj().getDeviceName());550 }551 }552 if (!StringUtil.isNullOrEmpty(tCExecution.getRobotExecutorObj().getDeviceName())) {553 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {554 if ((caps.getCapability("systemPort") == null)555 || ((caps.getCapability("systemPort") != null) && (caps.getCapability("systemPort").toString().equals("")))) {556 caps.setCapability("systemPort", tCExecution.getRobotExecutorObj().getDevicePort());557 }558 } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {559 if ((caps.getCapability("wdaLocalPort") == null)560 || ((caps.getCapability("wdaLocalPort") != null) && (caps.getCapability("wdaLocalPort").toString().equals("")))) {561 caps.setCapability("wdaLocalPort", tCExecution.getRobotExecutorObj().getDevicePort());562 }563 }564 }565 }566 /**567 * if application is a mobile one, then set the "app" capability to the568 * application binary path569 */570 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)571 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {572 // Set the app capability with the application path573 if (!StringUtil.isNullOrEmpty(tCExecution.getMyHost())) {574 if (isNotAlreadyDefined(caps, "app")) {575 caps.setCapability("app", tCExecution.getMyHost());576 }577 } else {578 if (isNotAlreadyDefined(caps, "app")) {579 caps.setCapability("app", tCExecution.getCountryEnvironmentParameters().getIp());580 }581 }582 if (!StringUtil.isNullOrEmpty(tCExecution.getCountryEnvironmentParameters().getMobileActivity()) && tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {583 if (isNotAlreadyDefined(caps, "appWaitActivity")) {584 caps.setCapability("appWaitActivity", tCExecution.getCountryEnvironmentParameters().getMobileActivity());585 }586 }587 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {588 if (isNotAlreadyDefined(caps, "automationName")) {589 caps.setCapability("automationName", "UIAutomator2"); // use UIAutomator2 by default590 }591 }592 }593 /**594 * We record Selenium log at the end of the execution.595 */596 switch (tCExecution.getRobotProvider()) {597 case TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK:598 if (!StringUtil.isNullOrEmpty(tCExecution.getTag()) && isNotAlreadyDefined(caps, "build")) {599 caps.setCapability("build", tCExecution.getTag());600 }601 if (isNotAlreadyDefined(caps, "project")) {602 caps.setCapability("project", tCExecution.getApplication());603 }604 if (isNotAlreadyDefined(caps, "name")) {605 String externalExeName = parameterService.getParameterStringByKey("cerberus_browserstack_defaultexename", tCExecution.getSystem(), "Exe : %EXEID%");606 externalExeName = externalExeName.replace("%EXEID%", String.valueOf(tCExecution.getId()));607 caps.setCapability("name", externalExeName);608 }609 if (tCExecution.getVerbose() >= 2) {610 if (isNotAlreadyDefined(caps, "browserstack.debug")) {611 caps.setCapability("browserstack.debug", true);612 }613 if (isNotAlreadyDefined(caps, "browserstack.console")) {614 caps.setCapability("browserstack.console", "warnings");615 }616 if (isNotAlreadyDefined(caps, "browserstack.networkLogs")) {617 caps.setCapability("browserstack.networkLogs", true);618 }619 }620 break;621 case TestCaseExecution.ROBOTPROVIDER_KOBITON:622 if (isNotAlreadyDefined(caps, "sessionName")) {623 String externalExeName = parameterService.getParameterStringByKey("cerberus_kobiton_defaultsessionname", tCExecution.getSystem(), "%EXEID% : %TEST% - %TESTCASE%");624 externalExeName = externalExeName.replace("%EXEID%", String.valueOf(tCExecution.getId()));625 externalExeName = externalExeName.replace("%APPLI%", String.valueOf(tCExecution.getApplication()));626 externalExeName = externalExeName.replace("%TAG%", String.valueOf(tCExecution.getTag()));627 externalExeName = externalExeName.replace("%TEST%", String.valueOf(tCExecution.getTest()));628 externalExeName = externalExeName.replace("%TESTCASE%", String.valueOf(tCExecution.getTestCase()));629 externalExeName = externalExeName.replace("%TESTCASEDESC%", String.valueOf(tCExecution.getTestCaseObj().getDescription()));630 caps.setCapability("sessionName", externalExeName);631 }632 if (isNotAlreadyDefined(caps, "sessionDescription")) {633 String externalExeName = parameterService.getParameterStringByKey("cerberus_kobiton_defaultsessiondescription", tCExecution.getSystem(), "%TESTCASEDESC%");634 externalExeName = externalExeName.replace("%EXEID%", String.valueOf(tCExecution.getId()));635 externalExeName = externalExeName.replace("%APPLI%", String.valueOf(tCExecution.getApplication()));636 externalExeName = externalExeName.replace("%TAG%", String.valueOf(tCExecution.getTag()));637 externalExeName = externalExeName.replace("%TEST%", String.valueOf(tCExecution.getTest()));638 externalExeName = externalExeName.replace("%TESTCASE%", String.valueOf(tCExecution.getTestCase()));639 externalExeName = externalExeName.replace("%TESTCASEDESC%", String.valueOf(tCExecution.getTestCaseObj().getDescription()));640 caps.setCapability("sessionDescription", externalExeName);641 }642 if (isNotAlreadyDefined(caps, "deviceGroup")) {643 caps.setCapability("deviceGroup", "KOBITON"); // use UIAutomator2 by default644 }645 break;646 case TestCaseExecution.ROBOTPROVIDER_NONE:647 break;648 default:649 }650 return caps;651 }652 private boolean isNotAlreadyDefined(MutableCapabilities caps, String capability) {653 return ((caps.getCapability(capability) == null)654 || ((caps.getCapability(capability) != null) && (caps.getCapability(capability).toString().equals(""))));655 }656 /**657 * Instantiate DesiredCapabilities regarding the browser658 *659 * @param capabilities660 * @param browser661 * @param tCExecution662 * @return663 * @throws CerberusException664 */665 private MutableCapabilities setCapabilityBrowser(MutableCapabilities capabilities, String browser, TestCaseExecution tCExecution) throws CerberusException {666 try {667 // Get User Agent to use.668 String usedUserAgent;669 usedUserAgent = getUserAgentToUse(tCExecution.getTestCaseObj().getUserAgent(), tCExecution.getUserAgent());670 switch (browser) {671 case "firefox":672 FirefoxOptions optionsFF = new FirefoxOptions();673 FirefoxProfile profile = new FirefoxProfile();674 profile.setPreference("app.update.enabled", false);675 try {676 Invariant invariant = invariantService.convert(invariantService.readByKey("COUNTRY", tCExecution.getCountry()));677 if (invariant.getGp2() == null) {678 LOG.warn("Country selected (" + tCExecution.getCountry() + ") has no value of GP2 in Invariant table, default language set to English (en)");679 profile.setPreference("intl.accept_languages", "en");680 } else {681 profile.setPreference("intl.accept_languages", invariant.getGp2());682 }683 } catch (CerberusException ex) {684 LOG.warn("Country selected (" + tCExecution.getCountry() + ") not in Invariant table, default language set to English (en)");685 profile.setPreference("intl.accept_languages", "en");686 }687 // Set UserAgent if testCaseUserAgent or robotUserAgent is defined688 if (!StringUtil.isNullOrEmpty(usedUserAgent)) {689 profile.setPreference("general.useragent.override", usedUserAgent);690 }691 if (tCExecution.getVerbose() <= 0) {692 optionsFF.setHeadless(true);693 }694 // Add the WebDriver proxy capability.695 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {696 Proxy proxy = new Proxy();697 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());698 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());699 proxy.setProxyType(Proxy.ProxyType.MANUAL);700 LOG.debug("Setting Firefox proxy to : " + proxy.toString());701 optionsFF.setProxy(proxy);702 }703 optionsFF.setProfile(profile);704 // Accept Insecure Certificates.705 optionsFF.setAcceptInsecureCerts(true);706 return optionsFF;707 case "chrome":708 ChromeOptions optionsCH = new ChromeOptions();709 // Maximize windows for chrome browser710 String targetScreensize = getScreenSizeToUse(tCExecution.getTestCaseObj().getScreenSize(), tCExecution.getScreenSize());711 if ((!StringUtil.isNullOrEmpty(targetScreensize)) && targetScreensize.contains("*")) {712 Integer screenWidth = Integer.valueOf(targetScreensize.split("\\*")[0]);713 Integer screenLength = Integer.valueOf(targetScreensize.split("\\*")[1]);714 String sizeOpts = "--window-size=" + screenWidth + "," + screenLength;715 optionsCH.addArguments(sizeOpts);716 LOG.debug("Selenium resolution (for Chrome) Activated : " + screenWidth + "*" + screenLength);717 }718 optionsCH.addArguments("start-maximized");719 if (tCExecution.getVerbose() <= 0) {720 optionsCH.addArguments("--headless");721 }722 // Set UserAgent if necessary723 if (!StringUtil.isNullOrEmpty(usedUserAgent)) {724 optionsCH.addArguments("--user-agent=" + usedUserAgent);725 }726 // Add the WebDriver proxy capability.727 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {728 Proxy proxy = new Proxy();729 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());730 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());731 proxy.setNoProxy("");732 proxy.setProxyType(Proxy.ProxyType.MANUAL);733 LOG.debug("Setting Chrome proxy to : " + proxy.toString());734 optionsCH.setCapability("proxy", proxy);735 }736 // Accept Insecure Certificates.737 optionsCH.setAcceptInsecureCerts(true);738 return optionsCH;739 case "safari":740 SafariOptions optionsSA = new SafariOptions();741 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {742 Proxy proxy = new Proxy();743 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());744 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());745 optionsSA.setProxy(proxy);746 }747 return optionsSA;748 case "IE":749 InternetExplorerOptions optionsIE = new InternetExplorerOptions();750 // Add the WebDriver proxy capability.751 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {752 Proxy proxy = new Proxy();753 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());754 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());755 proxy.setProxyType(Proxy.ProxyType.MANUAL);756 LOG.debug("Setting IE proxy to : " + proxy.toString());757 optionsIE.setCapability("proxy", proxy);758 }759 return optionsIE;760 case "edge":761 EdgeOptions optionsED = new EdgeOptions();762 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {763 Proxy proxy = new Proxy();764 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());765 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());766 optionsED.setProxy(proxy);767 }768 return optionsED;769 case "opera":770 OperaOptions optionsOP = new OperaOptions();771 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {772 Proxy proxy = new Proxy();773 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());774 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());775 optionsOP.setProxy(proxy);776 }777 optionsOP.setCapability("browser", "opera");778 // 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.779// if (!StringUtil.isNullOrEmpty(usedUserAgent)) {780// optionsOP.setCapability("opera.profile", "{profileName: \"foo\",userAgent: \"" + usedUserAgent + "\"}");781// }782 return optionsOP;783 case "android":784 if (tCExecution.getRobotExecutorObj() != null && "Y".equals(tCExecution.getRobotExecutorObj().getExecutorProxyActive())) {785 Proxy proxy = new Proxy();786 proxy.setHttpProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());787 proxy.setSslProxy(tCExecution.getRobotExecutorObj().getExecutorProxyHost() + ":" + tCExecution.getRemoteProxyPort());788 }789 capabilities = DesiredCapabilities.android();790 break;791 case "ipad":792 capabilities = DesiredCapabilities.ipad();793 break;794 case "iphone":795 capabilities = DesiredCapabilities.iphone();796 break;797 // Unfortunatly Yandex is not yet supported on BrowserStack. Once it will be it should look like that:798// case "yandex":799// capabilities = new DesiredCapabilities();800// capabilities.setCapability("browser", "Yandex");801// capabilities.setCapability("browser_version", "14.12");802// break;803 default:804 LOG.warn("Not supported Browser : " + browser);805 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);806 mes.setDescription(mes.getDescription().replace("%MES%", "Browser '" + browser + "' is not supported"));807 mes.setDescription("Not supported Browser : " + browser);808 throw new CerberusException(mes);809 }810 } catch (CerberusException ex) {811 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);812 mes.setDescription(mes.getDescription().replace("%MES%", "Failed to set capability on the browser '" + browser + "' due to " + ex.getMessageError().getDescription()));813 throw new CerberusException(mes);814 }815 return capabilities;816 }817 /**818 * This method determine which user agent to use.819 *820 * @param userAgentTestCase821 * @param userAgentRobot822 * @return String containing the userAgent to use823 */824 private String getUserAgentToUse(String userAgentTestCase, String userAgentRobot) {825 if (StringUtil.isNullOrEmpty(userAgentRobot) && StringUtil.isNullOrEmpty(userAgentTestCase)) {826 return "";827 } else {828 return StringUtil.isNullOrEmpty(userAgentTestCase) ? userAgentRobot : userAgentTestCase;829 }830 }831 /**832 * This method determine which screenSize to use.833 *834 * @param screenSizeTestCase835 * @param screenSizeRobot836 * @return String containing the screensize to use837 */838 private String getScreenSizeToUse(String screenSizeTestCase, String screenSizeRobot) {839 if (StringUtil.isNullOrEmpty(screenSizeRobot) && StringUtil.isNullOrEmpty(screenSizeTestCase)) {840 return "";841 } else {842 return StringUtil.isNullOrEmpty(screenSizeTestCase) ? screenSizeRobot : screenSizeTestCase;843 }844 }845 @Override846 public boolean stopServer(TestCaseExecution tce) {847 Session session = tce.getSession();848 if (session.isStarted()) {849 try {850 // Wait 2 sec till HAR is exported851 Thread.sleep(2000);852 } catch (InterruptedException ex) {853 LOG.error(ex.toString(), ex);854 }855 /**856 * We remove manually the package if it is defined.857 */858 if (session.getAppiumDriver() != null && tce.getCountryEnvironmentParameters() != null859 && !StringUtil.isNullOrEmpty(tce.getCountryEnvironmentParameters().getMobilePackage())) {860 session.getAppiumDriver().removeApp(tce.getCountryEnvironmentParameters().getMobilePackage());861 }862 /**863 * We lock device if deviceLockUnlock is active.864 */865 // 866 if (tce.getRobotExecutorObj() != null && session.getAppiumDriver() != null && session.getAppiumDriver() instanceof LocksDevice867 && "Y".equals(tce.getRobotExecutorObj().getDeviceLockUnlock())) {868 ((LocksDevice) session.getAppiumDriver()).lockDevice();869 }870 /**871 * We record Selenium log at the end of the execution.872 */873 switch (tce.getRobotProvider()) {874 case TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK:875 try {876 tce.addFileList(recorderService.recordSeleniumLog(tce));877 } catch (Exception ex) {878 LOG.error("Exception Getting Selenium Logs " + tce.getId(), ex);879 }880// try {881// tce.addFileList(recorderService.recordBrowserstackSeleniumLog(tce));882// } catch (Exception ex) {883// LOG.error("Exception Getting Browserstack Selenium Logs " + tce.getId(), ex);884// }885// break;886 case TestCaseExecution.ROBOTPROVIDER_NONE:887 try {888 tce.addFileList(recorderService.recordSeleniumLog(tce));889 } catch (Exception ex) {890 LOG.error("Exception Getting Selenium Logs " + tce.getId(), ex);891 }892 break;893 default:894 }895 /**896 * We record Har log at the end of the execution.897 */898 switch (tce.getRobotProvider()) {899 case TestCaseExecution.ROBOTPROVIDER_BROWSERSTACK:900// try {901// String url = "http://api.bs.com/getHar?uuid=" + tce.getRobotSessionID();902// tce.addFileList(recorderService.recordBrowserstackHarLog(tce, url));903// } catch (Exception ex) {904// LOG.error("Exception Getting Browserstack HAR File " + tce.getId(), ex);905// }906 break;907 case TestCaseExecution.ROBOTPROVIDER_NONE:908 break;909 default:910 }911 try {912 // Get Har File when Cerberus Executor is activated.913 // If proxy started and parameter verbose >= 1 activated914 if ("Y".equals(tce.getRobotExecutorObj().getExecutorProxyActive())915 && tce.getVerbose() >= 1) {916 if (parameterService.getParameterBooleanByKey("cerberus_networkstatsave_active", tce.getSystem(), false)) {917 // Before collecting the stats, we wait the network idles for few minutes918 executorService.waitForIdleNetwork(tce.getRobotExecutorObj().getExecutorExtensionHost(), tce.getRobotExecutorObj().getExecutorExtensionPort(), tce.getRemoteProxyUUID(), tce.getSystem());919 // We now get the har data.920 JSONObject har = executorService.getHar(null, false, tce.getRobotExecutorObj().getExecutorExtensionHost(), tce.getRobotExecutorObj().getExecutorExtensionPort(), tce.getRemoteProxyUUID(), tce.getSystem());921 // and enrich it with stat entry.922 har = harService.enrichWithStats(har, tce.getCountryEnvironmentParameters().getDomain(), tce.getSystem());923 /**924 * We convert the har to database record HttpStat and925 * save it to database.926 */927 try {928 AnswerItem<TestCaseExecutionHttpStat> answHttpStat = testCaseExecutionHttpStatService.convertFromHarWithStat(tce, har);929 tce.setHttpStat(answHttpStat.getItem());930 testCaseExecutionHttpStatService.create(answHttpStat.getItem());931 } catch (Exception ex) {932 LOG.warn("Exception collecting and saving stats for execution " + tce.getId() + " Exception : " + ex.toString());933 }934 }935 }936 } catch (Exception ex) {937 LOG.error("Exception Getting Har File from Cerberus Executor " + tce.getId(), ex);938 }939 /**940 * We Stop the Robot Session (Selenium or Appium).941 */942 LOG.info("Stop execution robot session");943 if (tce.getRobotProvider().equals(TestCaseExecution.ROBOTPROVIDER_KOBITON)) {944 // For Kobiton, we should first close Appium session.945 if (session.getAppiumDriver() != null) {946 session.getAppiumDriver().close();947 }948 if (session.getDriver() != null) {949 session.getDriver().quit();950 }951 } else {952 session.quit();953 }954 return true;955 }956 return false;957 }958 private static void getIPOfNode(TestCaseExecution tCExecution) {959 try {960 Session session = tCExecution.getSession();961 HttpCommandExecutor ce = (HttpCommandExecutor) ((RemoteWebDriver) session.getDriver()).getCommandExecutor();962 SessionId sessionId = ((RemoteWebDriver) session.getDriver()).getSessionId();963 String hostName = ce.getAddressOfRemoteServer().getHost();964 int port = ce.getAddressOfRemoteServer().getPort();965 HttpHost host = new HttpHost(hostName, port);966 HttpClient client = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();967 URL sessionURL = new URL(RobotServerService.getBaseUrl(session.getHost(), session.getPort()) + "/grid/api/testsession?session=" + sessionId);968 BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", sessionURL.toExternalForm());969 HttpResponse response = client.execute(host, r);970 if (!response.getStatusLine().toString().contains("403")971 && !response.getEntity().getContentType().getValue().contains("text/html")) {972 InputStream contents = response.getEntity().getContent();973 StringWriter writer = new StringWriter();974 IOUtils.copy(contents, writer, "UTF8");975 JSONObject object = new JSONObject(writer.toString());976 if (object.has("proxyId")) {977 URL myURL = new URL(object.getString("proxyId"));978 if ((myURL.getHost() != null) && (myURL.getPort() != -1)) {979 tCExecution.setRobotHost(myURL.getHost());980 tCExecution.setRobotPort(String.valueOf(myURL.getPort()));981 }982 } else {983 LOG.debug("'proxyId' json data not available from remote Selenium Server request : " + writer.toString());984 }985 }986 } catch (IOException | JSONException ex) {987 LOG.error(ex.toString(), ex);988 }989 }990 @Override991 public Capabilities getUsedCapabilities(Session session) {992 Capabilities caps = ((RemoteWebDriver) session.getDriver()).getCapabilities();993 return caps;994 }995 private void setScreenSize(WebDriver driver, Integer width, Integer length) {996 driver.manage().window().setPosition(new Point(0, 0));997 driver.manage().window().setSize(new Dimension(width, length));998 }999 private String getScreenSize(WebDriver driver) {1000 return driver.manage().window().getSize().width + "*" + driver.manage().window().getSize().height;1001 }1002 private static String getBaseUrl(String host, String port) {1003 String baseurl = "";1004 if (!StringUtil.isNullOrEmpty(host) && (host.contains("https://") || host.contains("http://"))) {1005 baseurl = host;1006 } else {1007 baseurl = "http://" + host;1008 }1009 if (!StringUtil.isNullOrEmpty(port) && Integer.valueOf(port) > 0) {1010 baseurl += ":" + port;1011 }1012 return baseurl;1013 }...

Full Screen

Full Screen

Source:SeleniumServerService.java Github

copy

Full Screen

...268 getIPOfNode(tCExecution);269 /**270 * If screenSize is defined, set the size of the screen.271 */272 String targetScreensize = getScreenSizeToUse(tCExecution.getTestCaseObj().getScreenSize(), tCExecution.getScreenSize());273 LOG.debug("Selenium resolution : " + targetScreensize);274 if ((!StringUtil.isNullOrEmpty(targetScreensize)) && targetScreensize.contains("*")) {275 Integer screenWidth = Integer.valueOf(targetScreensize.split("\\*")[0]);276 Integer screenLength = Integer.valueOf(targetScreensize.split("\\*")[1]);277 setScreenSize(driver, screenWidth, screenLength);278 LOG.debug("Selenium resolution Activated : " + screenWidth + "*" + screenLength);279 }280 tCExecution.setScreenSize(getScreenSize(driver));281 tCExecution.setRobotDecli(tCExecution.getRobotDecli().replace("%SCREENSIZE%", tCExecution.getScreenSize()));282 String userAgent = (String) ((JavascriptExecutor) driver).executeScript("return navigator.userAgent;");283 tCExecution.setUserAgent(userAgent);284 }285 tCExecution.getSession().setStarted(true);286 } catch (CerberusException exception) {287 LOG.error(logPrefix + exception.toString(), exception);288 throw new CerberusException(exception.getMessageError());289 } catch (MalformedURLException exception) {290 LOG.error(logPrefix + exception.toString(), exception);291 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_URL_MALFORMED);292 mes.setDescription(mes.getDescription().replace("%URL%", tCExecution.getSession().getHost() + ":" + tCExecution.getSession().getPort()));293 throw new CerberusException(mes);294 } catch (UnreachableBrowserException exception) {295 LOG.error(logPrefix + exception.toString(), exception);296 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_SELENIUM_COULDNOTCONNECT);297 mes.setDescription(mes.getDescription().replace("%SSIP%", tCExecution.getSeleniumIP()));298 mes.setDescription(mes.getDescription().replace("%SSPORT%", tCExecution.getSeleniumPort()));299 mes.setDescription(mes.getDescription().replace("%ERROR%", exception.toString()));300 throw new CerberusException(mes);301 } catch (Exception exception) {302 LOG.error(logPrefix + exception.toString(), exception);303 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);304 mes.setDescription(mes.getDescription().replace("%MES%", exception.toString()));305 throw new CerberusException(mes);306 }307 }308 /**309 * Set DesiredCapabilities310 *311 * @param tCExecution312 * @return313 * @throws CerberusException314 */315 private DesiredCapabilities setCapabilities(TestCaseExecution tCExecution) throws CerberusException {316 /**317 * Instanciate DesiredCapabilities318 */319 DesiredCapabilities caps = new DesiredCapabilities();320 // In case browser is not defined at that level, we force it to firefox.321 if (StringUtil.isNullOrEmpty(tCExecution.getBrowser())) {322 tCExecution.setBrowser("firefox");323 }324 caps = this.setCapabilityBrowser(caps, tCExecution.getBrowser(), tCExecution);325 /**326 * Feed DesiredCapabilities with values get from Robot327 */328 if (!StringUtil.isNullOrEmpty(tCExecution.getPlatform())) {329 caps.setCapability("platform", tCExecution.getPlatform());330 }331 if (!StringUtil.isNullOrEmpty(tCExecution.getVersion())) {332 caps.setCapability("version", tCExecution.getVersion());333 }334 /**335 * Loop on RobotCapabilities to feed DesiredCapabilities Capability must336 * be String, Integer or Boolean337 */338 List<RobotCapability> additionalCapabilities = tCExecution.getCapabilities();339 if (additionalCapabilities != null) {340 for (RobotCapability additionalCapability : additionalCapabilities) {341 if (StringUtil.isBoolean(additionalCapability.getValue())) {342 caps.setCapability(additionalCapability.getCapability(), StringUtil.parseBoolean(additionalCapability.getValue()));343 } else if (StringUtil.isInteger(additionalCapability.getValue())) {344 caps.setCapability(additionalCapability.getCapability(), Integer.valueOf(additionalCapability.getValue()));345 } else {346 caps.setCapability(additionalCapability.getCapability(), additionalCapability.getValue());347 }348 }349 }350 /**351 * if application is a mobile one, then set the "app" capability to the352 * application binary path353 */354 if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)355 || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {356 // Set the app capability with the application path357 if (tCExecution.isManualURL()) {358 caps.setCapability("app", tCExecution.getMyHost());359 } else {360 caps.setCapability("app", tCExecution.getCountryEnvironmentParameters().getIp());361 }362 }363 return caps;364 }365 /**366 * Instanciate DesiredCapabilities regarding the browser367 *368 * @param capabilities369 * @param browser370 * @param tCExecution371 * @return372 * @throws CerberusException373 */374 private DesiredCapabilities setCapabilityBrowser(DesiredCapabilities capabilities, String browser, TestCaseExecution tCExecution) throws CerberusException {375 try {376 if (browser.equalsIgnoreCase("firefox")) {377 capabilities = DesiredCapabilities.firefox();378 FirefoxProfile profile = new FirefoxProfile();379 profile.setPreference("app.update.enabled", false);380 try {381 Invariant invariant = invariantService.convert(invariantService.readByKey("COUNTRY", tCExecution.getCountry()));382 if (invariant.getGp2() == null) {383 LOG.warn("Country selected (" + tCExecution.getCountry() + ") has no value of GP2 in Invariant table, default language set to English (en)");384 profile.setPreference("intl.accept_languages", "en");385 } else {386 profile.setPreference("intl.accept_languages", invariant.getGp2());387 }388 } catch (CerberusException ex) {389 LOG.warn("Country selected (" + tCExecution.getCountry() + ") not in Invariant table, default language set to English (en)");390 profile.setPreference("intl.accept_languages", "en");391 }392 // Set UserAgent if testCaseUserAgent or robotUserAgent is defined393 String usedUserAgent = getUserAgentToUse(tCExecution.getTestCaseObj().getUserAgent(), tCExecution.getUserAgent());394 if (!StringUtil.isNullOrEmpty(usedUserAgent)) {395 profile.setPreference("general.useragent.override", usedUserAgent);396 }397 capabilities.setCapability(FirefoxDriver.PROFILE, profile);398 } else if (browser.equalsIgnoreCase("IE")) {399 capabilities = DesiredCapabilities.internetExplorer();400 } else if (browser.equalsIgnoreCase("chrome")) {401 capabilities = DesiredCapabilities.chrome();402 /**403 * Add custom capabilities404 */405 ChromeOptions options = new ChromeOptions();406 // Maximize windows for chrome browser407 options.addArguments("--start-fullscreen");408 // Set UserAgent if necessary409 String usedUserAgent = getUserAgentToUse(tCExecution.getTestCaseObj().getUserAgent(), tCExecution.getUserAgent());410 if (!StringUtil.isNullOrEmpty(usedUserAgent)) {411 options.addArguments("--user-agent=" + usedUserAgent);412 }413 capabilities.setCapability(ChromeOptions.CAPABILITY, options);414 } else if (browser.contains("android")) {415 capabilities = DesiredCapabilities.android();416 } else if (browser.contains("ipad")) {417 capabilities = DesiredCapabilities.ipad();418 } else if (browser.contains("iphone")) {419 capabilities = DesiredCapabilities.iphone();420 } else if (browser.contains("opera")) {421 capabilities = DesiredCapabilities.opera();422 } else if (browser.contains("safari")) {423 capabilities = DesiredCapabilities.safari();424 } else {425 LOG.warn("Not supported Browser : " + browser);426 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);427 mes.setDescription(mes.getDescription().replace("%MES%", "Browser '" + browser + "' is not supported"));428 mes.setDescription("Not supported Browser : " + browser);429 throw new CerberusException(mes);430 }431 } catch (CerberusException ex) {432 MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);433 mes.setDescription(mes.getDescription().replace("%MES%", "Failed to set capability on the browser '" + browser + "' due to " + ex.getMessageError().getDescription()));434 throw new CerberusException(mes);435 }436 return capabilities;437 }438 /**439 * This method determine which user agent to use.440 *441 * @param userAgentTestCase442 * @param userAgentRobot443 * @return String containing the userAgent to use444 */445 private String getUserAgentToUse(String userAgentTestCase, String userAgentRobot) {446 if (StringUtil.isNullOrEmpty(userAgentRobot) && StringUtil.isNullOrEmpty(userAgentTestCase)) {447 return "";448 } else {449 return StringUtil.isNullOrEmpty(userAgentTestCase) ? userAgentRobot : userAgentTestCase;450 }451 }452 /**453 * This method determine which screenSize to use.454 *455 * @param screenSizeTestCase456 * @param screenSizeRobot457 * @return String containing the userAgent to use458 */459 private String getScreenSizeToUse(String screenSizeTestCase, String screenSizeRobot) {460 if (StringUtil.isNullOrEmpty(screenSizeRobot) && StringUtil.isNullOrEmpty(screenSizeTestCase)) {461 return "";462 } else {463 return StringUtil.isNullOrEmpty(screenSizeTestCase) ? screenSizeRobot : screenSizeTestCase;464 }465 }466 @Override467 public boolean stopServer(Session session) {468 if (session.isStarted()) {469 try {470 // Wait 2 sec till HAR is exported471 Thread.sleep(2000);472 } catch (InterruptedException ex) {473 LOG.error(ex.toString());474 }475 LOG.info("Stop execution session");476 session.quit();477 return true;478 }479 return false;480 }481 private static void getIPOfNode(TestCaseExecution tCExecution) {482 try {483 Session session = tCExecution.getSession();484 HttpCommandExecutor ce = (HttpCommandExecutor) ((RemoteWebDriver) session.getDriver()).getCommandExecutor();485 SessionId sessionId = ((RemoteWebDriver) session.getDriver()).getSessionId();486 String hostName = ce.getAddressOfRemoteServer().getHost();487 int port = ce.getAddressOfRemoteServer().getPort();488 HttpHost host = new HttpHost(hostName, port);489 HttpClient client = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();490 URL sessionURL = new URL(SeleniumServerService.getBaseUrl(session.getHost(), session.getPort()) + "/grid/api/testsession?session=" + sessionId);491 BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", sessionURL.toExternalForm());492 HttpResponse response = client.execute(host, r);493 if (!response.getStatusLine().toString().contains("403")494 && !response.getEntity().getContentType().getValue().contains("text/html")) {495 InputStream contents = response.getEntity().getContent();496 StringWriter writer = new StringWriter();497 IOUtils.copy(contents, writer, "UTF8");498 JSONObject object = new JSONObject(writer.toString());499 URL myURL = new URL(object.getString("proxyId"));500 if ((myURL.getHost() != null) && (myURL.getPort() != -1)) {501 tCExecution.setIp(myURL.getHost());502 tCExecution.setPort(String.valueOf(myURL.getPort()));503 }504 }505 } catch (IOException ex) {506 LOG.error(ex.toString());507 } catch (JSONException ex) {508 LOG.error(ex.toString());509 }510 }511 @Override512 public Capabilities getUsedCapabilities(Session session) {513 Capabilities caps = ((RemoteWebDriver) session.getDriver()).getCapabilities();514 return caps;515 }516 private void setScreenSize(WebDriver driver, Integer width, Integer length) {517 driver.manage().window().setPosition(new Point(0, 0));518 driver.manage().window().setSize(new Dimension(width, length));519 }520 private String getScreenSize(WebDriver driver) {521 return driver.manage().window().getSize().width + "*" + driver.manage().window().getSize().height;522 }523 private static String getBaseUrl(String host, String port) {524 String baseurl = "";525 if (!StringUtil.isNullOrEmpty(host) && (host.contains("https://") || host.contains("http://"))) {526 baseurl = host;527 } else {528 baseurl = "http://" + host;529 }530 if (!StringUtil.isNullOrEmpty(port) && Integer.valueOf(port) > 0) {531 baseurl += ":" + port;532 }533 return baseurl;534 }...

Full Screen

Full Screen

getScreenSize

Using AI Code Generation

copy

Full Screen

1package org.cerberus.crud.entity;2import java.awt.Dimension;3import java.awt.Toolkit;4public class Robot {5 public static void main(String[] args) {6 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();7 System.out.println("Screen Size = " + screenSize);8 }9}

Full Screen

Full Screen

getScreenSize

Using AI Code Generation

copy

Full Screen

1package org.cerberus.crud.entity;2import java.awt.Dimension;3import java.awt.Toolkit;4public class Robot {5 public static void main(String[] args) {6 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();7 System.out.println(d);8 }9}

Full Screen

Full Screen

getScreenSize

Using AI Code Generation

copy

Full Screen

1package org.cerberus.crud.entity;2import java.awt.Dimension;3import java.awt.Toolkit;4{5 public static void main(String[] args)6 {7 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();8 double width = screenSize.getWidth();9 double height = screenSize.getHeight();10 System.out.println("width = " + width);

Full Screen

Full Screen

getScreenSize

Using AI Code Generation

copy

Full Screen

1import java.awt.Dimension;2import java.awt.Robot;3import java.awt.Toolkit;4import java.awt.event.InputEvent;5import java.awt.event.KeyEvent;6public class 3 {7 public static void main(String[] args) throws Exception {8 Robot robot = new Robot();9 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();10 System.out.println(d);11 robot.mousePress(InputEvent.BUTTON1_MASK);12 robot.mouseRelease(InputEvent.BUTTON1_MASK);

Full Screen

Full Screen

getScreenSize

Using AI Code Generation

copy

Full Screen

1import java.awt.Dimension;2import java.awt.Toolkit;3import javax.swing.JFrame;4import javax.swing.JLabel;5import javax.swing.JPanel;6public class Robot extends JFrame {7 public Robot() {8 JPanel panel = new JPanel();9 JLabel label = new JLabel("Robot");10 label.setBounds(10, 10, 100, 100);11 panel.add(label);12 add(panel);13 setSize(400, 400);14 setVisible(true);15 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);16 }17 public static void main(String[] args) {18 Robot frame = new Robot();19 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();20 frame.setLocation((int) screenSize.getWidth() / 2 - frame.getWidth() / 2, (int) screenSize.getHeight() / 2 - frame.getHeight() / 2);21 }22}

Full Screen

Full Screen

getScreenSize

Using AI Code Generation

copy

Full Screen

1import java.awt.Dimension;2import java.awt.Toolkit;3import javax.swing.JFrame;4import javax.swing.JLabel;5import javax.swing.JPanel;6public class Robot extends JFrame {7 public Robot() {8 JPanel panel = new JPanel();9 JLabel label = new JLabel("Robot");10 label.setBounds(10, 10, 100, 100);11 panel.add(label);12 add(panel);13 setSize(400, 400);14 setVisible(true);15 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);16 }17 public static void main(String[] args) {18 Robot frame = new Robot();19 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();20 frame.setLocation((int) screenSize.getWidth() / 2 - frame.getWidth() / 2, (int) screenSize.getHeight() / 2 - frame.getHeight() / 2);21 }22}

Full Screen

Full Screen

getScreenSize

Using AI Code Generation

copy

Full Screen

1import java.awt.*;2import java.awt.event.*;3import java.util.*;4import org.cerberus.crud.entity.Robot;5{6 Button b1;7 TextField t1;8 TextArea ta;

Full Screen

Full Screen

getScreenSize

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.Robot;2import java.awt.Dimension;3import java.awt.Point;4import java.awt.Toolkit;5import java.util.logging.Level;6import java. il.logging.Logger;7 pblic class 3 extends javax.swing.JFrame {8 Robot robot;9 Dimension dimension;10 Point point;11 Toolkit toolkit;12 public 3() {13 robot = new Robot();14 toolkit = Toolkit.getDefaultToolkit();15 dimension = toolkit.getScreenSize();16 point = new Point(0, 0);17 setSize(dimension);18 setLocation(point);19 setUndecorated(true);20 setVisible(true);21 setAlwaysOnTop(true);22 setResizable(true);23 setExtendedState(MAXIMIZED_BOTH);24 initComponents();25 }26 private void initComponents() {27 jButton1 = new javax.swing.JButton();28 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);29 jButton1.setText("jButton1");30 jButton1.addActionListener(new java.awt.event.ActionListener() {31 public void actionPerformed(java.awt.event.ActionEvent evt) {32 jButton1ActionPerformed(evt);33 }34 });35 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());36 getContentPane().setLayout(layout);37 layout.setHorizontalGroup(38 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)39 .addGroup(layout.createSequentialGroup()40 .addGap(145, 145, 145)41 .addComponent(jButton1)42 .addContainerGap(162, Short.MAX_VALUE))43 );44 layout.setVerticalGroup(45 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)46 .addGroup(layout.createSequentialGroup()47 .addGap(98, 98, 98)48 .blic 3()49 {50 b1=new Button("Click");51 t1=new TextField(20);52 ta=new TextArea(10,20);53 add(t1);54 add(b1);55 add(ta);56 b1.addActionListener(this);57 setLayout(new FlowLayout());58 }59 public void actionPerformed(ActionEvent e)60 {61 if(e.getSource()==b1)62 {63 Robot r=new Robot();64 Dimension d=r.getScreenSize();65 t1.setText("Height is "+d.height+" and width is "+d.width);66 }67 }68 public static void main(String args[])69 {70 3 f=new 3();71 f.setSize(400,400);72 f.setVisible(true);73 }74}

Full Screen

Full Screen

getScreenSize

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.Robot;2import java.awt.Dimension;3import java.awt.Point;4import java.awt.Toolkit;5import java.util.logging.Level;6import java.util.logging.Logger;7public class 3 extends javax.swing.JFrame {8 Robot robot;9 Dimension dimension;10 Point point;11 Toolkit toolkit;12 public 3() {13 robot = new Robot();14 toolkit = Toolkit.getDefaultToolkit();15 dimension = toolkit.getScreenSize();16 point = new Point(0, 0);17 setSize(dimension);18 setLocation(point);19 setUndecorated(true);20 setVisible(true);21 setAlwaysOnTop(true);22 setResizable(true);23 setExtendedState(MAXIMIZED_BOTH);24 initComponents();25 }26 private void initComponents() {27 jButton1 = new javax.swing.JButton();28 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);29 jButton1.setText("jButton1");30 jButton1.addActionListener(new java.awt.event.ActionListener() {31 public void actionPerformed(java.awt.event.ActionEvent evt) {32 jButton1ActionPerformed(evt);33 }34 });35 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());36 getContentPane().setLayout(layout);37 layout.setHorizontalGroup(38 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)39 .addGroup(layout.createSequentialGroup()40 .addGap(145, 145, 145)41 .addComponent(jButton1)42 .addContainerGap(162, Short.MAX_VALUE))43 );44 layout.setVerticalGroup(45 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)46 .addGroup(layout.createSequentialGroup()47 .addGap(98, 98, 98)

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful