Showing posts with label Robot Framework. Show all posts
Showing posts with label Robot Framework. Show all posts

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.



Wednesday, October 25, 2017

Troubleshooting Chrome WebDriver in Robot Framework


I had a nightmare recently. I had my Selenium script finished in Robot Framework and I was able to run pybot every time with no problem. However, it threw an ugly exception error when I added the test suite to our Jenkins pipeline:

| FAIL |
WebDriverException: Message: chrome not reachable
  (Driver info: chromedriver=2.24.417424 (c5c5ea873213ee72e3d0929b47482681555340c3),platform=Linux 3.10.0-229.20.1.el7.x86_64 x86_64)

I made sure that both chromedriver and google-chrome-stable are updated and available in path, but still couldn't figure why Jenkins was unable to run the same command in same box.

My best friend, google, said that's possibly because the user (Jenkins) can not reach Chrome's debugging ports and I could fix it easily by adding browser "options" in the code. I sounds easy now, but there is no single page in google to tell me how to set those options in ROBOT not Python, Java, etc.

At the end, here was my solution:


  • Don't use keyword:  Open Browser 
  • Instead, make and use a keyword this way:
Open Chrome With Options ${url}
   Log     Creating WebDriver   WARN
   Start Virtual Display    1920   1920
   ${options}=  Evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys
    Call Method   ${options}   add_argument   --no-sandbox
    Call Method   ${options}   add_argument   --disable-setuid-sandbox
    Create WebDriver   Chrome   chrome_options=${options}
    Go To   ${url}