Skip to content

Commit 5e5e993

Browse files
Mykola MokhnachSrinivasanTarget
Mykola Mokhnach
authored andcommitted
Add a possibility to set pressure value for iOS (#879)
* Add a possibility to set pressure value for iOS * Add integration test
1 parent d8f9aad commit 5e5e993

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

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

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

2121
import io.appium.java_client.PerformsTouchActions;
2222
import io.appium.java_client.TouchAction;
23+
import io.appium.java_client.ios.touch.IOSPressOptions;
2324
import io.appium.java_client.touch.offset.ElementOption;
2425
import io.appium.java_client.touch.offset.PointOption;
2526
import org.openqa.selenium.WebElement;
@@ -68,4 +69,15 @@ public IOSTouchAction doubleTap(PointOption doubleTapOption) {
6869
parameterBuilder.add(action);
6970
return this;
7071
}
72+
73+
/**
74+
* Press action on the screen.
75+
*
76+
* @param pressOptions see {@link IOSPressOptions}
77+
* @return this TouchAction, for chaining.
78+
*/
79+
public IOSTouchAction press(IOSPressOptions pressOptions) {
80+
parameterBuilder.add(new ActionParameter("press", pressOptions));
81+
return this;
82+
}
7183
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.touch;
18+
19+
import static java.util.Optional.ofNullable;
20+
21+
import io.appium.java_client.touch.offset.AbstractOptionCombinedWithPosition;
22+
23+
import java.util.Map;
24+
25+
public class IOSPressOptions extends AbstractOptionCombinedWithPosition<IOSPressOptions> {
26+
private Double pressure = null;
27+
28+
/**
29+
* It creates an empty instance of {@link IOSPressOptions}.
30+
*
31+
* @return an empty instance of {@link IOSPressOptions}
32+
*/
33+
public static IOSPressOptions iosPressOptions() {
34+
return new IOSPressOptions();
35+
}
36+
37+
/**
38+
* Set the pressure value. This allows to simulate force/3D touch on
39+
* devices, that support it.
40+
*
41+
* @param pressure the value to set.
42+
* See the description of `force` property on Apple's UITouch class
43+
* (https://developer.apple.com/documentation/uikit/uitouch?language=objc)
44+
* for more details on possible value ranges.
45+
*
46+
* @return this instance for chaining.
47+
*/
48+
public IOSPressOptions withPressure(double pressure) {
49+
this.pressure = pressure;
50+
return this;
51+
}
52+
53+
@Override
54+
public Map<String, Object> build() {
55+
final Map<String, Object> result = super.build();
56+
ofNullable(pressure).ifPresent(x -> result.put("pressure", x));
57+
return result;
58+
}
59+
}

src/test/java/io/appium/java_client/ios/IOSTouchTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package io.appium.java_client.ios;
22

33
import static io.appium.java_client.MobileBy.IosUIAutomation;
4+
import static io.appium.java_client.ios.touch.IOSPressOptions.iosPressOptions;
45
import static io.appium.java_client.touch.TapOptions.tapOptions;
56
import static io.appium.java_client.touch.WaitOptions.waitOptions;
67
import static io.appium.java_client.touch.offset.ElementOption.element;
8+
import static java.time.Duration.ofMillis;
79
import static java.time.Duration.ofSeconds;
810
import static org.junit.Assert.assertEquals;
911
import static org.junit.Assert.assertNotNull;
@@ -36,6 +38,26 @@ public void tapTest() {
3638
assertEquals(driver.findElementByXPath("//*[@name = \"Answer\"]").getText(), "6");
3739
}
3840

41+
@Test
42+
public void touchWithPressureTest() {
43+
IOSElement intA = driver.findElementById("IntegerA");
44+
IOSElement intB = driver.findElementById("IntegerB");
45+
intA.clear();
46+
intB.clear();
47+
intA.sendKeys("2");
48+
intB.sendKeys("4");
49+
50+
MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton");
51+
new IOSTouchAction(driver)
52+
.press(iosPressOptions()
53+
.withElement(element(e))
54+
.withPressure(1))
55+
.waitAction(waitOptions(ofMillis(100)))
56+
.release()
57+
.perform();
58+
assertEquals(driver.findElementByXPath("//*[@name = \"Answer\"]").getText(), "6");
59+
}
60+
3961
@Test public void swipeTest() {
4062
MobileElement slider = driver.findElementByClassName("UIASlider");
4163
Dimension size = slider.getSize();

0 commit comments

Comments
 (0)