Created
February 13, 2023 09:44
-
-
Save adelarcubs/2b855d2111ff279bce75b10d686542c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package appiumworkaround; | |
import io.appium.java_client.windows.WindowsDriver; | |
import java.io.IOException; | |
import java.net.URI; | |
import java.net.http.HttpClient; | |
import java.net.http.HttpRequest; | |
import java.net.http.HttpResponse; | |
import lombok.AccessLevel; | |
import lombok.NoArgsConstructor; | |
import lombok.extern.slf4j.Slf4j; | |
import org.openqa.selenium.remote.RemoteWebElement; | |
@Slf4j | |
@NoArgsConstructor(access = AccessLevel.PRIVATE) | |
public class AppiumWokaround { | |
private static AppiumWokaround appiumWokaround; | |
public static AppiumWokaround getInstance() { | |
if (appiumWokaround == null) { | |
appiumWokaround = new AppiumWokaround(); | |
} | |
return appiumWokaround; | |
} | |
private static void move(WindowsDriver driver, RemoteWebElement element) { | |
log.info(element.getId()); | |
String elementId = element.getId(); | |
String uri = String.format( | |
"%s/session/%s/moveto", | |
AppiumDriver.SERVER, driver.getSessionId().toString()); | |
String json = String.format("{\"element\":\"%s\"}", elementId); | |
AppiumWokaround.callRest(uri, HttpRequest.BodyPublishers.ofString(json)); | |
} | |
public void contextClick(WindowsDriver driver, RemoteWebElement element) { | |
AppiumWokaround.move(driver, element); | |
String uri = String.format( | |
"%s/session/%s/click", | |
AppiumDriver.SERVER, driver.getSessionId().toString()); | |
String json = String.format("{\"button\":2}"); | |
AppiumWokaround.callRest(uri, HttpRequest.BodyPublishers.ofString(json)); | |
} | |
public void doubleClick(WindowsDriver driver, RemoteWebElement element) { | |
AppiumWokaround.move(driver, element); | |
String uri = String.format( | |
"%s/session/%s/doubleClick", | |
AppiumDriver.SERVER, driver.getSessionId().toString()); | |
AppiumWokaround.callRest(uri, HttpRequest.BodyPublishers.noBody()); | |
} | |
private static void callRest(String uri, HttpRequest.BodyPublisher body) { | |
log.info("URI: {}", uri); | |
log.info("body: {}", body.toString()); | |
HttpClient httpClient = HttpClient.newHttpClient(); | |
HttpRequest request = HttpRequest.newBuilder() | |
.uri(URI.create(uri)) | |
.header("Content-Type", "application/json") | |
.POST(body) | |
.build(); | |
try { | |
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); | |
log.info("RETURN status code: {}", response.statusCode()); | |
log.info("RETURN: {}", response.body()); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} catch (InterruptedException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I want to impletement drag and drop etc.. can you please let me know all the supported endpoints like %s/session/%s/doubleClick. I have checked https://github.com/microsoft/WinAppDriver/blob/master/Docs/SupportedAPIs.md but there is no mention of drag and drop