I want to write UIAutomation (JavaScript based) tests for a rather plex iPhone App. I dont't want to use one single huge file, but to seperate the testing functions and helpers by using several files. Is that possible at all? How do you structure your UIAutomation tests?
I want to write UIAutomation (JavaScript based) tests for a rather plex iPhone App. I dont't want to use one single huge file, but to seperate the testing functions and helpers by using several files. Is that possible at all? How do you structure your UIAutomation tests?
Share Improve this question edited Sep 22, 2011 at 19:33 nschum 15.4k5 gold badges60 silver badges56 bronze badges asked Mar 21, 2011 at 17:41 Rene BerlinRene Berlin 1,1717 silver badges21 bronze badges2 Answers
Reset to default 8Hey.
Yes it is. Although import
keyword is not implemented for JS in browsers, it is implemented in Instruments. You just write #import "somefile.js"
in 'master' JS file which you run with Instruments. I haven't tried to include file from locations other than original file you're providing to instruments, but sub folders for that location work.
Look a following example based on this post:
#import "fileInTheSameDirectory.js"
#import "SubDirectory/fileInSubDirectory.js"
UIAutomation cannot handle large script files that you might end up with bundling your tests, helper functions, etc. - using the #include
directive. However, it is the only way you can manually run multiple tests, stored within separate files.
I have encountered this problem when building a small (600-700 lines or 25KB of code) JS framework that is able to run test sets and suites.
The test structure I came up with:
#import "test_scripts.js"
#import "test_data.js"
#import "helper_tools.js"
tools.runTestSet(TestContainer);
Where TestContainer
is the link to an object holding all my test cases as its fields/members.
And test_data.js
encapsulates data within JSON container.
P.S. at first I thought that UIAutomation has a great potential, but in the course of time I got disappointed. You cannot run plete automation testing cycles using this tool. Also, keep in mind that it provides you with API to work with UI only: no access to the "back-end" processes.