Skip to content

Commit 4f5c57e

Browse files
1 parent 28223fb commit 4f5c57e

File tree

4 files changed

+87
-93
lines changed

4 files changed

+87
-93
lines changed
Lines changed: 75 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,75 @@
1-
/*
2-
+Copyright 2014 Appium contributors
3-
+Copyright 2014 Software Freedom Conservancy
4-
+
5-
+Licensed under the Apache License, Version 2.0 (the "License");
6-
+you may not use this file except in compliance with the License.
7-
+You may obtain a copy of the License at
8-
+
9-
+ http://www.apache.org/licenses/LICENSE-2.0
10-
+
11-
+Unless required by applicable law or agreed to in writing, software
12-
+distributed under the License is distributed on an "AS IS" BASIS,
13-
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
+See the License for the specific language governing permissions and
15-
+limitations under the License.
16-
+ */
17-
18-
package io.appium.java_client;
19-
20-
import com.google.common.collect.ImmutableMap;
21-
22-
import org.openqa.selenium.By;
23-
import org.openqa.selenium.Dimension;
24-
import org.openqa.selenium.Point;
25-
import org.openqa.selenium.WebElement;
26-
import org.openqa.selenium.remote.FileDetector;
27-
import org.openqa.selenium.remote.RemoteWebDriver;
28-
import org.openqa.selenium.remote.RemoteWebElement;
29-
30-
import java.util.List;
31-
32-
public abstract class MobileElement extends RemoteWebElement implements FindsByAccessibilityId, TouchableElement {
33-
34-
protected FileDetector fileDetector;
35-
36-
public List<WebElement> findElements(By by) {
37-
return by.findElements(this);
38-
}
39-
40-
public WebElement findElement(By by) {
41-
return by.findElement(this);
42-
}
43-
44-
public WebElement findElementByAccessibilityId(String using) {
45-
return findElement("accessibility id", using);
46-
}
47-
48-
public List<WebElement> findElementsByAccessibilityId(String using) {
49-
return findElements("accessibility id", using);
50-
}
51-
52-
public void setValue(String value) {
53-
ImmutableMap.Builder builder = ImmutableMap.builder();
54-
builder.put("id", id).put("value", value);
55-
execute(MobileCommand.SET_VALUE, builder.build());
56-
}
57-
58-
public Point getCenter() {
59-
Point upperLeft = this.getLocation();
60-
Dimension dimensions = this.getSize();
61-
return new Point(upperLeft.getX() + dimensions.getWidth() / 2, upperLeft.getY() + dimensions.getHeight() / 2);
62-
}
63-
64-
@Override
65-
public void pinch() {
66-
((AppiumDriver) parent).pinch(this);
67-
}
68-
69-
@Override
70-
public void tap(int fingers, int duration) {
71-
((AppiumDriver) parent).tap(fingers, this, duration);
72-
}
73-
74-
@Override
75-
public void zoom() {
76-
((AppiumDriver) parent).zoom(this);
77-
}
78-
79-
80-
@Override
81-
public void swipe(SwipeElementDirection direction, int duration) {
82-
direction.swipe((AppiumDriver) parent, this, duration);
83-
}
84-
}
1+
/*
2+
+Copyright 2014 Appium contributors
3+
+Copyright 2014 Software Freedom Conservancy
4+
+
5+
+Licensed under the Apache License, Version 2.0 (the "License");
6+
+you may not use this file except in compliance with the License.
7+
+You may obtain a copy of the License at
8+
+
9+
+ http://www.apache.org/licenses/LICENSE-2.0
10+
+
11+
+Unless required by applicable law or agreed to in writing, software
12+
+distributed under the License is distributed on an "AS IS" BASIS,
13+
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
+See the License for the specific language governing permissions and
15+
+limitations under the License.
16+
+ */
17+
18+
package io.appium.java_client;
19+
20+
import org.openqa.selenium.By;
21+
import org.openqa.selenium.Dimension;
22+
import org.openqa.selenium.Point;
23+
import org.openqa.selenium.WebElement;
24+
import org.openqa.selenium.remote.FileDetector;
25+
import org.openqa.selenium.remote.RemoteWebElement;
26+
27+
import java.util.List;
28+
29+
public abstract class MobileElement extends RemoteWebElement implements FindsByAccessibilityId, TouchableElement {
30+
31+
protected FileDetector fileDetector;
32+
33+
public List<WebElement> findElements(By by) {
34+
return by.findElements(this);
35+
}
36+
37+
public WebElement findElement(By by) {
38+
return by.findElement(this);
39+
}
40+
41+
public WebElement findElementByAccessibilityId(String using) {
42+
return findElement("accessibility id", using);
43+
}
44+
45+
public List<WebElement> findElementsByAccessibilityId(String using) {
46+
return findElements("accessibility id", using);
47+
}
48+
49+
public Point getCenter() {
50+
Point upperLeft = this.getLocation();
51+
Dimension dimensions = this.getSize();
52+
return new Point(upperLeft.getX() + dimensions.getWidth() / 2, upperLeft.getY() + dimensions.getHeight() / 2);
53+
}
54+
55+
@Override
56+
public void pinch() {
57+
((AppiumDriver) parent).pinch(this);
58+
}
59+
60+
@Override
61+
public void tap(int fingers, int duration) {
62+
((AppiumDriver) parent).tap(fingers, this, duration);
63+
}
64+
65+
@Override
66+
public void zoom() {
67+
((AppiumDriver) parent).zoom(this);
68+
}
69+
70+
71+
@Override
72+
public void swipe(SwipeElementDirection direction, int duration) {
73+
direction.swipe((AppiumDriver) parent, this, duration);
74+
}
75+
}

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

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

33
import io.appium.java_client.FindsByIosUIAutomation;
4+
import io.appium.java_client.MobileCommand;
45
import io.appium.java_client.MobileElement;
56
import io.appium.java_client.ScrollsTo;
7+
68
import org.openqa.selenium.WebElement;
79

10+
import com.google.common.collect.ImmutableMap;
11+
812
import java.util.List;
913

1014
public class IOSElement extends MobileElement implements FindsByIosUIAutomation, ScrollsTo {
@@ -38,4 +42,11 @@ public MobileElement scrollTo(String text) {
3842
public MobileElement scrollToExact(String text) {
3943
return (MobileElement) findElementByIosUIAutomation(".scrollToElementWithName(\"" + text + "\")");
4044
}
45+
46+
@SuppressWarnings({ "rawtypes", "unchecked" })
47+
public void setValue(String value) {
48+
ImmutableMap.Builder builder = ImmutableMap.builder();
49+
builder.put("id", id).put("value", value);
50+
execute(MobileCommand.SET_VALUE, builder.build());
51+
}
4152
}

src/test/java/io/appium/java_client/AppiumDriverTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,6 @@ public void resetTest() {
6262
driver.resetApp();
6363
}
6464

65-
@Test
66-
public void setValueTest() {
67-
MobileElement element = (MobileElement)driver.findElementByAccessibilityId("Text Fields, AAPLTextFieldViewController");
68-
element.click();
69-
element = (MobileElement)driver.findElementByAccessibilityId("DEFAULT");
70-
element.setValue("Grace Hopper");
71-
}
72-
7365
@Test
7466
public void pullFileTest() {
7567
byte[] data = driver.pullFile("Library/AddressBook/AddressBook.sqlitedb");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void namedTextFieldTest() {
8383
MobileElement element = (MobileElement)driver.findElementByAccessibilityId("Text Fields, AAPLTextFieldViewController");
8484
element.click();
8585
element = (MobileElement)driver.getNamedTextField("DEFAULT");
86-
element.setValue("Grace Hopper");
86+
((IOSElement) element).setValue("Grace Hopper");
8787
assertEquals("Grace Hopper", element.getText());
8888
}
8989

0 commit comments

Comments
 (0)