Skip to content

Commit 93096fa

Browse files
committed
Merge pull request #106 from Jonahss/settings
add Settings, and ignoreUnimportantViews setting
2 parents 171fcca + b4cc787 commit 93096fa

File tree

5 files changed

+111
-0
lines changed

5 files changed

+111
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ More can be found in the docs, but here's a quick list of features which this pr
4444
- closeApp()
4545
- endTestCoverage()
4646
- lockScreen()
47+
- isLocked()
4748
- shake()
4849
- complexFind()
4950
- scrollTo()
5051
- scrollToExact()
5152
- openNotifications()
5253
- Context Switching: .context(), .getContextHandles(), getContext())
5354
- getNetworkConnection(), setNetworkConnection()
55+
- ignoreUnimportantViews
5456

5557
Locators:
5658
- findElementByAccessibilityId()

src/main/java/io/appium/java_client/AppiumDriver.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import com.google.common.collect.ImmutableList;
2121
import com.google.common.collect.ImmutableMap;
22+
import com.google.gson.JsonObject;
23+
import com.google.gson.JsonParser;
2224
import io.appium.java_client.internal.JsonToMobileElementConverter;
2325
import org.openqa.selenium.*;
2426
import org.openqa.selenium.html5.Location;
@@ -80,6 +82,8 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities){
8082
.put(OPEN_NOTIFICATIONS, postC("/session/:sessionId/appium/device/open_notifications"))
8183
.put(GET_NETWORK_CONNECTION, getC("/session/:sessionId/network_connection"))
8284
.put(SET_NETWORK_CONNECTION, postC("/session/:sessionId/network_connection"))
85+
.put(GET_SETTINGS, getC("/session/:sessionId/appium/settings"))
86+
.put(SET_SETTINGS, postC("/session/:sessionId/appium/settings"))
8387
;
8488
ImmutableMap<String, CommandInfo> mobileCommands = builder.build();
8589

@@ -559,6 +563,62 @@ public void setNetworkConnection(NetworkConnectionSetting connection) {
559563
execute(SET_NETWORK_CONNECTION, builder.build());
560564
}
561565

566+
/**
567+
* Get settings stored for this test session
568+
* It's probably better to use a convenience function, rather than use this function directly.
569+
* Try finding the method for the specific setting you want to read
570+
*
571+
* @return JsonObject, a straight-up hash of settings
572+
*/
573+
public JsonObject getSettings() {
574+
Response response = execute(GET_SETTINGS);
575+
576+
JsonParser parser = new JsonParser();
577+
JsonObject settings = (JsonObject)parser.parse(response.getValue().toString());
578+
579+
return settings;
580+
}
581+
582+
/**
583+
* Set settings for this test session
584+
* It's probably better to use a convenience function, rather than use this function directly.
585+
* Try finding the method for the specific setting you want to change
586+
*
587+
* @param settings Map of setting keys and values
588+
*/
589+
private void setSettings(ImmutableMap settings) {
590+
591+
ImmutableMap.Builder builder = ImmutableMap.builder();
592+
builder.put("settings", settings);
593+
594+
execute(SET_SETTINGS, builder.build());
595+
}
596+
597+
/**
598+
* Set a setting for this test session
599+
* It's probably better to use a convenience function, rather than use this function directly.
600+
* Try finding the method for the specific setting you want to change
601+
*
602+
* @param setting AppiumSetting you wish to set
603+
* @param value value of the setting
604+
*/
605+
private void setSetting(AppiumSetting setting, Object value) {
606+
ImmutableMap.Builder builder = ImmutableMap.builder();
607+
builder.put(setting.toString(), value);
608+
setSettings(builder.build());
609+
}
610+
611+
/**
612+
* Set the `ignoreUnimportantViews` setting.
613+
*
614+
* Sets whether Android devices should use `setCompressedLayoutHeirarchy()` which ignores all views which are marked IMPORTANT_FOR_ACCESSIBILITY_NO or IMPORTANT_FOR_ACCESSIBILITY_AUTO (and have been deemed not important by the system), in an attempt to make things less confusing or faster.
615+
*
616+
* @param compress ignores unimportant views if true, doesn't ignore otherwise.
617+
*/
618+
public void ignoreUnimportantViews(Boolean compress) {
619+
setSetting(AppiumSetting.IGNORE_UNIMPORTANT_VIEWS, compress);
620+
}
621+
562622
@Override
563623
public WebDriver context(String name) {
564624
if (name == null) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
/**
21+
* Enums defining constants for Appium Settings which can be set and toggled during a test session.
22+
*
23+
*/
24+
public enum AppiumSetting {
25+
26+
IGNORE_UNIMPORTANT_VIEWS("ignoreUnimportantViews");
27+
private String name;
28+
29+
private AppiumSetting(String name) {
30+
this.name = name;
31+
}
32+
33+
public String toString() {
34+
return this.name;
35+
}
36+
37+
}

src/main/java/io/appium/java_client/MobileCommand.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,7 @@ public interface MobileCommand {
4949
String OPEN_NOTIFICATIONS = "openNotifications";
5050
String GET_NETWORK_CONNECTION = "getNetworkConnection";
5151
String SET_NETWORK_CONNECTION = "setNetworkConnection";
52+
String GET_SETTINGS = "getSettings";
53+
String SET_SETTINGS = "setSettings";
5254

5355
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,14 @@ public void networkConnectionTest() {
129129
public void isLockedTest() {
130130
assertEquals(false, driver.isLocked());
131131
}
132+
133+
@Test
134+
public void ignoreUnimportantViews() {
135+
driver.ignoreUnimportantViews(true);
136+
boolean ignoreViews = driver.getSettings().get(AppiumSetting.IGNORE_UNIMPORTANT_VIEWS.toString()).getAsBoolean();
137+
assertTrue(ignoreViews);
138+
driver.ignoreUnimportantViews(false);
139+
ignoreViews = driver.getSettings().get(AppiumSetting.IGNORE_UNIMPORTANT_VIEWS.toString()).getAsBoolean();
140+
assertFalse(ignoreViews);
141+
}
132142
}

0 commit comments

Comments
 (0)