Tuesday, April 24, 2018

Integrating SoapUI into Robot Framework without plugins

If you find yourself so addicted to SoapUI but have to use Robot Framework for compatibility, then good news. It's really easy. At first I searched for a reliable Robot plugin but the best I could find was from years ago and needed Jython to be install on the test server.
So I started to work on my own Robot Project, and found it fairly easy.

I used SoapUI free 5.4.0 to create my test suite and test cases. Then made some keywords in my robot file:

*** Variables ***
${SoapUI_suite}=     TestSuite
${SoapUI_Project}=   Project_File
${test_runner}=   /home/pprz/SoapUI-5.4.0/bin/testrunner.sh
${output_path}=  /tmp

*** Keywords ***
SoapUI Test Runner ${Test_Case}
   ${cmd_out}=  Run  unset DISPLAY && ${test_runner} -s ${SoapUI_suite} -c ${Test_Case} -rMI -f ${output_path} ${SoapUI_Project} | tail -10
   Log  ${Test_Case} Test Case Results Summary: ${cmd_out}  WARN
   Should Contain  ${cmd_out}  SoapUI 5.4.0 TestCaseRunner Summary
   File Should Exist  ${output_path}/test_case_run_log_report.xml

Process XML results ${Test_Case}
   ${xml_out}=  Get File   ${output_path}/test_case_run_log_report.xml
   ${root}=  Parse XML  ${xml_out}
   Element Attribute Should Be  ${root}  testCase  ${Test_Case}
   ${result}=  Get Element Attribute  ${root}  status
   Run Keyword If  '${result}' == 'FINISHED'  Log  Test Case: ${Test_Case} Passed, Result: ${result}   WARN
   Run Keyword If  '${result}' != 'FINISHED'   Report Failed Case ${Test_Case}

Report Failed Case ${Test_Case}
   ${xml_out}=  Get File   ${output_path}/test_case_run_log_report.xml
   ${root}=  Parse XML  ${xml_out}
   @{test_steps}=  Get Elements  ${root}  testCaseRunLogTestStep
   :FOR  ${step}  IN  @{test_steps}
   \  ${step_status}=  Get Element Attribute  ${step}  status
   \  ${step_name}=  Get Element Attribute  ${step}  name
   \  ${failed_steps}=  Set Variable If  '${step_status}' != 'OK'  ${failed_steps}, "${step_name}"
   \  ${timeTaken}=  Get Element Attribute  ${step}  timeTaken
   \  Log  Step: ${step_name} , Time Taken: ${timeTaken}, Status: ${step_status}  WARN
   \  Run Keyword If  '${step_status}' != 'OK'   Get Message ${step_name}
   Fail  \nTest Case ${Test_Case} Failed in following steps: ${failed_steps}

Get Message ${step_name}
   ${xml_out}=  Get File   ${output_path}/test_case_run_log_report.xml
   ${root}=  Parse XML  ${xml_out}
   ${failed_step}=  Get Element  ${root}  testCaseRunLogTestStep[@name="${step_name}"]
   @{failed_messages}=  Get Elements Texts  ${failed_step}  message
   Log  ${failed_messages}[0]  WARN

TestRunner ${case}
  SoapUI Test Runner ${case}
  Process XML results ${case}

Delete XML Report
  Run  rm -f ${output_path}/test_case_run_log_report.xml &>/dev/null



The key here is having testrunner to run each test case separately then capture its summary and XML report file that is generated becuase of "-rMI" arguments. The key word "TestRunner ${case}" runs the testcase and Passes if it's value is "Finished" otherwise will throw the error message from XML and fails the case.



No comments:

Post a Comment