5 Replies Latest reply: Nov 20, 2012 12:31 PM by POPS. RSS

    how to fail the test case when the expected value is not met

    807307
      hi

      below is the sceanrio where iam checking whether PO is approved or not in the status.


      what i require is if the status is not approved it should fail and show the result as fail in the oats report.


      below is the code which i have used for checking status but want to know how to fail thru script and report the result.


      if (strStatus.equalsIgnoreCase("Approved")){
                          String strResult=""+strStatus+" value is as Expected Value";
                          info(strResult);
                          System.out.println("Field Status is ---->" +strStatus);
                          //info("Changed to "+strStatus+" Status Sucessfully");
                          break;
                          }
                     else {
                          String strResult=""+strStatus+" value is not as Expected Value";
                          info(strResult);
                          break;
        • 1. Re: how to fail the test case when the expected value is not met
          834498
          You just have to use :
          fail("my message");
          instead of
          info("");

          Of course, using that one will stop script execution and go to finish section.

          JB
          • 2. Re: how to fail the test case when the expected value is not met
            807307
            thanks JB

            it is working

            i need one more help that is whatever test case iam running iam capturing the resultcode and placing it in the UI as PASS or FAIL by using below code in the finish iteration.

            ResultCode result=getLastResult().getResultCode();


            but when my using the below code to fail whenever expected value is not matching it is failing and it is showing failed in the report but from the Result code it is returning PASS.

            how to get Fail in the result code.

            String strResult=""+strStatus+" value is not as Expected Value";
                                fail(strResult);
                                break;

            can you help me on this.
            • 3. Re: how to fail the test case when the expected value is not met
              834498
              Not sure to understand what you are trying to achieve..

              It reminds something I read but can't find it out...

              Stupid question: why don't you use "object test"?

              Can you paste here your code?
              • 4. Re: how to fail the test case when the expected value is not met
                807307
                below code is in run


                String strStatus=forms.textField(13,"//forms:textField[(@name='"+identifier+"')]").getText();
                               if (strStatus.equalsIgnoreCase("Approved")){
                                    String strResult=""+strStatus+" value is as Expected Value";
                                    info(strResult);
                                    System.out.println("Field Status is ---->" +strStatus);
                                    //info("Changed to "+strStatus+" Status Sucessfully");
                                    break;
                                    }
                               else {
                                    String strResult=""+strStatus+" value is not as Expected Value";
                                    fail(strResult);
                                    break;
                               }


                in finish

                public void finish() throws Exception {
                          updateStatus();

                     }



                below is the updateStatus method


                private void updateStatus() {
                          
                          try {
                               ResultCode result=getLastResult().getResultCode();
                               System.out.println("***Result---->" + result);
                          } catch (ResultUnavailableException e) {
                               // TODO Auto-generated catch block
                               e.printStackTrace();
                          }
                     }

                i am getting the ResultCode as PASS but the result is failed.

                i am using the ResultCode as reference to show that my test case is passed or failed in the UI which is my requirement.
                • 5. Re: how to fail the test case when the expected value is not met
                  POPS.
                  Hi,

                  hope this will help you.


                  in run

                  beginStep("Check PO Status", 1000);
                            {
                                 
                                 String strStatus=forms.textField("XPATH_OF_THE_OBJECT").getText();

                                 if (strStatus.equalsIgnoreCase("Approved"))
                                 {
                                      getStepResult().addComment("PO is approved");
                                 }
                                 else
                                 {
                                                               
                                      AttachedData data = new AttachedData();
                                      data.set(ResultDeclaration.verifyText_expected, "Approved");
                                      data.set(ResultDeclaration.verifyText_actual, strStatus);
                                      IResult result = new Result(ResultCode.FAIL, 1000, null, data, "PO is not approved");     
                                      setLastResult(result);
                                      
                                      fail(result.getSummary());
                                      
                                      /*
                                      * Or we can use getStepResult().setError(result.getSummary());
                                      * But it will not stop script execution like fail
                                      */
                                                

                                 }
                                 
                            }
                            endStep();






                  in finish

                  public void finish() throws Exception {
                  updateStatus();

                  }


                  below is the updateStatus method

                  private void updateStatus() {

                  try {
                  ResultCode result=getLastResult().getResultCode();
                  System.out.println("***Result---->" + result);
                  } catch (ResultUnavailableException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                  }
                  }




                  Thanks
                  -Pops