java - Accessing resources for Android UI Automator tests -
i'm working on set of tests using ui automator on android. have working, current tests made lots of string literals.
the string literals fine when trying things work in first place, bad going forward. if app changed, string literals need changed match. also, it's stupid tests have redone test localized builds in other languages.
the app has strings stored in resources. every string has invariant identifier... here's example:
<string name="more_options">more options</string>
the app code use name more_options
string resource, rather hard-coding "more options"
code.
so want import string resources, store them in kind of map object, , in ui automator test code use m.get("more_options")
rather literal string "more options"
now.
whatever do, want part of jar file gets built , pushed device run tests. don't want to, example, push xml string resource files device , try read them @ test runtime. want have data built in when jar file built.
i looked @ files produced building app, , names more_options
set integers. these must indexes or pointers store of resources, i'm not sure how copy store ui automator project , connected up; in android app use context
object access resources, , ui automator jar file doesn't have context
.
this has common problem, , people must have solved already, google searches haven't found discussions of how people solving this.
if don't advice, i'm going write python script imports xml file , writes java file has function builds map need, call ui automator test programs. (i have python script runs sequence of command-line tools kick of ui automator test, anyway... don't mind making more work.) figure there should pure-java solution this, 1 involves grabbing already-compiled files out of application's source directory.
i stuck similar problem. ended creating static hash map in java string literals. had files different languages same key , localized values.
then wrote module manipulate device language @ runtime , return corresponding localized value key.
Comments
Post a Comment