Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
825 views
in Technique[技术] by (71.8m points)

robotframework - Extract data from test and easily analyze it using robot framework

I am running a robot_test.robot file and I want to run a specific scenario (Search google in this case) multiple times. I am logging required information in the console i.e.

  1. time taken by they keyword with index number
  2. pass/fail status of the keyword
  3. total time taken by the complete test after all the iterations
  4. More data may be added later.

I wanted to know if robot provides the ability to use the information I have and present it in a report (e.g. any html or excel file) which makes it easy to analyze the stats instead of reading from the console.

If there are any other recommended approaches to extract or collect data from test cases, please feel free to share.

I like the detailed information of the whole script generated by robot in the log.html for each test run but looking for something to view our own extracted data from the test.

robot_test.robot

*** Settings ***
Library  Selenium2Library
Library  Collections
Library  DateTime
#Suite Setup
Suite Teardown  Close All Browsers
#Test Setup  Open Browser    ${URL}   ${BROWSER}
#Test Teardown  Close All Browsers


*** Variables ***
${URL}              http://www.google.com
${BROWSER}          Chrome
${search_form}      css=form[name=f]
${search_form2}      css=form[name=fac]
${search_query}     css=input[name=q]
${search_term}      RobotFramework
${test_case_run_time}  3600 #1 hr = 3600 seconds

*** Keywords ***
Search google
    Open Browser    ${URL}   ${BROWSER}
    Wait Until Element Is Visible  ${search_form}
    Wait Until Element Is Visible  ${search_query}
    Input Text      ${search_query}   ${EMPTY}
    Input Text      ${search_query}   ${search_term}
    Wait Until Element Is Visible  ${search_form2}
    Submit Form
    Close All Browsers

*** Test Cases ***

Test with Time
    ${timeBeforeTestCaseStart} =    Get Current Date

    FOR  ${INDEX}  IN RANGE  1  5
      ${timeBeforeOrderPlacing} =   Get Current Date
      ${status} =  Run Keyword And Ignore Error  Search google
      ${timeAfterOrderPlacing} =    Get Current Date
      ${timeTotalForOrderPlacementInMs} =    Subtract Date From Date    ${timeAfterOrderPlacing}    ${timeBeforeOrderPlacing}    result_format=number
      Log To Console  Time taken by test case no.${INDEX}: ${timeTotalForOrderPlacementInMs} seconds
      Log To Console  Status and Reason: ${status}

      ${timeAfter} =    Get Current Date
      ${timePassedTillNow} =    Subtract Date From Date    ${timeAfter}    ${timeBeforeTestCaseStart}    result_format=number
      Should be true    ${timePassedTillNow} < ${test_case_run_time}
    END

    ${timeAtEndOfTestCase} =    Get Current Date
    ${totalTimeForAllTestCases} =    Subtract Date From Date    ${timeAtEndOfTestCase}    ${timeBeforeTestCaseStart}    result_format=number
    Log To Console  Time taken by all test cases: ${totalTimeForAllTestCases} seconds

Log Output

(RobotFwTestProject1) C:UsersfaizancPycharmProjectsRobotFwTestProject1>robot "robot filesgoogle-search-continue-on-failure.robot"
==============================================================================
Google-Search-Continue-On-Failure
==============================================================================
Test with Time                                                        .
DevTools listening on ws://127.0.0.1:63742/devtools/browser/d8ef44d7-218c-44c5-a1e6-0918dbf5720c
[8900:14596:0126/141654.469:ERROR:device_event_log_impl.cc(211)] [14:16:54.466] Bluetooth: bluetooth_adapter_winrt.cc:1072 Getting Default Adapter failed.
Time taken by test case no.1: 11.023 seconds
Status and Reason: ('FAIL', "Element 'css=form[name=fac]' not visible after 5 seconds.")

DevTools listening on ws://127.0.0.1:63767/devtools/browser/cc4ddf86-0690-41a2-a04c-56fd0c998c11
[9960:4320:0126/141709.461:ERROR:device_event_log_impl.cc(211)] [14:17:09.470] Bluetooth: bluetooth_adapter_winrt.cc:1072 Getting Default Adapter failed.
Time taken by test case no.2: 10.318 seconds
Status and Reason: ('FAIL', "Element 'css=form[name=fac]' not visible after 5 seconds.")
...Time taken by all test cases: 21.357 seconds
Test with Time                                                        | PASS |
------------------------------------------------------------------------------
Google-Search-Continue-On-Failure                                     | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output:  C:UsersfaizancPycharmProjectsRobotFwTestProject1output.xml
Log:     C:UsersfaizancPycharmProjectsRobotFwTestProject1log.html
Report:  C:UsersfaizancPycharmProjectsRobotFwTestProject1
eport.html
question from:https://stackoverflow.com/questions/65899098/extract-data-from-test-and-easily-analyze-it-using-robot-framework

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...