Forum Discussion

jcatayong's avatar
jcatayong
Contributor
7 years ago

Is there anyway on how to get testcase status after test run and print it to logs?

Is there anyway on how to get testcase status after test run and print it to logs? 
For example:

// after test execution

var TestStatus = TestCase.Status();

Log.Message("Test case status is " + TestStaus); // either passed or failed

 

thanks,

 

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Define a test case?  Is it a script function? Some combination of script functions? A keyword test? 

     

    No matter what, by default, executing a function or keyword test does not return a "status".  You need to determine the status of a test case yourself and do the necessary code to return some sort of result or status.  Then, in your framework structure that executes the tests, you can check that result and write out to the log the pass/fail of the test case.

    • jcatayong's avatar
      jcatayong
      Contributor

      Hi,

       

      The TestCase that i metioned here was from a keyword tests

       

       

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        As mentioned, keyword tests do not return a "status".  Think of each keyword test as a code function.  If you write a function like so:

         

        function noStatus(){
            Log.Message('This is just a function that does stuff');
        }

        That function just executes and writes the log.  There is no feedback from the code to indicate any status of that function.  If, however, you write it like this:

         

        function giveMeStatus(myStatus){
            Log.Message('This is a function that returns a status');
            if (myStatus) {
                return true;
            }
            else {
                return false;
            }
        }

        Then you can do something like this

         

        function checkMyStatus(){
            if (giveMeStatus(true)) {
                 Log.Message('giveMeStatus Passed');
            }    
            else {
                 Log.Message('giveMeStatus Failed');
            }
        
        
        }

        It's all in the way you write your code.  If you want your keyword tests to return a value that you can then check to see if it passed or failed, then you need to actually have it "return" a value using the Return operation.  Otherwise, it just executes something.