How to use postC method of io.appium.java_client.MobileCommand class

Best io.appium code snippet using io.appium.java_client.MobileCommand.postC

DriverFactory.java

Source:DriverFactory.java Github

copy

Full Screen

...56import java.nio.file.Paths;57import java.util.Arrays;58import java.util.HashMap;59import java.util.Map;60import static io.appium.java_client.MobileCommand.postC;61/**62 * Factory that creates web driver.63 *64 * @author PhungDucKien65 * @since 2018.05.0466 */67public class DriverFactory {68 /**69 * Creates context aware web driver for an environment.70 *71 * @param environment the environment72 * @param project the project73 * @param testRunConfig the test run config74 * @return the context aware web driver75 * @throws IOException the io exception76 */77 public RemoteWebDriver createDriver(Environment environment, Project project, TestRunConfig testRunConfig) throws IOException {78 RemoteWebDriver webDriver = null;79 if (environment instanceof PcEnvironment) {80 webDriver = createPcDriver((PcEnvironment) environment, project, testRunConfig);81 } else if (environment instanceof MobileEnvironment) {82 webDriver = createMobileDriver((MobileEnvironment) environment, project, testRunConfig);83 }84 return webDriver;85 }86 /**87 * Creates web driver for the PC environment.88 *89 * @param environment the environment90 * @param project the project91 * @param testRunConfig the test run config92 * @return the PC web driver93 * @throws IOException the io exception94 */95 private RemoteWebDriver createPcDriver(PcEnvironment environment, Project project, TestRunConfig testRunConfig) throws IOException {96 boolean isLocalHost = isLocalHost(testRunConfig);97 if (isLocalHost) {98 ensurePcDriverDownloaded(environment);99 }100 RemoteWebDriver webDriver = null;101 switch (environment.getBrowser()) {102 case CHROME:103 webDriver = createChromeDriver(environment, project, testRunConfig);104 break;105 case FIREFOX:106 webDriver = createFirefoxDriver(environment, project, testRunConfig);107 break;108 case IE:109 webDriver = createInternetExplorerDriver(environment, testRunConfig);110 break;111 case EDGE:112 webDriver = createEdgeDriver(environment, testRunConfig);113 break;114 case SAFARI:115 webDriver = createSafariDriver(environment, testRunConfig);116 break;117 case OPERA:118 webDriver = createOperaDriver(environment, testRunConfig);119 break;120 }121 if (!isLocalHost && webDriver != null) {122 webDriver.setFileDetector(new LocalFileDetector());123 }124 return webDriver;125 }126 /**127 * Creates web driver for the mobile environment.128 *129 * @param environment the environment130 * @param project the project131 * @param testRunConfig the test run config132 * @return the mobile web driver133 * @throws MalformedURLException the malformed URL exception134 */135 private AppiumDriver createMobileDriver(MobileEnvironment environment, Project project, TestRunConfig testRunConfig) throws MalformedURLException {136 AppiumDriver appiumDriver = null;137 switch (environment.getPlatform()) {138 case ANDROID:139 appiumDriver = createAndroidDriver(environment, project, testRunConfig);140 break;141 case IOS:142 appiumDriver = createIOSDriver(environment, project, testRunConfig);143 break;144 }145 return appiumDriver;146 }147 /**148 * Creates web driver for Chrome browser.149 *150 * @param environment the environment151 * @param project the project152 * @param testRunConfig the test run config153 * @return the Chrome web driver154 */155 private RemoteWebDriver createChromeDriver(PcEnvironment environment, Project project, TestRunConfig testRunConfig) throws MalformedURLException {156 boolean isLocalHost = isLocalHost(testRunConfig);157 Path downloadPath = project.getBasePath() != null && project.getDownloadPath() != null ?158 project.getBasePath().resolve(project.getDownloadPath()) : project.getDownloadPath();159 ChromeOptions chromeOptions = new ChromeOptions();160 Map<String, Object> chromePrefs = new HashMap<>();161 if (isLocalHost && downloadPath != null) {162 chromePrefs.put("download.default_directory", downloadPath.toFile().getAbsolutePath());163 }164 chromePrefs.put("download.prompt_for_download", "false");165 chromePrefs.put("download.directory_upgrade", "true");166 chromeOptions.setExperimentalOption("prefs", chromePrefs);167 chromeOptions.setExperimentalOption("excludeSwitches", Arrays.asList("test-type", "ignore-certificate-errors"));168 if (testRunConfig != null) {169 chromeOptions.setHeadless(testRunConfig.isHeadless());170 }171 if (isLocalHost) {172 System.setProperty("webdriver.chrome.driver", getPcDriverPath(environment));173 return new ChromeDriver(chromeOptions);174 } else {175 return new RemoteWebDriver(getServerAddress(environment, testRunConfig), chromeOptions);176 }177 }178 /**179 * Creates web driver for Firefox browser.180 *181 * @param environment the environment182 * @param project the project183 * @param testRunConfig the test run config184 * @return the Firefox web driver185 */186 private RemoteWebDriver createFirefoxDriver(PcEnvironment environment, Project project, TestRunConfig testRunConfig) throws MalformedURLException {187 boolean isLocalHost = isLocalHost(testRunConfig);188 Path downloadPath = project.getBasePath() != null && project.getDownloadPath() != null ?189 project.getBasePath().resolve(project.getDownloadPath()) : project.getDownloadPath();190 FirefoxProfile firefoxProfile = new FirefoxProfile();191 firefoxProfile.setPreference("browser.startup.homepage", "about:blank");192 firefoxProfile.setPreference("browser.startup.homepage_override.mstone", "ignore");193 firefoxProfile.setPreference("startup.homepage_welcome_url", "about:blank");194 firefoxProfile.setPreference("startup.homepage_welcome_url.additional", "about:blank");195 firefoxProfile.setPreference("browser.download.folderList", 2);196 if (isLocalHost && downloadPath != null) {197 firefoxProfile.setPreference("browser.download.dir", downloadPath.toFile().getAbsolutePath());198 }199// firefoxProfile.setPreference("browser.download.manager.showWhenStarting", "false");200 firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");201 FirefoxOptions firefoxOptions = new FirefoxOptions();202 firefoxOptions.setCapability("marionette", true);203 firefoxOptions.setCapability("firefox_profile", firefoxProfile);204// firefoxOptions.setCapability("unexpectedAlertBehaviour", UnexpectedAlertBehaviour.IGNORE);205 if (testRunConfig != null) {206 firefoxOptions.setHeadless(testRunConfig.isHeadless());207 }208 if (isLocalHost) {209 System.setProperty("webdriver.gecko.driver", getPcDriverPath(environment));210 return new FirefoxDriver(firefoxOptions);211 } else {212 return new RemoteWebDriver(getServerAddress(environment, testRunConfig), firefoxOptions);213 }214 }215 /**216 * Creates web driver for Internet Explorer browser.217 *218 * @param environment the environment219 * @param testRunConfig the test run config220 * @return the Internet Explorer web driver221 */222 private RemoteWebDriver createInternetExplorerDriver(PcEnvironment environment, TestRunConfig testRunConfig) throws MalformedURLException {223 boolean isLocalHost = isLocalHost(testRunConfig);224 InternetExplorerOptions ieOptions = new InternetExplorerOptions();225 ieOptions.setCapability("ignoreProtectedModeSettings", true);226 ieOptions.setCapability("unexpectedAlertBehaviour", UnexpectedAlertBehaviour.IGNORE);227 if (isLocalHost) {228 System.setProperty("webdriver.ie.driver", getPcDriverPath(environment));229 return new InternetExplorerDriver(ieOptions);230 } else {231 return new RemoteWebDriver(getServerAddress(environment, testRunConfig), ieOptions);232 }233 }234 /**235 * Creates web driver for Microsoft Edge browser.236 *237 * @param environment the environment238 * @param testRunConfig the test run config239 * @return the Microsoft Edge web driver240 */241 private RemoteWebDriver createEdgeDriver(PcEnvironment environment, TestRunConfig testRunConfig) throws MalformedURLException {242 boolean isLocalHost = isLocalHost(testRunConfig);243 EdgeOptions edgeOptions = new EdgeOptions();244 if (isLocalHost) {245 System.setProperty("webdriver.edge.driver", getPcDriverPath(environment));246 return new EdgeDriver(edgeOptions);247 } else {248 return new RemoteWebDriver(getServerAddress(environment, testRunConfig), edgeOptions);249 }250 }251 /**252 * Creates web driver for Opera browser.253 *254 * @param environment the environment255 * @param testRunConfig the test run config256 * @return the Opera web driver257 */258 private RemoteWebDriver createOperaDriver(PcEnvironment environment, TestRunConfig testRunConfig) throws MalformedURLException {259 boolean isLocalHost = isLocalHost(testRunConfig);260 OperaOptions operaOptions = new OperaOptions();261 if (isLocalHost) {262 System.setProperty("webdriver.opera.driver", getPcDriverPath(environment));263 return new OperaDriver(operaOptions);264 } else {265 return new RemoteWebDriver(getServerAddress(environment, testRunConfig), operaOptions);266 }267 }268 /**269 * Creates web driver for Safari browser.270 *271 * @param environment the environment272 * @param testRunConfig the test run config273 * @return the Safari web driver274 */275 private RemoteWebDriver createSafariDriver(PcEnvironment environment, TestRunConfig testRunConfig) throws MalformedURLException {276 boolean isLocalHost = isLocalHost(testRunConfig);277 SafariOptions safariOptions = new SafariOptions();278 if (isLocalHost) {279 // Safari 10+ included Apple's SafariDriver280 return new SafariDriver(safariOptions);281 } else {282 return new RemoteWebDriver(getServerAddress(environment, testRunConfig), safariOptions);283 }284 }285 /**286 * Creates web driver for Android platform.287 *288 * @param environment the environment289 * @param project the project290 * @param testRunConfig the test run config291 * @return the Android driver292 * @throws MalformedURLException the malformed URL exception293 */294 private AndroidDriver createAndroidDriver(MobileEnvironment environment, Project project, TestRunConfig testRunConfig) throws MalformedURLException {295 DesiredCapabilities desiredCapabilities = new DesiredCapabilities();296 desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);297 if (StringUtils.isNotBlank(environment.getPlatformVersion())) {298 desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, environment.getPlatformVersion());299 }300 desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, StringUtils.isBlank(environment.getDeviceName()) ? "Android" : environment.getDeviceName());301 String udid = testRunConfig.getUdid();302 if (StringUtils.isBlank(udid)) {303 udid = environment.getUdid();304 }305 if (StringUtils.isBlank(udid)) {306 udid = "auto";307 }308 desiredCapabilities.setCapability(MobileCapabilityType.UDID, udid);309 if (environment instanceof MobileWebEnvironment) {310 desiredCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ((MobileWebEnvironment) environment).getBrowser().getText());311 } else if (environment instanceof MobileAppEnvironment) {312 String appPath = ((MobileAppEnvironment) environment).getAppPath();313 if (StringUtils.isNotBlank(appPath)) {314 if (StringUtils.startsWith(appPath, "http") || StringUtils.startsWith(appPath, "/")) {315 desiredCapabilities.setCapability(MobileCapabilityType.APP, appPath);316 } else {317 FileServer fileServer = FileServer.getInstance();318 if (fileServer != null) {319 Path appFile = Paths.get(fileServer.getServerUrl()).resolve(project.getAppPath()).resolve(appPath);320 desiredCapabilities.setCapability(MobileCapabilityType.APP, appFile.toAbsolutePath().toString());321 } else {322 Path appFilePath = project.getBasePath() != null && project.getAppPath() != null ?323 project.getBasePath().resolve(project.getAppPath()).resolve(appPath) : project.getAppPath().resolve(appPath);324 File appFile = appFilePath.toFile();325 desiredCapabilities.setCapability(MobileCapabilityType.APP, appFile.getAbsolutePath());326 }327 }328 }329 desiredCapabilities.setCapability(AndroidMobileCapabilityType.DONT_STOP_APP_ON_RESET, true);330 if (StringUtils.isNotBlank(((MobileAppEnvironment) environment).getAppActivity())) {331 desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ((MobileAppEnvironment) environment).getAppActivity());332 }333 if (StringUtils.isNotBlank(((MobileAppEnvironment) environment).getAppPackage())) {334 desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, ((MobileAppEnvironment) environment).getAppPackage());335 }336 if (StringUtils.isNotBlank(((MobileAppEnvironment) environment).getAppWaitActivity())) {337 desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_WAIT_ACTIVITY, ((MobileAppEnvironment) environment).getAppWaitActivity());338 }339 if (StringUtils.isNotBlank(((MobileAppEnvironment) environment).getAppWaitPackage())) {340 desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_WAIT_PACKAGE, ((MobileAppEnvironment) environment).getAppWaitPackage());341 }342 }343 desiredCapabilities.setCapability(MobileCapabilityType.NO_RESET, true);344 desiredCapabilities.setCapability(MobileCapabilityType.FULL_RESET, false);345 desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);346 return new AndroidDriver(new AppiumCommandExecutor(getCommandRepository(), getServerAddress(environment, testRunConfig)), desiredCapabilities);347 }348 /**349 * Creates web driver for iOS platform.350 *351 * @param environment the environment352 * @param project the project353 * @param testRunConfig the test run config354 * @return the iOS driver355 * @throws MalformedURLException the malformed URL exception356 */357 private IOSDriver createIOSDriver(MobileEnvironment environment, Project project, TestRunConfig testRunConfig) throws MalformedURLException {358 DesiredCapabilities desiredCapabilities = new DesiredCapabilities();359 desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS);360 if (StringUtils.isNotBlank(environment.getPlatformVersion())) {361 desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, environment.getPlatformVersion());362 }363 desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, StringUtils.isBlank(environment.getDeviceName()) ? "iPhone" : environment.getDeviceName());364 String udid = testRunConfig.getUdid();365 if (StringUtils.isBlank(udid)) {366 udid = environment.getUdid();367 }368 if (StringUtils.isBlank(udid)) {369 udid = "auto";370 }371 desiredCapabilities.setCapability(MobileCapabilityType.UDID, udid);372 if (environment instanceof MobileWebEnvironment) {373 desiredCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ((MobileWebEnvironment) environment).getBrowser().getText());374 desiredCapabilities.setCapability(IOSMobileCapabilityType.SAFARI_INITIAL_URL, ((MobileWebEnvironment) environment).getBaseUrl());375 desiredCapabilities.setCapability(IOSMobileCapabilityType.SAFARI_ALLOW_POPUPS, true);376 desiredCapabilities.setCapability(IOSMobileCapabilityType.NATIVE_WEB_TAP, true);377 } else if (environment instanceof MobileAppEnvironment) {378 String appPath = ((MobileAppEnvironment) environment).getAppPath();379 if (StringUtils.isNotBlank(appPath)) {380 if (StringUtils.startsWith(appPath, "http") || StringUtils.startsWith(appPath, "/")) {381 desiredCapabilities.setCapability(MobileCapabilityType.APP, appPath);382 } else {383 FileServer fileServer = FileServer.getInstance();384 if (fileServer != null) {385 Path appFile = Paths.get(fileServer.getServerUrl()).resolve(project.getAppPath()).resolve(appPath);386 desiredCapabilities.setCapability(MobileCapabilityType.APP, appFile.toAbsolutePath().toString());387 } else {388 Path appFilePath = project.getBasePath() != null && project.getAppPath() != null ?389 project.getBasePath().resolve(project.getAppPath()).resolve(appPath) : project.getAppPath().resolve(appPath);390 File appFile = appFilePath.toFile();391 desiredCapabilities.setCapability(MobileCapabilityType.APP, appFile.getAbsolutePath());392 }393 }394 }395 if (StringUtils.isNotBlank(((MobileAppEnvironment) environment).getBundleId())) {396 desiredCapabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID, ((MobileAppEnvironment) environment).getBundleId());397 }398 }399 desiredCapabilities.setCapability(MobileCapabilityType.NO_RESET, true);400 desiredCapabilities.setCapability(MobileCapabilityType.FULL_RESET, false);401 desiredCapabilities.setCapability(IOSMobileCapabilityType.ALLOW_TOUCHID_ENROLL, true);402 // For iOS 9.3 or higher403 desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);404 // For testing on real devices405 String xcodeConfigFile = System.getProperty(IOSMobileCapabilityType.XCODE_CONFIG_FILE);406 if (StringUtils.isBlank(xcodeConfigFile)) {407 xcodeConfigFile = System.getenv("XCODE_CONFIG_FILE");408 }409 if (StringUtils.isNotBlank(xcodeConfigFile)) {410 desiredCapabilities.setCapability(IOSMobileCapabilityType.XCODE_CONFIG_FILE, xcodeConfigFile);411 } else {412 desiredCapabilities.setCapability(IOSMobileCapabilityType.XCODE_CONFIG_FILE, System.getProperty("user.home") + File.separator + ".xcconfig");413 }414 String updatedWDABundleId = System.getProperty(IOSMobileCapabilityType.UPDATE_WDA_BUNDLEID);415 if (StringUtils.isBlank(updatedWDABundleId)) {416 updatedWDABundleId = System.getenv("UPDATE_WDA_BUNDLEID");417 }418 if (StringUtils.isNotBlank(updatedWDABundleId)) {419 desiredCapabilities.setCapability(IOSMobileCapabilityType.UPDATE_WDA_BUNDLEID, updatedWDABundleId);420 }421 return new IOSDriver(new AppiumCommandExecutor(getCommandRepository(), getServerAddress(environment, testRunConfig)), desiredCapabilities);422 }423 /**424 * Get remote server address.425 *426 * @param environment the environment427 * @param testRunConfig the test run config428 * @return the remote server address429 * @throws MalformedURLException the malformed URL exception430 */431 private URL getServerAddress(Environment environment, TestRunConfig testRunConfig) throws MalformedURLException {432 boolean isLocalHost = isLocalHost(testRunConfig);433 String remoteHost = isLocalHost ? "localhost" : testRunConfig.getRemoteHost();434 String remotePort = isLocalHost ? "" : testRunConfig.getRemotePort();435 if (StringUtils.isBlank(remotePort)) {436 if (environment instanceof PcEnvironment) {437 remotePort = "4444";438 } else {439 remotePort = String.valueOf(AppiumServiceBuilder.DEFAULT_APPIUM_PORT);440 }441 }442 return new URL("http://" + remoteHost + ":" + remotePort + "/wd/hub");443 }444 /**445 * Ensure that the PC web driver is downloaded.446 * This method tries to download the driver if the driver does not exist.447 *448 * @param environment the environment449 * @throws IOException the io exception450 */451 private void ensurePcDriverDownloaded(PcEnvironment environment) throws IOException {452 String driverPath = getPcDriverPath(environment);453 File driverFile = new File(driverPath);454 if (!driverFile.exists()) {455 DriverDownloader downloader = new DriverDownloader();456 downloader.downloadPcDriver(environment, driverPath);457 }458 }459 /**460 * Get the PC web driver local path461 *462 * @param environment the environment463 * @return the PC web driver local path464 */465 private String getPcDriverPath(PcEnvironment environment) {466 String appHome = System.getProperty("app.home");467 if (StringUtils.isBlank(appHome)) {468 appHome = System.getProperty("user.dir");469 }470 String driverPath = appHome + File.separator + "driver" + File.separator + environment.getBrowser().name().toLowerCase();471 if (driverPath.matches("^[a-zA-Z]:\\\\")) {472 driverPath += ".exe";473 }474 return driverPath;475 }476 private boolean isLocalHost(TestRunConfig testRunConfig) {477 return testRunConfig == null478 || StringUtils.isBlank(testRunConfig.getRemoteHost());479 }480 private Map<String, CommandInfo> getCommandRepository() {481 Map<String, CommandInfo> commands = new HashMap<>(MobileCommand.commandRepository);482 commands.put(DriverCommand.SUBMIT_ELEMENT, postC("/session/:sessionId/element/:id/submit"));483 return commands;484 }485}...

Full Screen

Full Screen

AppiumDriver.java

Source:AppiumDriver.java Github

copy

Full Screen

...181 case GET:182 MobileCommand.commandRepository.put(methodName, MobileCommand.getC(url));183 break;184 case POST:185 MobileCommand.commandRepository.put(methodName, MobileCommand.postC(url));186 break;187 case DELETE:188 MobileCommand.commandRepository.put(methodName, MobileCommand.deleteC(url));189 break;190 default:191 throw new WebDriverException(String.format("Unsupported HTTP Method: %s. Only %s methods are supported",192 httpMethod,193 Arrays.toString(HttpMethod.values())));194 }195 ((AppiumCommandExecutor) getCommandExecutor()).refreshAdditionalCommands();196 }197 public URL getRemoteAddress() {198 return remoteAddress;199 }...

Full Screen

Full Screen

MobileCommand.java

Source:MobileCommand.java Github

copy

Full Screen

...64 protected static final String REPLACE_VALUE = "replaceValue";65 public static final Map<String, CommandInfo> commandRepository = createCommandRepository();66 private static Map<String, CommandInfo> createCommandRepository() {67 HashMap<String, CommandInfo> result = new HashMap<String, CommandInfo>();68 result.put(RESET, postC("/session/:sessionId/appium/app/reset"));69 result.put(GET_STRINGS, postC("/session/:sessionId/appium/app/strings"));70 result.put(SET_VALUE, postC("/session/:sessionId/appium/element/:id/value"));71 result.put(PULL_FILE, postC("/session/:sessionId/appium/device/pull_file"));72 result.put(PULL_FOLDER, postC("/session/:sessionId/appium/device/pull_folder"));73 result.put(HIDE_KEYBOARD, postC("/session/:sessionId/appium/device/hide_keyboard"));74 result.put(RUN_APP_IN_BACKGROUND, postC("/session/:sessionId/appium/app/background"));75 result.put(PERFORM_TOUCH_ACTION, postC("/session/:sessionId/touch/perform"));76 result.put(PERFORM_MULTI_TOUCH, postC("/session/:sessionId/touch/multi/perform"));77 result.put(IS_APP_INSTALLED, postC("/session/:sessionId/appium/device/app_installed"));78 result.put(INSTALL_APP, postC("/session/:sessionId/appium/device/install_app"));79 result.put(REMOVE_APP, postC("/session/:sessionId/appium/device/remove_app"));80 result.put(LAUNCH_APP, postC("/session/:sessionId/appium/app/launch"));81 result.put(CLOSE_APP, postC("/session/:sessionId/appium/app/close"));82 result.put(LOCK, postC("/session/:sessionId/appium/device/lock"));83 result.put(COMPLEX_FIND, postC("/session/:sessionId/appium/app/complex_find"));84 result.put(GET_SETTINGS, getC("/session/:sessionId/appium/settings"));85 result.put(SET_SETTINGS, postC("/session/:sessionId/appium/settings"));86 result.put(GET_DEVICE_TIME, getC("/session/:sessionId/appium/device/system_time"));87 result.put(GET_SESSION,getC("/session/:sessionId/"));88 //iOS89 result.put(SHAKE, postC("/session/:sessionId/appium/device/shake"));90 //Android91 result.put(CURRENT_ACTIVITY,92 getC("/session/:sessionId/appium/device/current_activity"));93 result.put(END_TEST_COVERAGE,94 postC("/session/:sessionId/appium/app/end_test_coverage"));95 result.put(GET_NETWORK_CONNECTION, getC("/session/:sessionId/network_connection"));96 result.put(IS_LOCKED, postC("/session/:sessionId/appium/device/is_locked"));97 result.put(LONG_PRESS_KEY_CODE,98 postC("/session/:sessionId/appium/device/long_press_keycode"));99 result.put(OPEN_NOTIFICATIONS,100 postC("/session/:sessionId/appium/device/open_notifications"));101 result.put(PRESS_KEY_CODE,102 postC("/session/:sessionId/appium/device/press_keycode"));103 result.put(PUSH_FILE, postC("/session/:sessionId/appium/device/push_file"));104 result.put(SET_NETWORK_CONNECTION,105 postC("/session/:sessionId/network_connection"));106 result.put(START_ACTIVITY,107 postC("/session/:sessionId/appium/device/start_activity"));108 result.put(TOGGLE_LOCATION_SERVICES,109 postC("/session/:sessionId/appium/device/toggle_location_services"));110 result.put(UNLOCK, postC("/session/:sessionId/appium/device/unlock"));111 result.put(REPLACE_VALUE, postC("/session/:sessionId/appium/element/:id/replace_value"));112 return result;113 }114 /**115 * This methods forms GET commands.116 *117 * @param url is the command URL118 * @return an instance of {@link org.openqa.selenium.remote.CommandInfo}119 */120 public static CommandInfo getC(String url) {121 return new CommandInfo(url, HttpMethod.GET);122 }123 /**124 * This methods forms POST commands.125 *126 * @param url is the command URL127 * @return an instance of {@link org.openqa.selenium.remote.CommandInfo}128 */129 public static CommandInfo postC(String url) {130 return new CommandInfo(url, HttpMethod.POST);131 }132 /**133 * This methods forms DELETE commands.134 *135 * @param url is the command URL136 * @return an instance of {@link org.openqa.selenium.remote.CommandInfo}137 */138 public static CommandInfo deleteC(String url) {139 return new CommandInfo(url, HttpMethod.DELETE);140 }141 /**142 * @param param is a parameter name.143 * @param value is the parameter value....

Full Screen

Full Screen

postC

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.MobileCommand;2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.android.AndroidElement;4import io.appium.java_client.remote.MobileCapabilityType;5import org.openqa.selenium.remote.DesiredCapabilities;6import java.net.URL;7import java.util.HashMap;8import java.util.Map;9public class AppiumTest {10public static void main(String[] args) throws Exception {11DesiredCapabilities capabilities = new DesiredCapabilities();12capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");13capabilities.setCapability(MobileCapabilityType.APP, "D:\\Appium\\ApiDemos-debug.apk");14capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "100");

Full Screen

Full Screen

postC

Using AI Code Generation

copy

Full Screen

1MobileCommand command = new MobileCommand("postC");2command.setName("find");3command.setParameter("strategy", "name");4command.setParameter("selector", "some name");5command.setParameter("context", "NATIVE_APP");6command.setParameter("multiple", true);7command.setParameter("enabled", true);8command.setParameter("sessionId", "some session id");9command.setParameter("id", "some id");10command.setParameter("value", "some value");11command.setParameter("name", "some name");12command.setParameter("className", "some class name");13command.setParameter("tagName", "some tag name");14command.setParameter("linkText", "some link text");15command.setParameter("partialLinkText", "some partial link text");16command.setParameter("xpath", "some xpath");17command.setParameter("cssSelector", "some css selector");18command.setParameter("using", "some using");19command.setParameter("value", "some value");20command.setParameter("element", "some element");21command.setParameter("id", "some id");

Full Screen

Full Screen

postC

Using AI Code Generation

copy

Full Screen

1 public void postC(String commandName, Object value) {2 execute(MobileCommand.POST_C, ImmutableMap.of("command", commandName, "elementId", getId(), "params", value));3 }4 public void postC(String commandName, Object value) {5 execute(MobileCommand.POST_C, ImmutableMap.of("command", commandName, "elementId", getId(), "params", value));6 }7 public void postC(String commandName, Object value) {8 execute(MobileCommand.POST_C, ImmutableMap.of("command", commandName, "elementId", getId(), "params", value));9 }10 public void postC(String commandName, Object value) {11 execute(MobileCommand.POST_C, ImmutableMap.of("command", commandName, "elementId", getId(), "params", value));12 }13 public void postC(String commandName, Object value) {14 execute(MobileCommand.POST_C, ImmutableMap.of("command", commandName, "elementId", getId(), "params", value));15 }16 public void postC(String commandName, Object value) {17 execute(MobileCommand.POST_C, ImmutableMap.of("command", commandName, "elementId", getId(), "params", value));18 }19 public void postC(String commandName, Object value) {20 execute(MobileCommand.POST_C, ImmutableMap.of("command", commandName, "elementId", getId(), "params", value));21 }22 public void postC(String commandName, Object value) {23 execute(MobileCommand.POST_C, ImmutableMap.of("

Full Screen

Full Screen

postC

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.MobileCommand;2import io.appium.java_client.MobileElement;3import io.appium.java_client.android.AndroidDriver;4import io.appium.java_client.android.AndroidElement;5import io.appium.java_client.remote.MobileCapabilityType;6import java.net.MalformedURLException;7import java.net.URL;8import java.util.HashMap;9import java.util.Map;10import java.util.concurrent.TimeUnit;11import org.openqa.selenium.remote.DesiredCapabilities;12public class Appium {13 public static void main(String[] args) throws MalformedURLException {14 DesiredCapabilities cap = new DesiredCapabilities();15 cap.setCapability(MobileCapabilityType.DEVICE_NAME,"Android Device");16 cap.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");17 cap.setCapability(MobileCapabilityType.BROWSER_NAME,"Chrome");

Full Screen

Full Screen

postC

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebElement;3import org.openqa.selenium.remote.DesiredCapabilities;4import org.openqa.selenium.remote.RemoteWebElement;5import org.openqa.selenium.remote.Response;6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.support.ui.WebDriverWait;8import io.appium.java_client.AppiumDriver;9import io.appium.java_client.MobileCommand;10import io.appium.java_client.android.AndroidDriver;11import io.appium.java_client.remote.MobileCapabilityType;12import java.net.MalformedURLException;13import java.net.URL;14import java.util.HashMap;15import java.util.List;16import java.util.Map;17public class ScrollTo {18 public static void main(String[] args) throws MalformedURLException, InterruptedException {19 DesiredCapabilities caps = new DesiredCapabilities();20 caps.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");21 caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");22 caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "6.0");23 caps.setCapability(MobileCapabilityType.APP, "D:\\appium\\ApiDemos-debug.apk");

Full Screen

Full Screen

postC

Using AI Code Generation

copy

Full Screen

1package appium;2import java.io.File;3import java.io.IOException;4import java.io.InputStream;5import java.net.URL;6import java.util.List;7import java.util.concurrent.TimeUnit;8import org.apache.commons.io.FileUtils;9import org.openqa.selenium.By;10import org.openqa.selenium.OutputType;11import org.openqa.selenium.TakesScreenshot;12import org.openqa.selenium.WebDriver;13import org.openqa.selenium.WebElement;14import org.openqa.selenium.remote.DesiredCapabilities;15import org.openqa.selenium.support.ui.ExpectedConditions;16import org.openqa.selenium.support.ui.WebDriverWait;17import io.appium.java_client.AppiumDriver;18import io.appium.java_client.MobileCommand;19import io.appium.java_client.MobileElement;20import io.appium.java_client.android.AndroidDriver;21import io.appium.java_client.android.AndroidKeyCode;22public class AppiumJava {23public static void main(String[] args) throws IOException, InterruptedException {24DesiredCapabilities caps = new DesiredCapabilities();25caps.setCapability("deviceName", "Android Emulator");26caps.setCapability("udid", "emulator-5554");27caps.setCapability("platformName", "Android");28caps.setCapability("platformVersion", "9");29caps.setCapability("appPackage", "com.android.calculator2");30caps.setCapability("appActivity", "com.android.calculator2.Calculator");31caps.setCapability("noReset", "true");32AppiumDriver<MobileElement> driver = null;33try {

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