11/*
2+ +Copyright 2014 Appium contributors
23 +Copyright 2014 Software Freedom Conservancy
34 +
45 +Licensed under the Apache License, Version 2.0 (the "License");
1617
1718package io .appium .java_client ;
1819
19-
2020import com .google .common .collect .ImmutableMap ;
2121import org .openqa .selenium .*;
2222import org .openqa .selenium .remote .*;
2727import java .util .Map ;
2828import java .util .Set ;
2929
30+ import static io .appium .java_client .MobileCommand .*;
31+
3032public class AppiumDriver extends RemoteWebDriver implements MobileDriver , ContextAware , FindsByIosUIAutomation ,
31- FindsByAndroidUIAutomator {
33+ FindsByAndroidUIAutomator , FindsByAccessibilityId {
3234
3335 private final MobileErrorHandler errorHandler = new MobileErrorHandler ();
3436
3537 public AppiumDriver (URL remoteAddress , Capabilities desiredCapabilities ){
3638
3739 super (remoteAddress , desiredCapabilities );
3840
39- ImmutableMap <String , CommandInfo > mobileCommands = ImmutableMap .<String , CommandInfo >of ();
41+ ImmutableMap .Builder <String , CommandInfo > builder = ImmutableMap .builder ();
42+ builder
43+ .put (RESET , postC ("/session/:sessionId/appium/app/reset" ))
44+ .put (GET_STRINGS , getC ("/session/:sessionId/appium/app/strings" ))
45+ .put (KEY_EVENT , postC ("/session/:sessionId/appium/device/keyevent" ))
46+ ;
47+ ImmutableMap <String , CommandInfo > mobileCommands = builder .build ();
4048
4149 HttpCommandExecutor mobileExecutor = new HttpCommandExecutor (mobileCommands , remoteAddress );
4250 super .setCommandExecutor (mobileExecutor );
@@ -61,6 +69,26 @@ protected Response execute(String command) {
6169 }
6270
6371
72+ public void resetApp () {
73+ execute (MobileCommand .RESET );
74+ }
75+
76+ public String getAppStrings () {
77+ Response response = execute (GET_STRINGS );
78+ return response .getValue ().toString ();
79+ }
80+
81+ public void sendKeyEvent (int key ) {
82+ sendKeyEvent (key , null );
83+ }
84+
85+ public void sendKeyEvent (int key , Integer metastate ) {
86+ ImmutableMap .Builder builder = ImmutableMap .builder ();
87+ builder .put ("keycode" , key );
88+ if (metastate != null ) { builder .put ("metastate" , metastate ); }
89+ ImmutableMap <String , Integer > parameters = builder .build ();
90+ execute (KEY_EVENT , parameters );
91+ }
6492
6593
6694 @ Override
@@ -114,4 +142,26 @@ public WebElement findElementByAndroidUIAutomator(String using) {
114142 public List <WebElement > findElementsByAndroidUIAutomator (String using ) {
115143 return findElements ("-android uiautomator" , using );
116144 }
145+
146+ @ Override
147+ public WebElement findElementByAccessibilityId (String using ) {
148+ return findElement ("accessibility id" , using );
149+ }
150+
151+ @ Override
152+ public List <WebElement > findElementsByAccessibilityId (String using ) {
153+ return findElements ("accessibility id" , using );
154+ }
155+
156+ private static CommandInfo getC (String url ) {
157+ return new CommandInfo (url , HttpVerb .GET );
158+ }
159+
160+ private static CommandInfo postC (String url ) {
161+ return new CommandInfo (url , HttpVerb .POST );
162+ }
163+
164+ private static CommandInfo deleteC (String url ) {
165+ return new CommandInfo (url , HttpVerb .DELETE );
166+ }
117167}
0 commit comments