Forum Stats

  • 3,727,659 Users
  • 2,245,434 Discussions
  • 7,852,908 Comments

Discussions

How to get Overall Result of Script in OpenScript

Martin Zehetmeier
Martin Zehetmeier Member Posts: 7 Green Ribbon
edited August 2020 in QA/Testing

Hello,

we use OpenScript (Version: 13.3.0.1 Build 262) on Windows 10 and Internet Explorer 11.900

In my very simple test script I launch a browser, open a website and check for a text on the site "test" which is not present and that's why the test fails.

In the finish section I want to get the overall result of my script (which should be failed - as the Reports says too

Overall Result: Failed

Result failed: The text "test" is not found in the HTML content. 

But however I try to log this result it shows me my script has passed

See below for the output of my own info-Logs.

So my question is: How can I access the result of the Overall Result in the Java code and the summary.

Any help is appreciated.

Please see my code and console below.

15:12:32,315 INFO  [1] has LastError15:12:32,345 INFO  [1] getLastError null15:12:32,414 INFO  [1] No Exception15:12:32,440 INFO  [1] isIterationPassed passed15:12:32,467 INFO  [1] isLastResultPassed passed

public void initialize() throws Exception {browser.launch();}

/*** Add code to be executed each iteration for this virtual user.*/public void run() throws Exception {beginStep("[1] No Title (/spread)", 0);{web.window(17,"/web:window[@index='0' or @title='Help Spread DuckDuckGo']").navigate("https://duckduckgo.com/spread");{think(5.733);web.assertText("test", "test", Source.DisplayContent,TextPresence.PassIfPresent, MatchOption.Exact);}}endStep();}

public void finish() throws Exception {if (hasLastError()) {  info("has LastError");  info("getLastError " + String.valueOf(getLastError()));}         Exception exception = getIterationResult().getError();         if(exception == null){             info("No Exception");         }         else{             info("Exception");             info(exception.getMessage());         }         boolean isIterationPassed = getIterationResult().isPassed();         if(isIterationPassed){           info("isIterationPassed passed");         }         else{           info("isIterationPassed not passed");         }                 boolean isLastResultPassed = getLastResult().isPassed();         if(isLastResultPassed){           info("isLastResultPassed passed");         }         else{           info("isLastResultPassed not passed");         }     browser.close();}

Answers

  • Deepu Muraleedharan
    Deepu Muraleedharan Member Posts: 468 Silver Badge
    edited August 2020

    Hi Martin,

    Try getLastError().getMessage()

    public void run() throws Exception {

            beginStep("");{

                web.assertText("test", "aaaa", Source.DisplayContent,

                        TextPresence.PassIfPresent, MatchOption.Exact);

               

            }endStep();

        }

        public void finish() throws Exception {

            System.out.println(getLastError().getMessage());

        }

  • Martin Zehetmeier
    Martin Zehetmeier Member Posts: 7 Green Ribbon

    Thank you, this has worked! I now check "getLastError().getMessage() " for null - then I guess it was a success.

  • Martin Zehetmeier
    Martin Zehetmeier Member Posts: 7 Green Ribbon

    @Deepu Muraleedharan

    I still have a problem.

    In cases of a runtime problem like

    oracle.oats.scripting.modules.basic.api.exceptions.VariableNotFoundException

    this does not seem to work. As there also "getLastError().getMessage() " is null.

  • Deepu Muraleedharan
    Deepu Muraleedharan Member Posts: 468 Silver Badge
    edited October 2020

    Hi Martin,

    Try this.....

    public void run() throws Exception {

          try{

             beginStep("Step 1");{

                info("{{testVar}}");

             }endStep();

          }

          catch(Exception e){

             System.out.println("Outcome :" + getStepResult().getOutcome());

             System.out.println("Outcome :" + getStepResult().getErrorString());

          }

       }

       public void finish() throws Exception {

          if(getLastError()!= null)

             System.out.println(getLastError().getMessage());

       }


    Thanks,

    DeepuM

  • Martin Zehetmeier
    Martin Zehetmeier Member Posts: 7 Green Ribbon

    Hi, thank you again!

    Does it make a difference in general when we have an assertion that fails or something unexpectedly happens at runtime like the site does not load (timeout) or an element was not found?

    Because when I use "fail" to failk my test or an assertion fails like "assertAttributes" it seems to work getting getLastError().getMessage()  but whenever an unexpected thing happens it also Null though I would expect a error message should be there.


    I really wonder how the script itself gets the Overall Result and if it's possible to get this easily in the finish-section.

  • Deepu Muraleedharan
    Deepu Muraleedharan Member Posts: 468 Silver Badge

    Check what is getting printed

    info("{{result.code}}");


    Thanks,

    DeepuM

  • Martin Zehetmeier
    Martin Zehetmeier Member Posts: 7 Green Ribbon

    Hello Deepu,


    I tried it:

    public void finish() throws Exception {

    info("Result.Code: " + "{{result.code}}");

    }


    I made my test fail by inserting an invalid object which leads to:


    oracle.oats.scripting.modules.webdom.common.api.exception.PlaybackException:



    INFO [1] Result.Code: PASS

  • Deepu Muraleedharan
    Deepu Muraleedharan Member Posts: 468 Silver Badge

    Hi Martin,

    I'm using code as follows...

    Every stepgroup last line will be a library method call to fetch status, duration, and comments. So we can either store or print in console or database/report. I'm storing all stepgroup results to Map<id, List>, and calling a method in the finish to consolidate and insert to a database for report dashboard. This may help you...



    Thanks,

    DeepuM

Sign In or Register to comment.