Issuing a synchronous HTTP GET request or invoking shell script in JavaScript from iOS UIAutomation

后端 未结 5 868
日久生厌
日久生厌 2021-02-09 08:05

I am trying to use Apple\'s UIAutomation to write unit tests for an iOS Application that has a server-side component. In order to setup the test server in various states (as wel

5条回答
  •  臣服心动
    2021-02-09 08:43

    Just a small correction. The answer that suggests using UIATarget.host().performTaskWithPathArgumentsTimeout is an easy way to make a request on a URL in iOS 5.0+, but the syntax of the example is incorrect. Here is the correct way to make this call:

    UIATarget.host().performTaskWithPathArgumentsTimeout("/usr/bin/curl", ["http://google.com"], 30);
    

    The "[" around the "args" param is important, and the test will die with an exception similar to the following if you forget the brackets:

    Error: -[__NSCFString count]: unrecognized selector sent to instance

    Here is a fully working example that hits google.com and logs all the output:

    var result = UIATarget.host().performTaskWithPathArgumentsTimeout("/usr/bin/curl", ["http://www.google.com"], 30);
    
    UIALogger.logDebug("exitCode: " + result.exitCode);
    
    UIALogger.logDebug("stdout: " + result.stdout);
    
    UIALogger.logDebug("stderr: " + result.stderr);
    

提交回复
热议问题