Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable nativeWebTap setting for iOS #658

Merged
merged 4 commits into from
Jun 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/io/appium/java_client/AppiumSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/**
* This enum is deprecated. Was moved to
* {@link io.appium.java_client.android.Setting}.
* {@link io.appium.java_client.Setting}.
*/
@Deprecated
public enum AppiumSetting {
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/io/appium/java_client/HasSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.appium.java_client;

import static io.appium.java_client.MobileCommand.getSettingsCommand;
import static io.appium.java_client.MobileCommand.setSettingsCommand;

import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.remote.Response;

import java.util.Map;


public interface HasSettings extends ExecutesMethod {

/**
* Set a setting for this test session It's probably better to use a
* convenience function, rather than use this function directly. Try finding
* the method for the specific setting you want to change.
*
* @param setting Setting you wish to set.
* @param value value of the setting.
*/
default void setSetting(Setting setting, Object value) {
CommandExecutionHelper.execute(this, setSettingsCommand(setting, value));
}

/**
* Get settings stored for this test session It's probably better to use a
* convenience function, rather than use this function directly. Try finding
* the method for the specific setting you want to read.
*
* @return JsonObject, a straight-up hash of settings.
*/
@SuppressWarnings("unchecked")
default Map<String, Object> getSettings() {
Map.Entry<String, Map<String, ?>> keyValuePair = getSettingsCommand();
Response response = execute(keyValuePair.getKey(), keyValuePair.getValue());

return ImmutableMap.<String, Object>builder()
.putAll(Map.class.cast(response.getValue())).build();
}
}
9 changes: 9 additions & 0 deletions src/main/java/io/appium/java_client/MobileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,13 @@ public static ImmutableMap<String, Object> prepareArguments(String[] params,
return new AbstractMap.SimpleEntry<>(
LOCK, prepareArguments("seconds", duration.getSeconds()));
}

public static Map.Entry<String, Map<String, ?>> getSettingsCommand() {
return new AbstractMap.SimpleEntry<>(GET_SETTINGS, ImmutableMap.<String, Object>of());
}

public static Map.Entry<String, Map<String, ?>> setSettingsCommand(Setting setting, Object value) {
return new AbstractMap.SimpleEntry<>(SET_SETTINGS, prepareArguments("settings",
prepareArguments(setting.toString(), value)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.appium.java_client.android;
package io.appium.java_client;

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

private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
public class AndroidDriver<T extends WebElement>
extends AppiumDriver<T>
implements PressesKeyCode, HasNetworkConnection, PushesFiles, StartsActivity,
FindsByAndroidUIAutomator<T>, LocksAndroidDevice, HasSettings, HasDeviceDetails,
FindsByAndroidUIAutomator<T>, LocksAndroidDevice, HasAndroidSettings, HasDeviceDetails,
HasSupportedPerformanceDataType {

private static final String ANDROID_PLATFORM = MobilePlatform.ANDROID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,4 @@ public class AndroidMobileCommandHelper extends MobileCommand {
return new AbstractMap.SimpleEntry<>(
REPLACE_VALUE, prepareArguments(parameters, values));
}

public static Map.Entry<String, Map<String, ?>> getSettingsCommand() {
return new AbstractMap.SimpleEntry<>(GET_SETTINGS, ImmutableMap.<String, Object>of());
}

public static Map.Entry<String, Map<String, ?>> setSettingsCommand(Setting setting, Object value) {
return new AbstractMap.SimpleEntry<>(SET_SETTINGS, prepareArguments("settings",
prepareArguments(setting.toString(), value)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,13 @@

package io.appium.java_client.android;

import static io.appium.java_client.android.AndroidMobileCommandHelper.getSettingsCommand;
import static io.appium.java_client.android.AndroidMobileCommandHelper.setSettingsCommand;

import com.google.common.collect.ImmutableMap;

import io.appium.java_client.CommandExecutionHelper;
import io.appium.java_client.ExecutesMethod;

import org.openqa.selenium.remote.Response;
import io.appium.java_client.HasSettings;
import io.appium.java_client.Setting;

import java.time.Duration;
import java.util.Map;

interface HasSettings extends ExecutesMethod {
/**
* Set a setting for this test session It's probably better to use a
* convenience function, rather than use this function directly. Try finding
* the method for the specific setting you want to change.
*
* @param setting Setting you wish to set.
* @param value value of the setting.
*/
default void setSetting(Setting setting, Object value) {
CommandExecutionHelper.execute(this, setSettingsCommand(setting, value));
}

/**
* Get settings stored for this test session It's probably better to use a
* convenience function, rather than use this function directly. Try finding
* the method for the specific setting you want to read.
*
* @return JsonObject, a straight-up hash of settings.
*/
@SuppressWarnings("unchecked")
default Map<String, Object> getSettings() {
Map.Entry<String, Map<String, ?>> keyValuePair = getSettingsCommand();
Response response = execute(keyValuePair.getKey(), keyValuePair.getValue());

return ImmutableMap.<String, Object>builder()
.putAll(Map.class.cast(response.getValue())).build();
}

interface HasAndroidSettings extends HasSettings {
/**
* Set the `ignoreUnimportantViews` setting. *Android-only method*.
* Sets whether Android devices should use `setCompressedLayoutHeirarchy()`
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/io/appium/java_client/ios/HasIOSSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.appium.java_client.ios;


import io.appium.java_client.HasSettings;
import io.appium.java_client.Setting;

interface HasIOSSettings extends HasSettings {
/**
* Set the `nativeWebTap` setting. *iOS-only method*.
* Sets whether Safari/webviews should convert element taps into x/y taps
* @param enabled turns nativeWebTap on if true, off if false
*/
default void nativeWebTap(Boolean enabled) {
setSetting(Setting.NATIVE_WEB_TAP, enabled);
}
}
2 changes: 1 addition & 1 deletion src/main/java/io/appium/java_client/ios/IOSDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
*/
public class IOSDriver<T extends WebElement>
extends AppiumDriver<T>
implements HidesKeyboardWithKeyName, ShakesDevice,
implements HidesKeyboardWithKeyName, ShakesDevice, HasIOSSettings,
FindsByIosUIAutomation<T>, LocksIOSDevice, PerformsTouchID, FindsByIosNSPredicate<T>,
FindsByIosClassChain<T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.assertEquals;

import io.appium.java_client.Setting;
import org.junit.Test;

import java.time.Duration;
Expand Down
46 changes: 46 additions & 0 deletions src/test/java/io/appium/java_client/ios/BaseSafariTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.appium.java_client.ios;

import io.appium.java_client.remote.AutomationName;
import io.appium.java_client.remote.IOSMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException;
import org.junit.BeforeClass;
import org.openqa.selenium.remote.DesiredCapabilities;

public class BaseSafariTest extends BaseIOSTest {

@BeforeClass public static void beforeClass() throws Exception {
service = AppiumDriverLocalService.buildDefaultService();
service.start();

if (service == null || !service.isRunning()) {
throw new AppiumServerHasNotBeenStartedLocallyException("An appium server node is not started!");
}

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari");
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.2");
//sometimes environment has performance problems
capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator");
driver = new IOSDriver<>(service.getUrl(), capabilities);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.appium.java_client.ios;

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.openqa.selenium.WebElement;

public class IOSNativeWebTapSettingTest extends BaseSafariTest {

@Test public void nativeWebTapSettingTest() throws InterruptedException {
driver.get("https://saucelabs.com/test/guinea-pig");

// do a click with nativeWebTap turned on, and assert we get to the right page
driver.nativeWebTap(true);
WebElement el = driver.findElementById("i am a link");
el.click();
assertEquals(true, driver.getTitle().contains("I am another page title"));
driver.navigate().back();

// now do a click with it turned off and assert the same behavior
assertEquals(true, driver.getTitle().contains("I am a page title"));
driver.nativeWebTap(false);
el = driver.findElementById("i am a link");
el.click();
assertEquals(true, driver.getTitle().contains("I am another page title"));
}
}