Skip to content

Commit 265bea8

Browse files
Merge pull request #532 from TikhomirovSergey/master
JsonToMobileElementConverter re-design
2 parents ffc36db + 6f69389 commit 265bea8

File tree

67 files changed

+848
-804
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+848
-804
lines changed

src/main/java/io/appium/java_client/AppiumDriver.java

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.google.common.collect.ImmutableMap;
2222

23+
import io.appium.java_client.internal.JsonToMobileElementConverter;
2324
import io.appium.java_client.remote.AppiumCommandExecutor;
2425
import io.appium.java_client.remote.MobileCapabilityType;
2526
import io.appium.java_client.service.local.AppiumDriverLocalService;
@@ -39,14 +40,11 @@
3940
import org.openqa.selenium.remote.ErrorHandler;
4041
import org.openqa.selenium.remote.ExecuteMethod;
4142
import org.openqa.selenium.remote.HttpCommandExecutor;
42-
import org.openqa.selenium.remote.RemoteWebDriver;
4343
import org.openqa.selenium.remote.Response;
4444
import org.openqa.selenium.remote.html5.RemoteLocationContext;
4545
import org.openqa.selenium.remote.http.HttpClient;
4646
import org.openqa.selenium.remote.internal.JsonToWebElementConverter;
4747

48-
import java.lang.reflect.Constructor;
49-
import java.lang.reflect.InvocationTargetException;
5048
import java.net.URL;
5149
import java.util.LinkedHashSet;
5250
import java.util.List;
@@ -80,74 +78,54 @@ public class AppiumDriver<T extends WebElement>
8078
* commands may be specified there.
8179
* @param capabilities take a look
8280
* at {@link org.openqa.selenium.Capabilities}
83-
* @param converterClazz is an instance of a class that extends
84-
* {@link org.openqa.selenium.remote.internal.JsonToWebElementConverter}. It converts
85-
* JSON response to an instance of
86-
* {@link org.openqa.selenium.WebElement}
8781
*/
88-
protected AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities,
89-
Class<? extends JsonToWebElementConverter> converterClazz) {
82+
protected AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities) {
9083
super(executor, capabilities);
9184
this.executeMethod = new AppiumExecutionMethod(this);
9285
locationContext = new RemoteLocationContext(executeMethod);
9386
super.setErrorHandler(errorHandler);
9487
this.remoteAddress = executor.getAddressOfRemoteServer();
95-
try {
96-
Constructor<? extends JsonToWebElementConverter> constructor =
97-
converterClazz.getConstructor(RemoteWebDriver.class);
98-
this.setElementConverter(constructor.newInstance(this));
99-
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException
100-
| InvocationTargetException e) {
101-
throw new RuntimeException(e);
102-
}
88+
this.setElementConverter(new JsonToMobileElementConverter(this, getSessionDetails()));
10389
}
10490

105-
public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities,
106-
Class<? extends JsonToWebElementConverter> converterClazz) {
91+
public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) {
10792
this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress),
108-
desiredCapabilities, converterClazz);
93+
desiredCapabilities);
10994
}
11095

11196
public AppiumDriver(URL remoteAddress, HttpClient.Factory httpClientFactory,
112-
Capabilities desiredCapabilities,
113-
Class<? extends JsonToWebElementConverter> converterClazz) {
97+
Capabilities desiredCapabilities) {
11498
this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress,
115-
httpClientFactory), desiredCapabilities, converterClazz);
99+
httpClientFactory), desiredCapabilities);
116100
}
117101

118-
public AppiumDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities,
119-
Class<? extends JsonToWebElementConverter> converterClazz) {
102+
public AppiumDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) {
120103
this(new AppiumCommandExecutor(MobileCommand.commandRepository, service),
121-
desiredCapabilities, converterClazz);
104+
desiredCapabilities);
122105
}
123106

124107
public AppiumDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory,
125-
Capabilities desiredCapabilities,
126-
Class<? extends JsonToWebElementConverter> converterClazz) {
108+
Capabilities desiredCapabilities) {
127109
this(new AppiumCommandExecutor(MobileCommand.commandRepository, service, httpClientFactory),
128-
desiredCapabilities, converterClazz);
110+
desiredCapabilities);
129111
}
130112

131-
public AppiumDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities,
132-
Class<? extends JsonToWebElementConverter> converterClazz) {
133-
this(builder.build(), desiredCapabilities, converterClazz);
113+
public AppiumDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) {
114+
this(builder.build(), desiredCapabilities);
134115
}
135116

136117
public AppiumDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory,
137-
Capabilities desiredCapabilities,
138-
Class<? extends JsonToWebElementConverter> converterClazz) {
139-
this(builder.build(), httpClientFactory, desiredCapabilities, converterClazz);
118+
Capabilities desiredCapabilities) {
119+
this(builder.build(), httpClientFactory, desiredCapabilities);
140120
}
141121

142-
public AppiumDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities,
143-
Class<? extends JsonToWebElementConverter> converterClazz) {
122+
public AppiumDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {
144123
this(AppiumDriverLocalService.buildDefaultService(), httpClientFactory,
145-
desiredCapabilities, converterClazz);
124+
desiredCapabilities);
146125
}
147126

148-
public AppiumDriver(Capabilities desiredCapabilities,
149-
Class<? extends JsonToWebElementConverter> converterClazz) {
150-
this(AppiumDriverLocalService.buildDefaultService(), desiredCapabilities, converterClazz);
127+
public AppiumDriver(Capabilities desiredCapabilities) {
128+
this(AppiumDriverLocalService.buildDefaultService(), desiredCapabilities);
151129
}
152130

153131
/**

src/main/java/io/appium/java_client/AppiumSetting.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
package io.appium.java_client;
1818

19-
import io.appium.java_client.android.Setting;
2019

2120
/**
22-
* This enum is deprecated. Was moved to {@link Setting}
21+
* This enum is deprecated. Was moved to
22+
* {@link io.appium.java_client.android.Setting}.
2323
*/
2424
@Deprecated
2525
public enum AppiumSetting {

src/main/java/io/appium/java_client/FindsByAccessibilityId.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616

1717
package io.appium.java_client;
1818

19-
import org.openqa.selenium.WebDriverException;
2019
import org.openqa.selenium.WebElement;
2120

2221
import java.util.List;
2322

2423
public interface FindsByAccessibilityId<T extends WebElement> extends FindsByFluentSelector<T> {
2524
/**
26-
* @throws WebDriverException This method is not
25+
* @throws {@link org.openqa.selenium.WebDriverException} This method is not
2726
* applicable with browser/webview UI.
27+
* @throws {@link org.openqa.selenium.NoSuchElementException} when no one element is found
2828
*/
2929
default T findElementByAccessibilityId(String using) {
3030
return findElement(MobileSelector.ACCESSIBILITY.toString(), using);
3131
}
3232

3333
/**
34-
* @throws WebDriverException This method is not
34+
* @throws {@link org.openqa.selenium.WebDriverException} This method is not
3535
* applicable with browser/webview UI.
3636
*/
3737
default List<T> findElementsByAccessibilityId(String using) {

src/main/java/io/appium/java_client/FindsByAndroidUIAutomator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@
1616

1717
package io.appium.java_client;
1818

19-
import org.openqa.selenium.WebDriverException;
2019
import org.openqa.selenium.WebElement;
2120

2221
import java.util.List;
2322

2423
public interface FindsByAndroidUIAutomator<T extends WebElement> extends FindsByFluentSelector<T> {
2524

2625
/**
27-
* @throws WebDriverException This method is not
26+
* @throws {@link org.openqa.selenium.WebDriverException} This method is not
2827
* applicable with browser/webview UI.
28+
* @throws {@link org.openqa.selenium.NoSuchElementException} when no one element is found
2929
*/
3030
default T findElementByAndroidUIAutomator(String using) {
3131
return findElement(MobileSelector.ANDROID_UI_AUTOMATOR.toString(), using);
3232
}
3333

3434
/**
35-
* @throws WebDriverException This method is not
35+
* @throws {@link org.openqa.selenium.WebDriverException} This method is not
3636
* applicable with browser/webview UI.
3737
*/
3838
default List<T> findElementsByAndroidUIAutomator(String using) {

src/main/java/io/appium/java_client/FindsByFluentSelector.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package io.appium.java_client;
1818

19-
import org.openqa.selenium.NoSuchElementException;
20-
import org.openqa.selenium.WebDriverException;
2119
import org.openqa.selenium.WebElement;
2220

2321
import java.util.List;
@@ -32,11 +30,11 @@ public interface FindsByFluentSelector<T extends WebElement> {
3230
* @param using is a value of the given selector
3331
* @return the first found element
3432
*
35-
* @throws WebDriverException when current session doesn't support the given selector or when
36-
* value of the selector is not consistent.
37-
* @throws NoSuchElementException when no one element is found
33+
* @throws org.openqa.selenium.WebDriverException when current session doesn't
34+
* support the given selector or when value of the selector is not consistent.
35+
* @throws org.openqa.selenium.NoSuchElementException when no one element is found
3836
*/
39-
T findElement(String by, String using) throws WebDriverException, NoSuchElementException;
37+
T findElement(String by, String using);
4038

4139
/**
4240
* Method performs the searching for a list of elements by some selector defined by string
@@ -46,8 +44,8 @@ public interface FindsByFluentSelector<T extends WebElement> {
4644
* @param using is a value of the given selector
4745
* @return a list of elements
4846
*
49-
* @throws WebDriverException when current session doesn't support the given selector or when
50-
* value of the selector is not consistent.
47+
* @throws org.openqa.selenium.WebDriverException when current session doesn't support
48+
* the given selector or when value of the selector is not consistent.
5149
*/
52-
List<T> findElements(String by, String using) throws WebDriverException;
50+
List<T> findElements(String by, String using);
5351
}

src/main/java/io/appium/java_client/FindsByIosUIAutomation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616

1717
package io.appium.java_client;
1818

19-
import org.openqa.selenium.WebDriverException;
2019
import org.openqa.selenium.WebElement;
2120

2221
import java.util.List;
2322

2423
public interface FindsByIosUIAutomation<T extends WebElement> extends FindsByFluentSelector<T> {
2524
/**
26-
* @throws WebDriverException
25+
* @throws {@link org.openqa.selenium.WebDriverException}
2726
* This method is not applicable with browser/webview UI.
27+
* @throws {@link org.openqa.selenium.NoSuchElementException} when no one element is found
2828
*/
2929
default T findElementByIosUIAutomation(String using) {
3030
return findElement(MobileSelector.IOS_UI_AUTOMATION.toString(), using);
3131
}
3232

3333
/**
34-
* @throws WebDriverException
34+
* @throws {@link org.openqa.selenium.WebDriverException}
3535
* This method is not applicable with browser/webview UI.
3636
*/
3737
default List<T> findElementsByIosUIAutomation(String using) {

src/main/java/io/appium/java_client/FindsByWindowsAutomation.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public interface FindsByWindowsAutomation<T extends WebElement> extends FindsByF
2828
*
2929
* @param selector a Windows UIAutomation selector
3030
* @return The first element that matches the given selector
31+
* @throws {@link org.openqa.selenium.WebDriverException} This method is not
32+
* applicable with browser/webview UI.
33+
* @throws {@link org.openqa.selenium.NoSuchElementException} when no one element is found
3134
*/
3235
default T findElementByWindowsUIAutomation(String selector) {
3336
return findElement(MobileSelector.WINDOWS_UI_AUTOMATION.toString(), selector);
@@ -38,6 +41,8 @@ default T findElementByWindowsUIAutomation(String selector) {
3841
*
3942
* @param selector a Windows UIAutomation selector
4043
* @return a list of elements that match the given selector
44+
* @throws {@link org.openqa.selenium.WebDriverException} This method is not
45+
* applicable with browser/webview UI.
4146
*/
4247
default List<T> findElementsByWindowsUIAutomation(String selector) {
4348
return findElements(MobileSelector.WINDOWS_UI_AUTOMATION.toString(), selector);

src/main/java/io/appium/java_client/HidesKeyboardWithKeyName.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,22 @@
1616

1717
package io.appium.java_client;
1818

19-
import static io.appium.java_client.ios.IOSMobileCommandHelper.hideKeyboardCommand;
19+
20+
import static io.appium.java_client.MobileCommand.hideKeyboardCommand;
2021

2122
public interface HidesKeyboardWithKeyName extends HidesKeyboard {
2223

24+
/**
25+
* Hides the keyboard by pressing the button specified by keyName if it is
26+
* showing.
27+
*
28+
* @param keyName The button pressed by the mobile driver to attempt hiding the
29+
* keyboard.
30+
*/
31+
default void hideKeyboard(String keyName) {
32+
CommandExecutionHelper.execute(this, hideKeyboardCommand(keyName));
33+
}
34+
2335
/**
2436
* Hides the keyboard if it is showing. Hiding the keyboard often
2537
* depends on the way an app is implemented, no single strategy always

0 commit comments

Comments
 (0)