From b27be8ea8bdfba5c6dffa9bed7473bd8b6f66b46 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sun, 31 Jul 2022 00:06:20 +0530 Subject: [PATCH] Fix gestures for latest appium 2 beta version (#6) * update command to start server with plugin * fix gestures for latest appium 2 beta version * bump new version --- .prettierrc.json | 4 ++++ README.md | 54 +++++++++++++++++++++---------------------- package-lock.json | 5 ++-- package.json | 2 +- src/gestures/swipe.js | 4 +--- src/sessionInfo.js | 2 +- 6 files changed, 37 insertions(+), 34 deletions(-) create mode 100644 .prettierrc.json diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..5ac85e2 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,4 @@ +{ + "printWidth": 100, + "singleQuote": true +} diff --git a/README.md b/README.md index d985a48..17f504c 100644 --- a/README.md +++ b/README.md @@ -19,16 +19,15 @@ appium plugin install --source=npm appium-gestures-plugin The plugin will not be active unless turned on when invoking the Appium server: ``` -appium --plugins=gestures +appium --use-plugins=gestures ``` # Drag and Drop test without plugin + ``` -MobileElement dragMe = (MobileElement) new WebDriverWait(driver, 30) - .until(elementToBeClickable(MobileBy.AccessibilityId("dragMe"))); +WebElement dragMe = wait.until(elementToBeClickable(AppiumBy.accessibilityId("dragMe"))); Point source = dragMe.getCenter(); -MobileElement dropzone = (MobileElement) new WebDriverWait(driver, 30) - .until(elementToBeClickable(MobileBy.AccessibilityId("dropzone"))); +WebElement dropzone = wait.until(elementToBeClickable(AppiumBy.accessibilityId("dropzone"))); Point target = dropzone.getCenter(); PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger"); Sequence dragNDrop = new Sequence(finger, 1); @@ -46,28 +45,29 @@ driver.perform(singletonList(dragNDrop)); # Usage # Drag and Drop + ``` -MobileElement source = (MobileElement) new WebDriverWait(driver, 30) - .until(elementToBeClickable(MobileBy.AccessibilityId("dragMe"))); -MobileElement destination = (MobileElement) new WebDriverWait(driver, 30) - .until(elementToBeClickable(MobileBy.AccessibilityId("dropzone"))); +RemoteWebElement source = (RemoteWebElement) wait + .until(elementToBeClickable(AppiumBy.accessibilityId("dragMe"))); +RemoteWebElement destination = (RemoteWebElement) wait + .until(elementToBeClickable(AppiumBy.accessibilityId("dropzone"))); -driver.addCommand(HttpMethod.POST, String.format("/session/%s/plugin/actions/dragAndDrop", - driver.getSessionId()), "dragAndDrop"); +driver.addCommand(HttpMethod.POST, String.format("/session/%s/plugin/actions/dragAndDrop", + driver.getSessionId()), "dragAndDrop"); driver.execute("dragAndDrop", ImmutableMap.of("sourceId", source.getId(), "destinationId", destination.getId())); ``` + # Horizontal Swipe + ``` -MobileElement source = (MobileElement) new WebDriverWait(driver, 30) - .until(elementToBeClickable(MobileBy.AccessibilityId("slider"))); +RemoteWebElement source = (RemoteWebElement) wait.until(elementToBeClickable(AppiumBy.accessibilityId("slider"))); +driver.addCommand(HttpMethod.POST, String.format("/session/%s/plugin/actions/swipe", driver.getSessionId()), "swipe"); -driver.addCommand(HttpMethod.POST, String.format("/session/%s/plugin/actions/swipe", - driver.getSessionId()), "swipe"); -driver.execute("dragAndDrop", ImmutableMap.of("elementId", source.getId(), "percentage", 50)); +driver.execute("swipe", ImmutableMap.of("elementId", source.getId(), "percentage", 50)); ``` -# WDIO +# WDIO ``` driver.addCommand( @@ -91,18 +91,18 @@ driver.addCommand( }) ); await driver.dragAndDrop(sourceId, destinationId); - + ``` -## Supported -* Horizontal Swipe -* Drag and Drop -### TODO +## Supported -* swipe vertically -* double click -* longpress -* zoom -* multi finger swipe +- Horizontal Swipe +- Drag and Drop +### TODO +- swipe vertically +- double click +- longpress +- zoom +- multi finger swipe diff --git a/package-lock.json b/package-lock.json index 8196cc5..e38c491 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,12 @@ { "name": "appium-gestures-plugin", - "version": "1.0.0-beta.3", + "version": "1.0.0-beta.4", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "1.0.0-beta.3", + "name": "appium-gestures-plugin", + "version": "1.0.0-beta.4", "license": "ISC", "dependencies": { "@appium/base-plugin": "^1.8.1", diff --git a/package.json b/package.json index 3175c4d..ad28c68 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "appium-gestures-plugin", - "version": "1.0.0-beta.3", + "version": "1.0.0-beta.4", "description": "", "main": "./lib/index.js", "scripts": { diff --git a/src/gestures/swipe.js b/src/gestures/swipe.js index 034c783..d0e4fd3 100644 --- a/src/gestures/swipe.js +++ b/src/gestures/swipe.js @@ -47,9 +47,7 @@ async function horizontalSwipe(elementId, percentage, driverInfo) { ], }; let actionsUrl = `${driverInfo.driverUrl}/actions`; - log.info( - `Performing Swipe ${actionsUrl} with ${JSON.stringify(actionsData)}` - ); + log.info(`Performing Swipe ${actionsUrl} with ${JSON.stringify(actionsData)}`); if (driverInfo.automationName === 'XCuiTest') { await post({ diff --git a/src/sessionInfo.js b/src/sessionInfo.js index 6b55a47..7375d00 100644 --- a/src/sessionInfo.js +++ b/src/sessionInfo.js @@ -11,7 +11,7 @@ export default function sessionInfo(driver) { driverUrl: `${baseUrl}/session/${jwProxySessionId}`, }; } else { - const baseUrl = `http://${driver.uiautomator2.host}:${driver.uiautomator2.systemPort}/wd/hub`; + const baseUrl = `http://${driver.uiautomator2.host}:${driver.uiautomator2.systemPort}`; const jwProxySessionId = driver.uiautomator2.jwproxy.sessionId; return { baseUrl,