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

Add a possibility to set pressure value for iOS #879

Merged
merged 2 commits into from
Apr 29, 2018
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
12 changes: 12 additions & 0 deletions src/main/java/io/appium/java_client/ios/IOSTouchAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import io.appium.java_client.PerformsTouchActions;
import io.appium.java_client.TouchAction;
import io.appium.java_client.ios.touch.IOSPressOptions;
import io.appium.java_client.touch.offset.ElementOption;
import io.appium.java_client.touch.offset.PointOption;
import org.openqa.selenium.WebElement;
Expand Down Expand Up @@ -68,4 +69,15 @@ public IOSTouchAction doubleTap(PointOption doubleTapOption) {
parameterBuilder.add(action);
return this;
}

/**
* Press action on the screen.
*
* @param pressOptions see {@link IOSPressOptions}
* @return this TouchAction, for chaining.
*/
public IOSTouchAction press(IOSPressOptions pressOptions) {
parameterBuilder.add(new ActionParameter("press", pressOptions));
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.touch;

import static java.util.Optional.ofNullable;

import io.appium.java_client.touch.offset.AbstractOptionCombinedWithPosition;

import java.util.Map;

public class IOSPressOptions extends AbstractOptionCombinedWithPosition<IOSPressOptions> {
private Double pressure = null;

/**
* It creates an empty instance of {@link IOSPressOptions}.
*
* @return an empty instance of {@link IOSPressOptions}
*/
public static IOSPressOptions iosPressOptions() {
return new IOSPressOptions();
}

/**
* Set the pressure value. This allows to simulate force/3D touch on
* devices, that support it.
*
* @param pressure the value to set.
* See the description of `force` property on Apple's UITouch class
* (https://developer.apple.com/documentation/uikit/uitouch?language=objc)
* for more details on possible value ranges.
*
* @return this instance for chaining.
*/
public IOSPressOptions withPressure(double pressure) {
this.pressure = pressure;
return this;
}

@Override
public Map<String, Object> build() {
final Map<String, Object> result = super.build();
ofNullable(pressure).ifPresent(x -> result.put("pressure", x));
return result;
}
}
22 changes: 22 additions & 0 deletions src/test/java/io/appium/java_client/ios/IOSTouchTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.appium.java_client.ios;

import static io.appium.java_client.MobileBy.IosUIAutomation;
import static io.appium.java_client.ios.touch.IOSPressOptions.iosPressOptions;
import static io.appium.java_client.touch.TapOptions.tapOptions;
import static io.appium.java_client.touch.WaitOptions.waitOptions;
import static io.appium.java_client.touch.offset.ElementOption.element;
import static java.time.Duration.ofMillis;
import static java.time.Duration.ofSeconds;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -36,6 +38,26 @@ public void tapTest() {
assertEquals(driver.findElementByXPath("//*[@name = \"Answer\"]").getText(), "6");
}

@Test
public void touchWithPressureTest() {
IOSElement intA = driver.findElementById("IntegerA");
IOSElement intB = driver.findElementById("IntegerB");
intA.clear();
intB.clear();
intA.sendKeys("2");
intB.sendKeys("4");

MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton");
new IOSTouchAction(driver)
.press(iosPressOptions()
.withElement(element(e))
.withPressure(1))
.waitAction(waitOptions(ofMillis(100)))
.release()
.perform();
assertEquals(driver.findElementByXPath("//*[@name = \"Answer\"]").getText(), "6");
}

@Test public void swipeTest() {
MobileElement slider = driver.findElementByClassName("UIASlider");
Dimension size = slider.getSize();
Expand Down