Best io.appium code snippet using io.appium.java_client.LocksDevice.lockDevice
pureDrivers.java
Source:pureDrivers.java
...1746 // ********************************************************************************************************************************************************1747 // AndroidDriver [131] = public default java.util.List<T> io.appium.java_client.FindsByAndroidUIAutomator.findElementsByAndroidUIAutomator(java.lang.String)1748 1749 // ********************************************************************************************************************************************************1750 // AndroidDriver [132] = public default void io.appium.java_client.LocksDevice.lockDevice()1751 public void lockDevice() {1752 pureDriverDetails currentDriver = getCurrentDriverDetails();1753 pureCore.callMethod( currentDriver.mainDriver, currentDriver.mainDriver.getClass(), "lockDevice", (Class<?>)null,1754 currentDriver.mainDriver.getClass().toString(), (Object)null );1755 }1756 1757 // ********************************************************************************************************************************************************1758 // AndroidDriver [133] = public default void io.appium.java_client.LocksDevice.lockDevice(java.time.Duration)1759 1760 // ********************************************************************************************************************************************************1761 // AndroidDriver [134] = public default void io.appium.java_client.LocksDevice.unlockDevice()1762 public void unlockDevice() {1763 pureDriverDetails currentDriver = getCurrentDriverDetails();1764 pureCore.callMethod( currentDriver.mainDriver, currentDriver.mainDriver.getClass(), "unlockDevice", (Class<?>)null,1765 currentDriver.mainDriver.getClass().toString(), (Object)null );1766 }1767 1768 // ********************************************************************************************************************************************************1769 // AndroidDriver [135] = public default boolean io.appium.java_client.LocksDevice.isDeviceLocked()1770 public boolean isDeviceLocked() {1771 pureDriverDetails currentDriver = getCurrentDriverDetails();1772 return (boolean)pureCore.callMethod( currentDriver.mainDriver, currentDriver.mainDriver.getClass(), "isDeviceLocked", (Class<?>)null,1773 currentDriver.mainDriver.getClass().toString(), (Object)null );1774 }1775 1776 // ********************************************************************************************************************************************************1777 // AndroidDriver [136] = public default void io.appium.java_client.android.HasAndroidSettings.configuratorSetWaitForIdleTimeout(java.time.Duration)1778 ...
RobotServerService.java
Source:RobotServerService.java
...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) {...
TestSearchAndAddToCart.java
Source:TestSearchAndAddToCart.java
...16 17 @Test18 public void ScreenOrientation()19 {20 ((LocksDevice) driver).lockDevice();21 ((LocksDevice) driver).unlockDevice();22 driver.rotate(ScreenOrientation.LANDSCAPE);2324 driver.rotate(ScreenOrientation.PORTRAIT);25 }26 27 @Test(priority=1)28 public void Search01() throws InterruptedException29 {30 s1=new SearchAndAddToCart(driver);31 WebElement we=s1.search;32 WebDriverWait wait=new WebDriverWait(driver, 30);33 wait.until(ExpectedConditions.visibilityOf(we));34 //tapping on search text box35 we.click();
...
MobileDevice.java
Source:MobileDevice.java
...32 public static ScreenOrientation getOrientation() {33 return executeDriverMethod(AppiumDriver.class,34 (Function<AppiumDriver, ScreenOrientation>) AppiumDriver::getOrientation);35 }36 public static void lockDevice() {37 executeDriverMethod(LocksDevice.class, (Consumer<LocksDevice>) LocksDevice::lockDevice);38 }39 public static void lockDevice(Duration duration) {40 executeDriverMethod(LocksDevice.class, (LocksDevice driver) -> driver.lockDevice(duration));41 }42 public static void unlockDevice() {43 executeDriverMethod(LocksDevice.class, LocksDevice::unlockDevice);44 }45 public static boolean isLocked() {46 return executeDriverMethod(LocksDevice.class, LocksDevice::isDeviceLocked);47 }48 public static BatteryInfo getBatteryInfo() {49 WebDriver driver = getDriver();50 if (driver instanceof IOSDriver) {51 return ((IOSDriver) driver).getBatteryInfo();52 } else if (driver instanceof AndroidDriver) {53 return ((AndroidDriver) driver).getBatteryInfo();54 } else {55 throw exception("This method is not supported by the driver. The driver needs to be the instance of either Ios or Android driver");56 }57 }...
Activity2_3.java
Source:Activity2_3.java
...44 45 46 /*47 * if (((AndroidDriver) driver).isDeviceLocked()) ((AndroidDriver)48 * driver).unlockDevice(); else ((AndroidDriver) driver).lockDevice();49 */ 50 51 //((AndroidDriver) driver).unlockDevice();52 //Runtime.getRuntime().exec("adb shell am start -n io.appium.unlock/.Unlock");53 54 // Click on add new contact floating button55 //unlockDevice();56 57 // ((AndroidDriver) driver).unlockDevice();58 Thread.sleep(5000);59 driver.findElementById("android:id/icon").click();60 Thread.sleep(5000);61 // Find the first name, last name, and phone number fields62 MobileElement firstName = driver.findElementByXPath("//android.widget.EditText[@text='First name']");63 MobileElement lastName = driver.findElementByXPath("//android.widget.EditText[@text='Surname']");64 MobileElement phoneNumber = driver.findElementByXPath("//android.widget.EditText[@text='Phone']");65 66 // Enter the text in the fields67 firstName.sendKeys("Aaditya");68 lastName.sendKeys("Varma");69 phoneNumber.sendKeys("9991284782");70 71 // Save the contact...
webview.java
Source:webview.java
...67 }68 69 @Test70 public void lock() {71 ((LocksDevice) driver).lockDevice();72 System.out.println(((LocksDevice) driver).isDeviceLocked());73 ((LocksDevice) driver).unlockDevice();74 75 }76 77 78 79 }80 ...
NetworkDemo.java
Source:NetworkDemo.java
...25 26 27 //Lock a device28 29 ((LocksDevice) driver).lockDevice();30 31 Thread.sleep(2000);32 33 34 ((LocksDevice) driver).unlockDevice();35 36 37 ((AndroidDriver<MobileElement>) driver).openNotifications();38 39 Thread.sleep(2000);40 41 driver.rotate(ScreenOrientation.LANDSCAPE);42 43 44 Thread.sleep(2000);45 46 driver.rotate(ScreenOrientation.PORTRAIT);47 48 // it tell you if wifi is enabled or not...
LocksDevice.java
Source:LocksDevice.java
...14 * limitations under the License.15 */16package io.appium.java_client;17import static io.appium.java_client.MobileCommand.getIsDeviceLockedCommand;18import static io.appium.java_client.MobileCommand.lockDeviceCommand;19import static io.appium.java_client.MobileCommand.unlockDeviceCommand;20import java.time.Duration;21public interface LocksDevice extends ExecutesMethod {22 /**23 * This method locks a device. It will return silently if the device24 * is already locked.25 */26 default void lockDevice() {27 lockDevice(Duration.ofSeconds(0));28 }29 /**30 * Lock the device (bring it to the lock screen) for a given number of31 * seconds or forever (until the command for unlocking is called). The call32 * is ignored if the device has been already locked.33 *34 * @param duration for how long to lock the screen. Minimum time resolution is one second.35 * A negative/zero value will lock the device and return immediately.36 */37 default void lockDevice(Duration duration) {38 CommandExecutionHelper.execute(this, lockDeviceCommand(duration));39 }40 /**41 * Unlock the device if it is locked. This method will return silently if the device42 * is not locked.43 */44 default void unlockDevice() {45 CommandExecutionHelper.execute(this, unlockDeviceCommand());46 }47 /**48 * Check if the device is locked.49 *50 * @return true if the device is locked or false otherwise.51 */52 default boolean isDeviceLocked() {53 return CommandExecutionHelper.execute(this, getIsDeviceLockedCommand());54 }55}...
lockDevice
Using AI Code Generation
1driver.lockDevice();2driver.unlockDevice();3driver.isLocked();4driver.openNotifications();5driver.toggleWiFi();6driver.toggleData();7driver.toggleAirplaneMode();8driver.toggleLocationServices();9driver.toggleWiFi();10driver.toggleData();11driver.toggleAirplaneMode();12driver.toggleLocationServices();13driver.toggleWiFi();14driver.toggleData();15driver.toggleAirplaneMode();16driver.toggleLocationServices();17driver.toggleWiFi();18driver.toggleData();19driver.toggleAirplaneMode();20driver.toggleLocationServices();21driver.toggleWiFi();22driver.toggleData();
lockDevice
Using AI Code Generation
1package appium;2import java.net.MalformedURLException;3import java.net.URL;4import org.openqa.selenium.By;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.remote.DesiredCapabilities;7import io.appium.java_client.android.AndroidDriver;8import io.appium.java_client.remote.MobileCapabilityType;9public class LockDevice {10 public static void main(String[] args) throws MalformedURLException, InterruptedException {11 DesiredCapabilities cap = new DesiredCapabilities();12 cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Nexus_5X_API_25");13 cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");14 cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1.1");15 cap.setCapability(MobileCapabilityType.APP, "C:\\Users\\Sushma\\Desktop\\Appium\\ApiDemos-debug.apk");
lockDevice
Using AI Code Generation
1driver.lockDevice();2driver.unlockDevice();3driver.runAppInBackground(1);4driver.isLocked();5driver.openNotifications();6driver.pressKeyCode(1);7driver.pressKeyCode(1, 1);8driver.pressKeyCode(1, 1, 1);9driver.pressKeyCode(1, 1, 1, 1);10driver.pressKeyCode(1, 1, 1, 1, 1);11driver.pressKeyCode(1, 1, 1, 1, 1, 1);12driver.rotate(ScreenOrientation.LANDSCAPE);13driver.rotate(ScreenOrientation.LANDSCAPE, 1);14driver.rotate(ScreenOrientation.LANDSCAPE, 1, 1);15driver.rotate(ScreenOrientation.LANDSCAPE, 1,
lockDevice
Using AI Code Generation
1package appium;2import java.net.MalformedURLException;3import java.net.URL;4import org.openqa.selenium.By;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.remote.DesiredCapabilities;7import org.testng.annotations.Test;8import io.appium.java_client.AppiumDriver;9import io.appium.java_client.android.AndroidDriver;10import io.appium.java_client.remote.MobileCapabilityType;11public class LockDevice {12 public void lockDevice() throws MalformedURLException, InterruptedException {13 DesiredCapabilities capabilities = new DesiredCapabilities();14 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");15 capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");16 capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "8.1.0");17 capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "25");18 capabilities.setCapability("appPackage", "com.android.settings");19 capabilities.setCapability("appActivity", "com.android.settings.Settings");
lockDevice
Using AI Code Generation
1package com.appium.test;2import java.net.MalformedURLException;3import java.net.URL;4import java.util.concurrent.TimeUnit;5import org.openqa.selenium.By;6import org.openqa.selenium.remote.DesiredCapabilities;7import io.appium.java_client.android.AndroidDriver;8import io.appium.java_client.android.AndroidElement;9public class LockDeviceTest {10public static void main(String[] args) throws MalformedURLException, InterruptedException {11 DesiredCapabilities cap = new DesiredCapabilities();12 cap.setCapability("deviceName", "Android Emulator");13 cap.setCapability("platformName", "Android");14 cap.setCapability("platformVersion", "7.1.1");15 cap.setCapability("appPackage", "com.android.contacts");16 cap.setCapability("appActivity", "com.android.contacts.activities.PeopleActivity");17 cap.setCapability("noReset", true);18 cap.setCapability("automationName", "uiautomator2");
lockDevice
Using AI Code Generation
1package appium.java;2import java.net.MalformedURLException;3import java.net.URL;4import org.openqa.selenium.remote.DesiredCapabilities;5import io.appium.java_client.AppiumDriver;6import io.appium.java_client.android.AndroidDriver;7import io.appium.java_client.remote.MobileCapabilityType;8public class LockDevice {9public static void main(String[] args) throws MalformedURLException {10DesiredCapabilities capabilities = new DesiredCapabilities();11capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Nexus 5");12capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");13capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1.1");14capabilities.setCapability(MobileCapabilityType.APP, "C:\\Users\\Saurabh\\Downloads\\APK\\com.android.calculator2.apk");
lockDevice
Using AI Code Generation
1import io.appium.java_client.LocksDevice;2import io.appium.java_client.AppiumDriver;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.remote.DesiredCapabilities;5import java.net.URL;6import java.net.MalformedURLException;7import java.util.concurrent.TimeUnit;8import org.openqa.selenium.WebElement;9import org.openqa.selenium.By;10import org.openqa.selenium.remote.RemoteWebElement;11import org.openqa.selenium.remote.RemoteExecuteMethod;12import org.openqa.selenium.remote.RemoteWebDriver;13import java.util.concurrent.TimeUnit;14import java.util.List;15public class appium {16 public static void main(String[] args) {17 DesiredCapabilities capabilities = new DesiredCapabilities();18 capabilities.setCapability("deviceName", "Android Emulator");19 capabilities.setCapability("browserName", "Android");20 capabilities.setCapability("platformVersion", "4.4.2");21 capabilities.setCapability("platformName", "Android");22 capabilities.setCapability("app-package", "com.android.settings");23 capabilities.setCapability("app-activity", ".Settings");
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!!