Best Cerberus-source code snippet using org.cerberus.engine.execution.impl.RobotServerService.setCapabilityBrowser
Source:RobotServerService.java
...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 }...
setCapabilityBrowser
Using AI Code Generation
1import org.cerberus.engine.execution.impl.RobotServerService;2import org.cerberus.engine.execution.impl.RobotServerServiceFactory;3def robotServerService = new RobotServerServiceFactory().createRobotServerService();4def capabilities = robotServerService.getCapabilities();5def browser = robotServerService.getCapabilityBrowser(capabilities);6log.info("Browser: " + browser);7import org.cerberus.engine.execution.impl.RobotServerService;8import org.cerberus.engine.execution.impl.RobotServerServiceFactory;9def robotServerService = new RobotServerServiceFactory().createRobotServerService();10def capabilities = robotServerService.getCapabilities();11def browser = robotServerService.getCapabilityBrowser(capabilities);12log.info("Browser: " + browser);13import org.cerberus.engine.execution.impl.RobotServerService;14import org.cerberus.engine.execution.impl.RobotServerServiceFactory;15def robotServerService = new RobotServerServiceFactory().createRobotServerService();16def capabilities = robotServerService.getCapabilities();17def browser = robotServerService.getCapabilityBrowser(capabilities);18log.info("Browser: " + browser);19import org.cerberus.engine.execution.impl.RobotServerService;20import org.cerberus.engine.execution.impl.RobotServerServiceFactory;21def robotServerService = new RobotServerServiceFactory().createRobotServerService();22def capabilities = robotServerService.getCapabilities();23def browser = robotServerService.getCapabilityBrowser(capabilities);24log.info("Browser: " + browser);25import org.cerberus.engine.execution.impl.RobotServerService;26import org.cerberus.engine.execution.impl.RobotServerServiceFactory;27def robotServerService = new RobotServerServiceFactory().createRobotServerService();28def capabilities = robotServerService.getCapabilities();29def browser = robotServerService.getCapabilityBrowser(capabilities);30log.info("Browser: " + browser);31import org.cerberus.engine.execution
setCapabilityBrowser
Using AI Code Generation
1import org.cerberus.engine.execution.impl.RobotServerService2import org.cerberus.engine.execution.impl.RobotServerService.setCapabilityBrowser3def capabilities = setCapabilityBrowser(browser)4import org.cerberus.engine.execution.impl.RobotServerService5import org.cerberus.engine.execution.impl.RobotServerService.setCapabilityBrowser6def capabilities = setCapabilityBrowser(browser)7def testScript() {8 def capabilities = setCapabilityBrowser(browser)9 driver.quit()10}11def testScript() {12 def capabilities = setCapabilityBrowser(browser)13 driver.quit()14}15def testScript() {16 def capabilities = setCapabilityBrowser(browser)17 driver.quit()18}19def testScript() {20 def capabilities = setCapabilityBrowser(browser)21 driver.quit()22}23def testScript() {24 def capabilities = setCapabilityBrowser(browser)25 driver.quit()26}27def testScript() {28 def capabilities = setCapabilityBrowser(browser)29 driver.get("
setCapabilityBrowser
Using AI Code Generation
1import org.cerberus.engine.execution.impl.RobotServerService;2RobotServerService robot = new RobotServerService();3robot.setCapabilityBrowser("firefox", "47.0", "windows 10");4robot.runTestCase("C:\\cerberus\\Cerberus1.1.12\\cerberus\\CerberusQA\\testcases\\demo\\demo.robot");5robot.runTestCase("C:\\cerberus\\Cerberus1.1.12\\cerberus\\CerberusQA\\testcases\\demo\\demo.robot", "C:\\cerberus\\Cerberus1.1.12\\cerberus\\CerberusQA\\testcases\\demo\\demo.properties");6robot.runTestCase("C:\\cerberus\\Cerberus1.1.12\\cerberus\\CerberusQA\\testcases\\demo\\demo.robot", "C:\\cerberus\\Cerberus1.1.12\\cerberus\\CerberusQA\\testcases\\demo\\demo.properties", "C:\\cerberus\\Cerberus1.1.12\\cerberus\\CerberusQA\\testcases\\demo\\demo.html");7robot.runTestCase("C:\\cerberus\\Cerberus1.1.12\\cerberus\\CerberusQA\\testcases\\demo\\demo.robot", "C:\\cerberus\\Cerberus1.1.12\\cerberus\\CerberusQA\\testcases\\demo\\demo.properties",
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!