Search code examples
javascriptios7xcode5ios-ui-automation

IOS UI Automation - working with external Data


Is there any way to work with external Data, for example Textfiles ? With JS there isn´t any option to do I/O, for a good reason. The purpose is, that i want to validate data from a file or a database with the data represented in the APP (comparison tests)… Is there any trick for the UI Automation tool ?


Solution

  • Text file

    This is something I came up with based on performTaskWithPathArgumentsTimeout method:

    var target = UIATarget.localTarget();
    var host = target.host();
    var result = host.performTaskWithPathArgumentsTimeout(
                         "/bin/cat", ["/Users/username/Documents/test.txt"], 5)
    
    var content = result.stdout;
    UIALogger.logMessage(content);
    

    Content of the test.txt:

    Hello World!
    This is a test.

    And this is how it looks in the Editor Log:

    enter image description here

    The downside is that you'll have to manually parse file's content.

    Database

    The only feasible option I can see, is to use this same method in conjunction with Command Line Shell For SQLite. But, alas, I haven't tried this approach, so I can't guarantee it'll work.