Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing resources for Android UI Automator tests
    primarykey
    data
    text
    <p>I'm working on a set of tests using UI Automator on Android. I have it working, but my current tests are made with lots of string literals.</p> <p>The string literals were fine when I was just trying to get things to work in the first place, but they will be bad going forward. If the app is changed, the string literals will need to be changed to match. Also, it's stupid that my tests would have to be completely redone to test localized builds in other languages.</p> <p>The app itself has all strings stored in resources. Every string has an invariant identifier... here's an example:</p> <pre><code>&lt;string name="more_options"&gt;More options&lt;/string&gt; </code></pre> <p>The app code will always use the name <code>more_options</code> to look up the string resource, rather than hard-coding <code>"More options"</code> into the code.</p> <p>So what I want is to import all the string resources, store them in some kind of map object, and then in my UI Automator test code use something like <code>m.get("more_options")</code> rather than a literal string <code>"More options"</code> as I do now.</p> <p>Whatever I do, I want it to just be part of the JAR file that gets built and pushed to the device to run the tests. I don't want to, for example, push the XML string resource files to the device and try to read them at test runtime. I want to have the data built in when the JAR file is built.</p> <p>I looked at the files produced by building the app, and the names like <code>more_options</code> are just set to integers. These must be indexes or pointers into a store of resources, but I'm not sure how I could copy that store into my UI Automator project and get it connected up; in an Android app you use a <code>Context</code> object to access resources, and a UI Automator JAR file doesn't have a <code>Context</code>.</p> <p>This has to be a common problem, and people must have solved it already, but my Google searches haven't found any discussions of how people are solving this.</p> <p>If I don't get any advice, I'm going to write a Python script that imports the XML file and writes a Java file that has a function that builds the map I need, then call that from my UI Automator test programs. (I have a Python script that runs the sequence of command-line tools to kick of a UI Automator test, anyway... I don't mind making that do more work.) But I figure there should be a pure-Java solution for this, probably one that involves grabbing the already-compiled files out of the application's source directory.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload