-
-
Notifications
You must be signed in to change notification settings - Fork 760
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable nativeWebTap setting for iOS (#658)
* enable nativeWebTap setting for iOS * add tests for nativeWebTap method * make javadoc happy * conform to style
- Loading branch information
Showing
12 changed files
with
182 additions
and
52 deletions.
There are no files selected for viewing
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
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
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(); | ||
} | ||
} |
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
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
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
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
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
32 changes: 32 additions & 0 deletions
32
src/main/java/io/appium/java_client/ios/HasIOSSettings.java
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
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); | ||
} | ||
} |
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
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
46 changes: 46 additions & 0 deletions
46
src/test/java/io/appium/java_client/ios/BaseSafariTest.java
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
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); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java
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
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")); | ||
} | ||
} |
37f5ed3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is fine