Skip to content

Commit

Permalink
Add a possibility to set pressure value for iOS (#879)
Browse files Browse the repository at this point in the history
* Add a possibility to set pressure value for iOS

* Add integration test
  • Loading branch information
Mykola Mokhnach authored and SrinivasanTarget committed Apr 29, 2018
1 parent d8f9aad commit 5e5e993
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
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;
}
}
59 changes: 59 additions & 0 deletions src/main/java/io/appium/java_client/ios/touch/IOSPressOptions.java
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

0 comments on commit 5e5e993

Please sign in to comment.