├── .gitignore
├── BasicSample
├── .gitignore
├── README.md
├── app
│ ├── build.gradle
│ └── src
│ │ ├── androidTest
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── android
│ │ │ └── testing
│ │ │ └── espresso
│ │ │ └── BasicSample
│ │ │ ├── ChangeTextBehaviorTest.java
│ │ │ ├── GetRootView.java
│ │ │ └── ViewToUix.java
│ │ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── android
│ │ │ └── testing
│ │ │ └── espresso
│ │ │ └── BasicSample
│ │ │ ├── MainActivity.java
│ │ │ └── ShowTextActivity.java
│ │ └── res
│ │ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── activity_show_text.xml
│ │ ├── values-v13
│ │ └── styles.xml
│ │ ├── values-v21
│ │ └── styles.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── LICENSE
├── readme.md
├── readme
├── inspector.png
└── open_files.png
└── uix
├── espresso_dump.uix
└── espresso_image.png
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | *.iml
3 | local.properties
4 | build
5 | .gradle
6 | # Eclipse project files
7 | .project
8 | .settings/
9 | .classpath
10 |
--------------------------------------------------------------------------------
/BasicSample/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | local.properties
3 | .idea
4 | .DS_Store
5 | build
6 | *.iml
7 |
--------------------------------------------------------------------------------
/BasicSample/README.md:
--------------------------------------------------------------------------------
1 | # Basic sample for Espresso
2 |
3 | *If you are new to Espresso, try this sample first.*
4 |
5 | This project uses the Gradle build system. You don't need an IDE to build and execute it but Android Studio is recommended.
6 |
7 | 1. Download the project code, preferably using `git clone`.
8 | 1. Open the Android SDK Manager (*Tools* Menu | *Android*) and make sure you have installed the *Android Support Repository* under *Extras*. (For more Information click [here](http://developer.android.com/tools/testing-support-library/index.html#setup))
9 | 1. In Android Studio, select *File* | *Open...* and point to the `./build.gradle` file.
10 | 1. Check out the relevant code:
11 | * The application under test is located in `src/main/java`
12 | * Tests are in `src/androidTest/java`
13 | 1. Create the test configuration with a custom runner: `android.support.test.runner.AndroidJUnitRunner`
14 | * Open *Run* menu | *Edit Configurations*
15 | * Add a new *Android Tests* configuration
16 | * Choose a module
17 | * Add a *Specific instrumentation runner*: `android.support.test.runner.AndroidJUnitRunner`
18 | 1. Connect a device or start an emulator
19 | * Turn animations off.
20 | (On your device, under Settings->Developer options disable the following 3 settings: "Window animation scale", "Transition animation scale" and "Animator duration scale")
21 | 1. Run the newly created configuration
22 |
23 | The application will be started on the device/emulator and a series of actions will be performed automatically.
24 |
25 | If you are using Android Studio, the *Run* window will show the test results.
26 |
--------------------------------------------------------------------------------
/BasicSample/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion '23.0.1'
6 | defaultConfig {
7 | applicationId "com.example.android.testing.espresso.BasicSample"
8 | minSdkVersion 10
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | packagingOptions {
16 | exclude 'LICENSE.txt'
17 | }
18 | lintOptions {
19 | abortOnError false
20 | }
21 | productFlavors {
22 | }
23 | }
24 |
25 | dependencies {
26 | // App dependencies
27 | compile 'com.android.support:support-annotations:23.0.1'
28 | compile 'com.google.guava:guava:18.0'
29 | // Testing-only dependencies
30 | // Force usage of support annotations in the test app, since it is internally used by the runner module.
31 | androidTestCompile 'com.android.support:support-annotations:23.0.1'
32 | androidTestCompile 'com.android.support.test:runner:0.4.1'
33 | androidTestCompile 'com.android.support.test:rules:0.4.1'
34 | androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
35 | androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/BasicSample/app/src/androidTest/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/BasicSample/app/src/androidTest/java/com/example/android/testing/espresso/BasicSample/ChangeTextBehaviorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015, The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
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 com.example.android.testing.espresso.BasicSample;
18 |
19 | import org.junit.Before;
20 | import org.junit.Rule;
21 | import org.junit.Test;
22 | import org.junit.runner.RunWith;
23 |
24 | import android.app.Activity;
25 | import android.support.test.espresso.action.ViewActions;
26 | import android.support.test.espresso.matcher.ViewMatchers;
27 | import android.support.test.rule.ActivityTestRule;
28 | import android.support.test.runner.AndroidJUnit4;
29 | import android.test.ActivityInstrumentationTestCase2;
30 | import android.test.suitebuilder.annotation.LargeTest;
31 |
32 | import static android.support.test.espresso.Espresso.onView;
33 | import static android.support.test.espresso.action.ViewActions.click;
34 | import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
35 | import static android.support.test.espresso.action.ViewActions.typeText;
36 | import static android.support.test.espresso.assertion.ViewAssertions.matches;
37 | import static android.support.test.espresso.matcher.ViewMatchers.withId;
38 | import static android.support.test.espresso.matcher.ViewMatchers.withText;
39 |
40 |
41 | /**
42 | * Basic tests showcasing simple view matchers and actions like {@link ViewMatchers#withId},
43 | * {@link ViewActions#click} and {@link ViewActions#typeText}.
44 | *
45 | * Note that there is no need to tell Espresso that a view is in a different {@link Activity}.
46 | */
47 | @RunWith(AndroidJUnit4.class)
48 | @LargeTest
49 | public class ChangeTextBehaviorTest {
50 |
51 | public static final String STRING_TO_BE_TYPED = "Espresso";
52 |
53 | /**
54 | * A JUnit {@link Rule @Rule} to launch your activity under test. This is a replacement
55 | * for {@link ActivityInstrumentationTestCase2}.
56 | *
57 | * Rules are interceptors which are executed for each test method and will run before
58 | * any of your setup code in the {@link Before @Before} method.
59 | *
60 | * {@link ActivityTestRule} will create and launch of the activity for you and also expose
61 | * the activity under test. To get a reference to the activity you can use
62 | * the {@link ActivityTestRule#getActivity()} method.
63 | */
64 | @Rule
65 | public ActivityTestRule mActivityRule = new ActivityTestRule<>(
66 | MainActivity.class);
67 |
68 | @Test
69 | public void changeText_sameActivity() {
70 | // Type text and then press the button.
71 | onView(withId(R.id.editTextUserInput))
72 | .perform(typeText(STRING_TO_BE_TYPED), closeSoftKeyboard());
73 | onView(withId(R.id.changeTextBt)).perform(click());
74 |
75 | // Check that the text was changed.
76 | onView(withId(R.id.textToBeChanged)).check(matches(withText(STRING_TO_BE_TYPED)));
77 |
78 | // Dump. Download with adb pull /sdcard/Android/data/com.example.android.testing.espresso.BasicSample/cache/dump
79 | ViewToUix.dumpView();
80 | }
81 | }
--------------------------------------------------------------------------------
/BasicSample/app/src/androidTest/java/com/example/android/testing/espresso/BasicSample/GetRootView.java:
--------------------------------------------------------------------------------
1 | package com.example.android.testing.espresso.BasicSample;
2 |
3 | import android.support.test.espresso.UiController;
4 | import android.support.test.espresso.ViewAction;
5 | import android.support.test.espresso.matcher.ViewMatchers;
6 | import android.view.View;
7 |
8 | import org.hamcrest.Matcher;
9 | import org.hamcrest.Matchers;
10 |
11 | public class GetRootView implements ViewAction {
12 | View rootView;
13 |
14 | @Override
15 | public Matcher getConstraints() {
16 | return Matchers.allOf(ViewMatchers.isRoot());
17 | }
18 |
19 | @Override
20 | public String getDescription() {
21 | return "get root view";
22 | }
23 |
24 | @Override
25 | public void perform(UiController uiController, View view) {
26 | rootView = view;
27 | }
28 |
29 | public View getRootView() {
30 | return rootView;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/BasicSample/app/src/androidTest/java/com/example/android/testing/espresso/BasicSample/ViewToUix.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 DroidDriver committers
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
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 | /*
18 | * Copyright (C) 2012 The Android Open Source Project
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | */
32 | package com.example.android.testing.espresso.BasicSample;
33 |
34 | import android.content.res.Resources;
35 | import android.graphics.Rect;
36 | import android.os.Build;
37 | import android.support.test.InstrumentationRegistry;
38 | import android.support.test.espresso.core.deps.guava.base.Charsets;
39 | import android.support.test.espresso.core.deps.guava.io.Files;
40 | import android.support.test.uiautomator.UiDevice;
41 | import android.util.Log;
42 | import android.util.Printer;
43 | import android.util.StringBuilderPrinter;
44 | import android.view.View;
45 | import android.view.ViewGroup;
46 | import android.view.accessibility.AccessibilityNodeInfo;
47 | import android.view.inputmethod.EditorInfo;
48 | import android.view.inputmethod.InputConnection;
49 | import android.widget.Checkable;
50 | import android.widget.TextView;
51 |
52 | import org.junit.Assert;
53 | import org.w3c.dom.Document;
54 | import org.w3c.dom.Element;
55 |
56 | import java.io.BufferedOutputStream;
57 | import java.io.ByteArrayOutputStream;
58 | import java.io.File;
59 | import java.util.HashMap;
60 | import java.util.Map;
61 |
62 | import javax.xml.parsers.DocumentBuilderFactory;
63 | import javax.xml.parsers.ParserConfigurationException;
64 | import javax.xml.transform.OutputKeys;
65 | import javax.xml.transform.Transformer;
66 | import javax.xml.transform.TransformerFactory;
67 | import javax.xml.transform.dom.DOMSource;
68 | import javax.xml.transform.stream.StreamResult;
69 |
70 | import static android.support.test.InstrumentationRegistry.getTargetContext;
71 | import static android.support.test.espresso.Espresso.onView;
72 | import static android.support.test.espresso.matcher.ViewMatchers.isRoot;
73 | import static org.hamcrest.Matchers.allOf;
74 |
75 | /** Converts Espresso view tree to XML format that works with uiautomatorviewer **/
76 | // https://github.com/appium/droiddriver/blob/c1f89919ed5e88650548f34fe8ca9e5d458a41df/src/io/appium/droiddriver/finders/ByXPath.java#L198
77 | public class ViewToUix {
78 | private static final File dumpDir = new File(getTargetContext().getExternalCacheDir(), "dump");
79 | private static final File DUMP_XML = new File(dumpDir, "espresso_dump.uix");
80 | private static final File DUMP_PNG = new File(dumpDir, "espresso_image.png");
81 | private static final UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
82 | private static final String TAG = "espresso";
83 |
84 | // document needs to be static so that when buildDomNode is called recursively
85 | // on children they are in the same document to be appended.
86 | private static Document document;
87 | // The two maps should be kept in sync
88 | private static final Map TO_DOM_MAP =
89 | new HashMap<>();
90 |
91 | // https://github.com/appium/droiddriver/blob/c1f89919ed5e88650548f34fe8ca9e5d458a41df/src/io/appium/droiddriver/finders/ByXPath.java#L64
92 | private static void clearData() {
93 | TO_DOM_MAP.clear();
94 | document = null;
95 | }
96 |
97 | /**
98 | * Returns the DOM node representing this UiElement.
99 | */
100 | // https://github.com/appium/droiddriver/blob/c1f89919ed5e88650548f34fe8ca9e5d458a41df/src/io/appium/droiddriver/finders/ByXPath.java#L127
101 | private static Element getDomNode(View view, int index) {
102 | Element domNode = TO_DOM_MAP.get(view);
103 | if (domNode == null) {
104 | domNode = buildDomNode(view, index);
105 | }
106 | return domNode;
107 | }
108 |
109 | // https://github.com/appium/droiddriver/blob/c1f89919ed5e88650548f34fe8ca9e5d458a41df/src/io/appium/droiddriver/finders/ByXPath.java#L113
110 | private static Document getDocument() {
111 | if (document == null) {
112 | try {
113 | document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
114 | } catch (ParserConfigurationException e) {
115 | throw new RuntimeException(e);
116 | }
117 | }
118 | return document;
119 | }
120 |
121 | // https://github.com/appium/droiddriver/blob/c1f89919ed5e88650548f34fe8ca9e5d458a41df/src/io/appium/droiddriver/finders/XPaths.java
122 | private static String tag(String className) {
123 | return simpleClassName(className);
124 | }
125 |
126 | // https://github.com/appium/droiddriver/blob/c1f89919ed5e88650548f34fe8ca9e5d458a41df/src/io/appium/droiddriver/finders/XPaths.java
127 | private static String simpleClassName(String name) {
128 | // the nth anonymous class has a class name ending in "Outer$n"
129 | // and local inner classes have names ending in "Outer.$1Inner"
130 | name = name.replaceAll("\\$[0-9]+", "\\$");
131 |
132 | // we want the name of the inner class all by its lonesome
133 | int start = name.lastIndexOf('$');
134 |
135 | // if this isn't an inner class, just find the start of the
136 | // top level class name.
137 | if (start == -1) {
138 | start = name.lastIndexOf('.');
139 | }
140 | return name.substring(start + 1);
141 | }
142 |
143 |
144 | // https://github.com/bootstraponline/uiautomator2/blob/fa866903ece601742d694279c03a6db48a953c22/src/main/java/android/support/test/uiautomator/AccessibilityNodeInfoDumper.java#L166
145 | private static String safeCharSeqToString(CharSequence cs) {
146 | if (cs == null)
147 | return "";
148 | else {
149 | return stripInvalidXMLChars(cs);
150 | }
151 | }
152 |
153 | // https://github.com/bootstraponline/uiautomator2/blob/fa866903ece601742d694279c03a6db48a953c22/src/main/java/android/support/test/uiautomator/AccessibilityNodeInfoDumper.java#L174
154 | private static String stripInvalidXMLChars(CharSequence cs) {
155 | StringBuffer ret = new StringBuffer();
156 | char ch;
157 | /* http://www.w3.org/TR/xml11/#charsets
158 | [#x1-#x8], [#xB-#xC], [#xE-#x1F], [#x7F-#x84], [#x86-#x9F], [#xFDD0-#xFDDF],
159 | [#x1FFFE-#x1FFFF], [#x2FFFE-#x2FFFF], [#x3FFFE-#x3FFFF],
160 | [#x4FFFE-#x4FFFF], [#x5FFFE-#x5FFFF], [#x6FFFE-#x6FFFF],
161 | [#x7FFFE-#x7FFFF], [#x8FFFE-#x8FFFF], [#x9FFFE-#x9FFFF],
162 | [#xAFFFE-#xAFFFF], [#xBFFFE-#xBFFFF], [#xCFFFE-#xCFFFF],
163 | [#xDFFFE-#xDFFFF], [#xEFFFE-#xEFFFF], [#xFFFFE-#xFFFFF],
164 | [#x10FFFE-#x10FFFF].
165 | */
166 | for (int i = 0; i < cs.length(); i++) {
167 | ch = cs.charAt(i);
168 |
169 | if ((ch >= 0x1 && ch <= 0x8) || (ch >= 0xB && ch <= 0xC) || (ch >= 0xE && ch <= 0x1F) ||
170 | (ch >= 0x7F && ch <= 0x84) || (ch >= 0x86 && ch <= 0x9f) ||
171 | (ch >= 0xFDD0 && ch <= 0xFDDF) || (ch >= 0x1FFFE && ch <= 0x1FFFF) ||
172 | (ch >= 0x2FFFE && ch <= 0x2FFFF) || (ch >= 0x3FFFE && ch <= 0x3FFFF) ||
173 | (ch >= 0x4FFFE && ch <= 0x4FFFF) || (ch >= 0x5FFFE && ch <= 0x5FFFF) ||
174 | (ch >= 0x6FFFE && ch <= 0x6FFFF) || (ch >= 0x7FFFE && ch <= 0x7FFFF) ||
175 | (ch >= 0x8FFFE && ch <= 0x8FFFF) || (ch >= 0x9FFFE && ch <= 0x9FFFF) ||
176 | (ch >= 0xAFFFE && ch <= 0xAFFFF) || (ch >= 0xBFFFE && ch <= 0xBFFFF) ||
177 | (ch >= 0xCFFFE && ch <= 0xCFFFF) || (ch >= 0xDFFFE && ch <= 0xDFFFF) ||
178 | (ch >= 0xEFFFE && ch <= 0xEFFFF) || (ch >= 0xFFFFE && ch <= 0xFFFFF) ||
179 | (ch >= 0x10FFFE && ch <= 0x10FFFF))
180 | ret.append(".");
181 | else
182 | ret.append(ch);
183 | }
184 | return ret.toString();
185 | }
186 |
187 | // https://raw.githubusercontent.com/bootstraponline/uiautomator2/android-support-test/src/main/java/android/support/test/uiautomator/AccessibilityNodeInfoHelper.java
188 | /**
189 | * Returns the node's bounds clipped to the size of the display
190 | *
191 | * @param node
192 | * @param width pixel width of the display
193 | * @param height pixel height of the display
194 | * @return null if node is null, else a Rect containing visible bounds
195 | */
196 | static Rect getVisibleBoundsInScreen(AccessibilityNodeInfo node, int width, int height) {
197 | if (node == null) {
198 | return null;
199 | }
200 | // targeted node's bounds
201 | Rect nodeRect = new Rect();
202 | node.getBoundsInScreen(nodeRect);
203 |
204 | Rect displayRect = new Rect();
205 | displayRect.top = 0;
206 | displayRect.left = 0;
207 | displayRect.right = width;
208 | displayRect.bottom = height;
209 |
210 | // may change rect. must call
211 | //noinspection ResourceType
212 | nodeRect.intersect(displayRect);
213 | return nodeRect;
214 | }
215 |
216 | private static void attr(Element element, String attribute, CharSequence value) {
217 | element.setAttribute(attribute, safeCharSeqToString(value));
218 | }
219 |
220 | private static void attr(Element element, String attribute, Boolean value) {
221 | element.setAttribute(attribute, Boolean.toString(value));
222 | }
223 |
224 | private static void attr(Element element, String attribute, Integer value) {
225 | element.setAttribute(attribute, Integer.toString(value));
226 | }
227 |
228 | private static void attr(Element element, String attribute, Float value) {
229 | element.setAttribute(attribute, Float.toString(value));
230 | }
231 |
232 | // https://github.com/bootstraponline/platform_frameworks_testing/blob/fb9996b698387e62bd70fd8e42e4a5f0304d2d81/espresso/core/src/main/java/android/support/test/espresso/util/HumanReadables.java#L237
233 | private static void innerDescribe(Element element, TextView textBox) {
234 | if (null != textBox.getText()) {
235 | attr(element, "text", textBox.getText());
236 | }
237 |
238 | if (null != textBox.getError()) {
239 | attr(element, "error-text", textBox.getError());
240 | }
241 |
242 | if (null != textBox.getHint()) {
243 | attr(element, "hint", textBox.getHint());
244 | }
245 |
246 | attr(element, "input-type", textBox.getInputType());
247 | attr(element, "ime-target", textBox.isInputMethodTarget());
248 | attr(element, "has-links", textBox.getUrls().length > 0);
249 | }
250 |
251 | // https://github.com/bootstraponline/platform_frameworks_testing/blob/fb9996b698387e62bd70fd8e42e4a5f0304d2d81/espresso/core/src/main/java/android/support/test/espresso/util/HumanReadables.java#L255
252 | private static void innerDescribe(Element element, Checkable checkable) {
253 | attr(element, "is-checked", checkable.isChecked());
254 | }
255 |
256 | // https://github.com/bootstraponline/platform_frameworks_testing/blob/fb9996b698387e62bd70fd8e42e4a5f0304d2d81/espresso/core/src/main/java/android/support/test/espresso/util/HumanReadables.java#L259
257 | private static void innerDescribe(Element element, ViewGroup viewGroup) {
258 | attr(element, "child-count", viewGroup.getChildCount());
259 | }
260 |
261 | // https://github.com/appium/droiddriver/blob/c1f89919ed5e88650548f34fe8ca9e5d458a41df/src/io/appium/droiddriver/finders/ByXPath.java#L136
262 | private static Element buildDomNode(View view, int index) {
263 | Element element = getDocument().createElement(tag("node"));
264 | TO_DOM_MAP.put(view, element);
265 |
266 | AccessibilityNodeInfo node = view.createAccessibilityNodeInfo();
267 |
268 | if (Build.VERSION.SDK_INT >= 18) {
269 | // Manually set viewId since Espresso has no easy way of enabling
270 | // AccessibilityNodeInfo.FLAG_REPORT_VIEW_IDS
271 | // https://android.googlesource.com/platform/frameworks/base/+/47b50333c110194565498011379988e5c05f7890/core/java/android/view/View.java
272 | try {
273 | String viewId = view.getResources().getResourceName(view.getId());
274 | node.setViewIdResourceName(viewId);
275 | } catch (Resources.NotFoundException nfe) {
276 | /* ignore */
277 | }
278 | }
279 |
280 | // https://github.com/bootstraponline/uiautomator2/blob/085063a4e394f8e9c6195ec00cdf81a2c2b4f1c9/src/main/java/android/support/test/uiautomator/AccessibilityNodeInfoDumper.java
281 | attr(element, "index", index);
282 | attr(element, "text", node.getText());
283 | if (Build.VERSION.SDK_INT >= 18) {
284 | attr(element, "resource-id", node.getViewIdResourceName()); // aka res-name
285 | }
286 | // node.getClassName() returns the accessibility class which isn't used by Espresso
287 | // espresso requires the concrete class. uiautomatorviewer looks nicer using simple names
288 | attr(element, "class", view.getClass().getSimpleName());
289 | attr(element, "package", node.getPackageName());
290 | attr(element, "content-desc", node.getContentDescription()); // aka desc
291 | attr(element, "checkable", node.isCheckable());
292 | attr(element, "checked", node.isChecked());
293 | attr(element, "clickable", node.isClickable()); // aka is-clickable
294 | attr(element, "enabled", node.isEnabled()); // aka is-enabled
295 | attr(element, "focusable", node.isFocusable()); // aka is-focusable
296 | attr(element, "focused", node.isFocused()); // aka is-focus
297 | attr(element, "scrollable", node.isScrollable());
298 | attr(element, "long-clickable", node.isLongClickable());
299 | attr(element, "password", node.isPassword());
300 | attr(element, "selected", node.isSelected()); // aka is-selected
301 |
302 | int width = device.getDisplayWidth();
303 | int height = device.getDisplayHeight();
304 |
305 | element.setAttribute("bounds", getVisibleBoundsInScreen(node, width, height).toShortString());
306 |
307 | // extra attributes
308 | attr(element, "full-class", view.getClass().getName()); // fully qualified class
309 | attr(element, "acc-class", node.getClassName()); // accessibility class
310 |
311 | // Espresso human readable attributes
312 | // https://github.com/bootstraponline/platform_frameworks_testing/blob/android-support-test/espresso/core/src/main/java/android/support/test/espresso/util/HumanReadables.java#L161
313 | attr(element, "view-id", view.getId()); // aka 'id'
314 |
315 | switch (view.getVisibility()) {
316 | case View.GONE:
317 | attr(element, "visibility", "GONE");
318 | break;
319 | case View.INVISIBLE:
320 | attr(element, "visibility", "INVISIBLE");
321 | break;
322 | case View.VISIBLE:
323 | attr(element, "visibility", "VISIBLE");
324 | break;
325 | default:
326 | attr(element, "visibility", view.getVisibility());
327 | }
328 |
329 | attr(element, "width", view.getWidth());
330 | attr(element, "height", view.getHeight());
331 | attr(element, "has-focus", view.hasFocus());
332 | attr(element, "has-focusable", view.hasFocusable());
333 | attr(element, "has-window-focus", view.hasWindowFocus());
334 | attr(element, "is-layout-requested", view.isLayoutRequested());
335 |
336 | if (null != view.getRootView()) {
337 | // pretty much only true in unit-tests.
338 | attr(element, "root-is-layout-requested", view.getRootView().isLayoutRequested());
339 | }
340 |
341 | EditorInfo ei = new EditorInfo();
342 | InputConnection ic = view.onCreateInputConnection(ei);
343 | boolean hasInputConnection = ic != null;
344 | attr(element, "has-input-connection", hasInputConnection);
345 | if (hasInputConnection) {
346 | StringBuilder sb = new StringBuilder();
347 | sb.append("[");
348 | Printer p = new StringBuilderPrinter(sb);
349 | ei.dump(p, "");
350 | sb.append("]");
351 | attr(element, "editor-info", sb.toString().replace("\n", " "));
352 | }
353 |
354 | if (Build.VERSION.SDK_INT > 10) {
355 | attr(element, "view-x", view.getX());
356 | attr(element, "view-y", view.getY());
357 | }
358 |
359 | if (view instanceof TextView) {
360 | innerDescribe(element, (TextView) view);
361 | }
362 |
363 | if (view instanceof Checkable) {
364 | innerDescribe(element, (Checkable) view);
365 | }
366 |
367 | if (view instanceof ViewGroup) {
368 | innerDescribe(element, (ViewGroup) view);
369 | }
370 |
371 | // https://github.com/bootstraponline/espresso_2_clone/blob/436878d48678428fdbef57bdc90153833c1a3d61/espresso-core-2.0-sources/android/support/test/espresso/util/TreeIterables.java#L199
372 | if (view instanceof ViewGroup) {
373 | ViewGroup group = (ViewGroup) view;
374 | int childCount = group.getChildCount();
375 | for (int i = 0; i < childCount; i++) {
376 | element.appendChild(getDomNode(group.getChildAt(i), i));
377 | }
378 | }
379 |
380 | return element;
381 | }
382 |
383 | // https://github.com/appium/droiddriver/blob/c1f89919ed5e88650548f34fe8ca9e5d458a41df/src/io/appium/droiddriver/finders/ByXPath.java#L198
384 | private static byte[] dumpDomBytes(View view) throws Exception {
385 | String path = DUMP_XML.toString();
386 | BufferedOutputStream bos = null;
387 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
388 |
389 | try {
390 | bos = new BufferedOutputStream(baos);
391 | Transformer transformer = TransformerFactory.newInstance().newTransformer();
392 | transformer.setOutputProperty(OutputKeys.INDENT, "yes");
393 | clearData();
394 |
395 | Element domNode = getDomNode(view, 0);
396 | transformer.transform(new DOMSource(domNode), new StreamResult(bos));
397 | Log.i(TAG, "Wrote dom to " + path);
398 | } catch (Exception e) {
399 | Log.e(TAG, "Failed to transform node", e);
400 | throw e;
401 | } finally {
402 | clearData();
403 | if (bos != null) {
404 | try {
405 | bos.flush();
406 | bos.close();
407 | } catch (Exception e) {
408 | // ignore
409 | }
410 | }
411 | }
412 | return baos.toByteArray();
413 | }
414 |
415 | /**
416 | * Dumps view as a String
417 | **/
418 | private static String dumpDom(View view) throws Exception {
419 | return new String(dumpDomBytes(view), Charsets.UTF_8);
420 | }
421 |
422 | /**
423 | * Dumps view xml and png.
424 | * Download with adb pull /sdcard/Android/data/com.example.android.testing.espresso.BasicSample/cache/dump
425 | **/
426 | private static boolean dumpToFile(View view) {
427 | boolean result = false;
428 | dumpDir.mkdirs();
429 | DUMP_PNG.delete();
430 | DUMP_XML.delete();
431 | try {
432 | device.takeScreenshot(DUMP_PNG);
433 | Files.write(dumpDomBytes(view), DUMP_XML);
434 | result = true;
435 | } catch (Exception e) {
436 | // ignored
437 | }
438 | return result;
439 | }
440 |
441 | /**
442 | * Invoke ViewToUix.dumpView(); from a test to dump the view
443 | **/
444 | public static void dumpView() {
445 | GetRootView getRoot = new GetRootView();
446 | onView(allOf(isRoot())).perform(getRoot);
447 | View rootView = getRoot.getRootView();
448 |
449 | boolean dumpResult = ViewToUix.dumpToFile(rootView);
450 | Assert.assertTrue(dumpResult);
451 | }
452 | }
453 |
--------------------------------------------------------------------------------
/BasicSample/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
20 |
24 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/BasicSample/app/src/main/java/com/example/android/testing/espresso/BasicSample/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015, The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
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 com.example.android.testing.espresso.BasicSample;
18 |
19 | import android.app.Activity;
20 | import android.content.Intent;
21 | import android.os.Bundle;
22 | import android.view.View;
23 | import android.widget.EditText;
24 | import android.widget.TextView;
25 |
26 | /**
27 | * An {@link Activity} that gets a text string from the user and displays it back when the user
28 | * clicks on one of the two buttons. The first one shows it in the same activity and the second
29 | * one opens another activity and displays the message.
30 | */
31 | public class MainActivity extends Activity implements View.OnClickListener {
32 |
33 | // The TextView used to display the message inside the Activity.
34 | private TextView mTextView;
35 |
36 | // The EditText where the user types the message.
37 | private EditText mEditText;
38 |
39 | @Override
40 | protected void onCreate(Bundle savedInstanceState) {
41 | super.onCreate(savedInstanceState);
42 | setContentView(R.layout.activity_main);
43 |
44 | // Set the listeners for the buttons.
45 | findViewById(R.id.changeTextBt).setOnClickListener(this);
46 | findViewById(R.id.activityChangeTextBtn).setOnClickListener(this);
47 |
48 | mTextView = (TextView) findViewById(R.id.textToBeChanged);
49 | mEditText = (EditText) findViewById(R.id.editTextUserInput);
50 | }
51 |
52 | @Override
53 | public void onClick(View view) {
54 | // Get the text from the EditText view.
55 | final String text = mEditText.getText().toString();
56 |
57 | switch (view.getId()) {
58 | case R.id.changeTextBt:
59 | // First button's interaction: set a text in a text view.
60 | mTextView.setText(text);
61 | break;
62 | case R.id.activityChangeTextBtn:
63 | // Second button's interaction: start an activity and send a message to it.
64 | Intent intent = ShowTextActivity.newStartIntent(this, text);
65 | startActivity(intent);
66 | break;
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/BasicSample/app/src/main/java/com/example/android/testing/espresso/BasicSample/ShowTextActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015, The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
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 com.example.android.testing.espresso.BasicSample;
18 |
19 | import com.google.common.base.Strings;
20 |
21 | import android.app.Activity;
22 | import android.content.Context;
23 | import android.content.Intent;
24 | import android.os.Bundle;
25 | import android.widget.TextView;
26 |
27 | /**
28 | * A simple {@link Activity} that shows a message.
29 | */
30 | public class ShowTextActivity extends Activity {
31 |
32 | // The name of the extra data sent through an {@link Intent}.
33 | public final static String KEY_EXTRA_MESSAGE =
34 | "com.example.android.testing.espresso.basicsample.MESSAGE";
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 | setContentView(R.layout.activity_show_text);
40 |
41 | // Get the message from the Intent.
42 | Intent intent = getIntent();
43 | String message = Strings.nullToEmpty(intent.getStringExtra(KEY_EXTRA_MESSAGE));
44 |
45 | // Show message.
46 | ((TextView)findViewById(R.id.show_text_view)).setText(message);
47 | }
48 |
49 | /**
50 | * Creates an {@link Intent} for {@link ShowTextActivity} with the message to be displayed.
51 | * @param context the {@link Context} where the {@link Intent} will be used
52 | * @param message a {@link String} with text to be displayed
53 | * @return an {@link Intent} used to start {@link ShowTextActivity}
54 | */
55 | static protected Intent newStartIntent(Context context, String message) {
56 | Intent newIntent = new Intent(context, ShowTextActivity.class);
57 | newIntent.putExtra(KEY_EXTRA_MESSAGE, message);
58 | return newIntent;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/BasicSample/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bootstraponline/view_to_uix/636d942c5f0a01cc6e830f89b880c05d3280663f/BasicSample/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/BasicSample/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bootstraponline/view_to_uix/636d942c5f0a01cc6e830f89b880c05d3280663f/BasicSample/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/BasicSample/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bootstraponline/view_to_uix/636d942c5f0a01cc6e830f89b880c05d3280663f/BasicSample/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/BasicSample/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bootstraponline/view_to_uix/636d942c5f0a01cc6e830f89b880c05d3280663f/BasicSample/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/BasicSample/app/src/main/res/drawable-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bootstraponline/view_to_uix/636d942c5f0a01cc6e830f89b880c05d3280663f/BasicSample/app/src/main/res/drawable-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/BasicSample/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
24 |
25 |
26 |
35 |
36 |
37 |
43 |
44 |
51 |
52 |
53 |
60 |
61 |
--------------------------------------------------------------------------------
/BasicSample/app/src/main/res/layout/activity_show_text.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
22 |
23 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/BasicSample/app/src/main/res/values-v13/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/BasicSample/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/BasicSample/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 | 64dp
22 |
23 |
--------------------------------------------------------------------------------
/BasicSample/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | 16dp
20 | 32dp
21 |
22 |
--------------------------------------------------------------------------------
/BasicSample/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | Basic Espresso sample
19 | Hello Espresso!
20 | Change text
21 | type something…
22 | Open activity and change text
23 |
24 |
--------------------------------------------------------------------------------
/BasicSample/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/BasicSample/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.3.1'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/BasicSample/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/BasicSample/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bootstraponline/view_to_uix/636d942c5f0a01cc6e830f89b880c05d3280663f/BasicSample/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/BasicSample/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Nov 05 14:10:42 GMT 2014
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/BasicSample/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/BasicSample/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/BasicSample/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2014 The Android Open Source Project
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 |
2 | # view_to_uix
3 |
4 | Exports Espresso view in uiautomatorviewer format.
5 |
6 | # Use
7 |
8 | 1. Invoke [`ViewToUix.dumpView();`](https://github.com/bootstraponline/view_to_uix/blob/437a3be9c3a04ff0e8f21670baafef521f8a4ee8/BasicSample/app/src/androidTest/java/com/example/android/testing/espresso/BasicSample/ViewToUix.java#L444) [from your test.](https://github.com/bootstraponline/view_to_uix/blob/b87b4dd4749127c232c9a70adfe85517dc8928be/BasicSample/app/src/androidTest/java/com/example/android/testing/espresso/BasicSample/ChangeTextBehaviorTest.java#L79)
9 | 2. Download png and uix file with `adb pull /sdcard/Android/data/com.example.android.testing.espresso.BasicSample/cache/dump`
10 | 3. Open uiautomatorviewer then select [image and file](uix/)
11 |
12 | 4. Inspect the Espresso view hierarchy
13 |
14 |
15 | # Credits
16 |
17 | - [droiddriver](https://android.googlesource.com/platform/external/droiddriver)
18 | - [espresso](https://android.googlesource.com/platform/frameworks/testing/+/android-support-test)
19 | - [uiautomator](https://android.googlesource.com/platform/frameworks/uiautomator/+/android-support-test/src/main/java/android/support/test/uiautomator)
20 |
--------------------------------------------------------------------------------
/readme/inspector.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bootstraponline/view_to_uix/636d942c5f0a01cc6e830f89b880c05d3280663f/readme/inspector.png
--------------------------------------------------------------------------------
/readme/open_files.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bootstraponline/view_to_uix/636d942c5f0a01cc6e830f89b880c05d3280663f/readme/open_files.png
--------------------------------------------------------------------------------
/uix/espresso_dump.uix:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/uix/espresso_image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bootstraponline/view_to_uix/636d942c5f0a01cc6e830f89b880c05d3280663f/uix/espresso_image.png
--------------------------------------------------------------------------------