Skip to content

Commit 37f5ed3

Browse files
authored
enable nativeWebTap setting for iOS (#658)
* enable nativeWebTap setting for iOS * add tests for nativeWebTap method * make javadoc happy * conform to style
1 parent 59b0ff2 commit 37f5ed3

File tree

12 files changed

+182
-52
lines changed

12 files changed

+182
-52
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/**
2121
* This enum is deprecated. Was moved to
22-
* {@link io.appium.java_client.android.Setting}.
22+
* {@link io.appium.java_client.Setting}.
2323
*/
2424
@Deprecated
2525
public enum AppiumSetting {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client;
18+
19+
import static io.appium.java_client.MobileCommand.getSettingsCommand;
20+
import static io.appium.java_client.MobileCommand.setSettingsCommand;
21+
22+
import com.google.common.collect.ImmutableMap;
23+
24+
import org.openqa.selenium.remote.Response;
25+
26+
import java.util.Map;
27+
28+
29+
public interface HasSettings extends ExecutesMethod {
30+
31+
/**
32+
* Set a setting for this test session It's probably better to use a
33+
* convenience function, rather than use this function directly. Try finding
34+
* the method for the specific setting you want to change.
35+
*
36+
* @param setting Setting you wish to set.
37+
* @param value value of the setting.
38+
*/
39+
default void setSetting(Setting setting, Object value) {
40+
CommandExecutionHelper.execute(this, setSettingsCommand(setting, value));
41+
}
42+
43+
/**
44+
* Get settings stored for this test session It's probably better to use a
45+
* convenience function, rather than use this function directly. Try finding
46+
* the method for the specific setting you want to read.
47+
*
48+
* @return JsonObject, a straight-up hash of settings.
49+
*/
50+
@SuppressWarnings("unchecked")
51+
default Map<String, Object> getSettings() {
52+
Map.Entry<String, Map<String, ?>> keyValuePair = getSettingsCommand();
53+
Response response = execute(keyValuePair.getKey(), keyValuePair.getValue());
54+
55+
return ImmutableMap.<String, Object>builder()
56+
.putAll(Map.class.cast(response.getValue())).build();
57+
}
58+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,13 @@ public static ImmutableMap<String, Object> prepareArguments(String[] params,
354354
return new AbstractMap.SimpleEntry<>(
355355
LOCK, prepareArguments("seconds", duration.getSeconds()));
356356
}
357+
358+
public static Map.Entry<String, Map<String, ?>> getSettingsCommand() {
359+
return new AbstractMap.SimpleEntry<>(GET_SETTINGS, ImmutableMap.<String, Object>of());
360+
}
361+
362+
public static Map.Entry<String, Map<String, ?>> setSettingsCommand(Setting setting, Object value) {
363+
return new AbstractMap.SimpleEntry<>(SET_SETTINGS, prepareArguments("settings",
364+
prepareArguments(setting.toString(), value)));
365+
}
357366
}

src/main/java/io/appium/java_client/android/Setting.java renamed to src/main/java/io/appium/java_client/Setting.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.appium.java_client.android;
17+
package io.appium.java_client;
1818

1919
/**
2020
* Enums defining constants for Appium Settings which can be set and toggled during a test session.
@@ -26,7 +26,8 @@ public enum Setting {
2626
WAIT_FOR_SELECTOR_TIMEOUT("setWaitForSelectorTimeout"),
2727
WAIT_SCROLL_ACKNOWLEDGMENT_TIMEOUT("setScrollAcknowledgmentTimeout"),
2828
WAIT_ACTION_ACKNOWLEDGMENT_TIMEOUT("setActionAcknowledgmentTimeout"),
29-
KEY_INJECTION_DELAY("setKeyInjectionDelay");
29+
KEY_INJECTION_DELAY("setKeyInjectionDelay"),
30+
NATIVE_WEB_TAP("nativeWebTap");
3031

3132
private String name;
3233

src/main/java/io/appium/java_client/android/AndroidDriver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
public class AndroidDriver<T extends WebElement>
4848
extends AppiumDriver<T>
4949
implements PressesKeyCode, HasNetworkConnection, PushesFiles, StartsActivity,
50-
FindsByAndroidUIAutomator<T>, LocksAndroidDevice, HasSettings, HasDeviceDetails,
50+
FindsByAndroidUIAutomator<T>, LocksAndroidDevice, HasAndroidSettings, HasDeviceDetails,
5151
HasSupportedPerformanceDataType {
5252

5353
private static final String ANDROID_PLATFORM = MobilePlatform.ANDROID;

src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,4 @@ public class AndroidMobileCommandHelper extends MobileCommand {
355355
return new AbstractMap.SimpleEntry<>(
356356
REPLACE_VALUE, prepareArguments(parameters, values));
357357
}
358-
359-
public static Map.Entry<String, Map<String, ?>> getSettingsCommand() {
360-
return new AbstractMap.SimpleEntry<>(GET_SETTINGS, ImmutableMap.<String, Object>of());
361-
}
362-
363-
public static Map.Entry<String, Map<String, ?>> setSettingsCommand(Setting setting, Object value) {
364-
return new AbstractMap.SimpleEntry<>(SET_SETTINGS, prepareArguments("settings",
365-
prepareArguments(setting.toString(), value)));
366-
}
367358
}

src/main/java/io/appium/java_client/android/HasSettings.java renamed to src/main/java/io/appium/java_client/android/HasAndroidSettings.java

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

1717
package io.appium.java_client.android;
1818

19-
import static io.appium.java_client.android.AndroidMobileCommandHelper.getSettingsCommand;
20-
import static io.appium.java_client.android.AndroidMobileCommandHelper.setSettingsCommand;
2119

22-
import com.google.common.collect.ImmutableMap;
23-
24-
import io.appium.java_client.CommandExecutionHelper;
25-
import io.appium.java_client.ExecutesMethod;
26-
27-
import org.openqa.selenium.remote.Response;
20+
import io.appium.java_client.HasSettings;
21+
import io.appium.java_client.Setting;
2822

2923
import java.time.Duration;
30-
import java.util.Map;
31-
32-
interface HasSettings extends ExecutesMethod {
33-
/**
34-
* Set a setting for this test session It's probably better to use a
35-
* convenience function, rather than use this function directly. Try finding
36-
* the method for the specific setting you want to change.
37-
*
38-
* @param setting Setting you wish to set.
39-
* @param value value of the setting.
40-
*/
41-
default void setSetting(Setting setting, Object value) {
42-
CommandExecutionHelper.execute(this, setSettingsCommand(setting, value));
43-
}
44-
45-
/**
46-
* Get settings stored for this test session It's probably better to use a
47-
* convenience function, rather than use this function directly. Try finding
48-
* the method for the specific setting you want to read.
49-
*
50-
* @return JsonObject, a straight-up hash of settings.
51-
*/
52-
@SuppressWarnings("unchecked")
53-
default Map<String, Object> getSettings() {
54-
Map.Entry<String, Map<String, ?>> keyValuePair = getSettingsCommand();
55-
Response response = execute(keyValuePair.getKey(), keyValuePair.getValue());
56-
57-
return ImmutableMap.<String, Object>builder()
58-
.putAll(Map.class.cast(response.getValue())).build();
59-
}
6024

25+
interface HasAndroidSettings extends HasSettings {
6126
/**
6227
* Set the `ignoreUnimportantViews` setting. *Android-only method*.
6328
* Sets whether Android devices should use `setCompressedLayoutHeirarchy()`
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.ios;
18+
19+
20+
import io.appium.java_client.HasSettings;
21+
import io.appium.java_client.Setting;
22+
23+
interface HasIOSSettings extends HasSettings {
24+
/**
25+
* Set the `nativeWebTap` setting. *iOS-only method*.
26+
* Sets whether Safari/webviews should convert element taps into x/y taps
27+
* @param enabled turns nativeWebTap on if true, off if false
28+
*/
29+
default void nativeWebTap(Boolean enabled) {
30+
setSetting(Setting.NATIVE_WEB_TAP, enabled);
31+
}
32+
}

src/main/java/io/appium/java_client/ios/IOSDriver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
*/
5252
public class IOSDriver<T extends WebElement>
5353
extends AppiumDriver<T>
54-
implements HidesKeyboardWithKeyName, ShakesDevice,
54+
implements HidesKeyboardWithKeyName, ShakesDevice, HasIOSSettings,
5555
FindsByIosUIAutomation<T>, LocksIOSDevice, PerformsTouchID, FindsByIosNSPredicate<T>,
5656
FindsByIosClassChain<T> {
5757

src/test/java/io/appium/java_client/android/SettingTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.junit.Assert.assertEquals;
44

5+
import io.appium.java_client.Setting;
56
import org.junit.Test;
67

78
import java.time.Duration;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.ios;
18+
19+
import io.appium.java_client.remote.AutomationName;
20+
import io.appium.java_client.remote.IOSMobileCapabilityType;
21+
import io.appium.java_client.remote.MobileCapabilityType;
22+
import io.appium.java_client.service.local.AppiumDriverLocalService;
23+
import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException;
24+
import org.junit.BeforeClass;
25+
import org.openqa.selenium.remote.DesiredCapabilities;
26+
27+
public class BaseSafariTest extends BaseIOSTest {
28+
29+
@BeforeClass public static void beforeClass() throws Exception {
30+
service = AppiumDriverLocalService.buildDefaultService();
31+
service.start();
32+
33+
if (service == null || !service.isRunning()) {
34+
throw new AppiumServerHasNotBeenStartedLocallyException("An appium server node is not started!");
35+
}
36+
37+
DesiredCapabilities capabilities = new DesiredCapabilities();
38+
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari");
39+
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);
40+
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.2");
41+
//sometimes environment has performance problems
42+
capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000);
43+
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator");
44+
driver = new IOSDriver<>(service.getUrl(), capabilities);
45+
}
46+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.appium.java_client.ios;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.junit.Test;
6+
import org.openqa.selenium.WebElement;
7+
8+
public class IOSNativeWebTapSettingTest extends BaseSafariTest {
9+
10+
@Test public void nativeWebTapSettingTest() throws InterruptedException {
11+
driver.get("https://saucelabs.com/test/guinea-pig");
12+
13+
// do a click with nativeWebTap turned on, and assert we get to the right page
14+
driver.nativeWebTap(true);
15+
WebElement el = driver.findElementById("i am a link");
16+
el.click();
17+
assertEquals(true, driver.getTitle().contains("I am another page title"));
18+
driver.navigate().back();
19+
20+
// now do a click with it turned off and assert the same behavior
21+
assertEquals(true, driver.getTitle().contains("I am a page title"));
22+
driver.nativeWebTap(false);
23+
el = driver.findElementById("i am a link");
24+
el.click();
25+
assertEquals(true, driver.getTitle().contains("I am another page title"));
26+
}
27+
}

0 commit comments

Comments
 (0)