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
656 views
in Technique[技术] by (71.8m points)

robotframework - python tests using robot framework

Does anyone have a good example of testing a python program using Robot Framework.

I am trying to run my python program (chaptermarkers.py) with an argument of --test and checking the results.

Passing the argument has been an odyssey of google searches for 2 days.

[file: common_resourses.robot]

*** Settings ***
Library  OperatingSystem

*** Variables ***
${CHAPTERMARKERS_EXEC}  chaptermarkers
${LOG LEVEL}    DEBUG

*** Keywords ***
# TODO

[Test Cases: file: default_suite.robot]

*** Settings ***
Documentation       *Test Chapter Markers runs but has error in filename*
Metadata    Github  https://github.com/cbitterfield/chaptermarkers
Metadata    Version 1.0.0
Metadata    Executed At    ${HOST}


# External libraries imports
Library  Process
Library  String

Resource    common_resources.robot

*** Variables ***
${EXPECTED_MESSAGE}  Movie Filename
${REPORT FILE}  report.html
${LOG FILE}     logfile.html
${LOG LEVEL}    DEBUG
${OUTPUT DIR}   /Users/colin/IdeaProjects/chaptermarkers
${test} --test


*** Test Cases ***

    Scenerio test chaptermarkers run
        [Tags]    DEBUG
        [Documentation]     Verifies that chaptermarkers is executed well and without errors
        ${result}=  Run process     ${CHAPTERMARKERS_EXEC} ${test}
        Should Contain  ${result.stdout}    ${EXPECTED_MESSAGE}
        Should Be Empty     ${result.stderr}

No matter how I try to put something after the program, I get an error of directory missing.

[Crazy unusable error messages]

$ robot --loglevel DEBUG --log log.html --report report.html stests/default_suite.robot 
[ ERROR ] Error in file '/Users/colin/IdeaProjects/chaptermarkers/stests/default_suite.robot' on line 25: Invalid variable name '${test} --test'.
==============================================================================
Default Suite :: *Test Chapter Markers runs but has error in filename*        
==============================================================================
Scenerio test chaptermarkers run :: Verifies that chaptermarkers i... | FAIL |
Variable '${test}' not found. Did you mean:
    ${TEST_TAGS}
    ${TEST_NAME}
------------------------------------------------------------------------------
Default Suite :: *Test Chapter Markers runs but has error in filen... | PASS |
0 critical tests, 0 passed, 0 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output:  /Users/colin/IdeaProjects/chaptermarkers/output.xml
[ ERROR ] Unexpected error: FileNotFoundError: [Errno 2] No such file or directory: '/Users/colin/IdeaProjects/chaptermarkers/env/lib/python3.8/site-packages/robot/htmldata/rebot/log.html'
Traceback (most recent call last):
  File "/Users/colin/IdeaProjects/chaptermarkers/env/lib/python3.8/site-packages/robot/utils/application.py", line 83, in _execute
    rc = self.main(arguments, **options)
  File "/Users/colin/IdeaProjects/chaptermarkers/env/lib/python3.8/site-packages/robot/run.py", line 451, in main
    writer.write_results(settings.get_rebot_settings())
  File "/Users/colin/IdeaProjects/chaptermarkers/env/lib/python3.8/site-packages/robot/reporting/resultwriter.py", line 65, in write_results
    self._write_log(results.js_result, settings.log, config)
  File "/Users/colin/IdeaProjects/chaptermarkers/env/lib/python3.8/site-packages/robot/reporting/resultwriter.py", line 79, in _write_log
    self._write('Log', LogWriter(js_result).write, path, config)
  File "/Users/colin/IdeaProjects/chaptermarkers/env/lib/python3.8/site-packages/robot/reporting/resultwriter.py", line 86, in _write
    writer(path, *args)
  File "/Users/colin/IdeaProjects/chaptermarkers/env/lib/python3.8/site-packages/robot/reporting/logreportwriters.py", line 43, in write
    self._write_file(path, config, LOG)
  File "/Users/colin/IdeaProjects/chaptermarkers/env/lib/python3.8/site-packages/robot/reporting/logreportwriters.py", line 36, in _write_file
    writer.write(template)
  File "/Users/colin/IdeaProjects/chaptermarkers/env/lib/python3.8/site-packages/robot/htmldata/htmlfilewriter.py", line 33, in write
    for line in HtmlTemplate(template):
  File "/Users/colin/IdeaProjects/chaptermarkers/env/lib/python3.8/site-packages/robot/htmldata/normaltemplate.py", line 28, in __iter__
    with codecs.open(self._path, encoding='UTF-8') as file:
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/codecs.py", line 905, in open
    file = builtins.open(filename, mode, buffering)
(env) razzamataz:chaptermarkers colin$ 
question from:https://stackoverflow.com/questions/65623690/python-tests-using-robot-framework

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

1 Answer

0 votes
by (71.8m points)

A few things I noticed:

  1. There needs to be at least two spaces between ${test} and --test in your variables section. You provided only one. The same in the Run Process line, there should be at least two spaces between exec and argument. The rule is that RF uses two spaces as delimiter.
  2. Your test name is indented. RF inteprets it as a keyword calling which is unexpected. It should start from the begining of the line without indent
  3. The file missing error looks weired and I don't know the reason. The file is part of RF library and if you installed RF correctly, it should be there. I suggest that you start a new virtual environment and try again if it's not too complex.

P.S. Just FYI, all RF buil-in libraries can be found here: https://robotframework.org/#libraries.


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

...