简体   繁体   中英

How to Stop the automation testing in ios

Is there any possible way to stop the automation testing? Actually im testing my app with automation javascript. I have two test in my script. if the first test fail i dont want to continue my script.. MY code:

var target = UIATarget.localTarget();
var testname = "Test1";
UIALogger.logStart(testname);
target.frontMostApp().mainWindow().buttons()[0].tap();
UIALogger.logPass(testname);
target.delay(2);

var testname = "Test2";
UIALogger.logStart(testname);
target.frontMostApp().mainWindow().buttons()[1].tap();
target.frontMostApp().mainWindow().buttons()[0].tap();
UIALogger.logPass(testname);

Here if the test1 fails i have to say the script to stop the process.. please tell me any suggestion to this problem. Thanks...

You should really look at abstracting out your tests. You can use something like:

function test(description, steps) {
    try{
        UIALogger.logStart(description);
        steps();
        UIALogger.logPass("Test Passed");
    } catch (exception) {
        UIALogger.logError(exception.message);
        UIATarget.localTarget().logElementTree();
        UIALogger.logFail("Test Failed");
        throw exception;
    }
}

as a function you can wrap your test in. As you can see, it will start the test, complete the steps of your test (if possible). If it failed, the test will log the element tree (very handy) and then will throw the same error again, stopping the test from continuing, and giving information about the error you experienced.

I highly recommend using tuneup_js for running UIAutomation. I don't think you can stop the Test run if one test fails using Instruments GUI, but it will stop when using the tuneup_js library and running the tests from the command line

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM