Running tests on PyCharm using Robot Framework

非 Y 不嫁゛ 提交于 2019-11-27 21:38:53

I have used the Intellibot PyCharm plugin for Robot Framework.

For running the tests, we can do the below configuration:

  1. Go to File > Settings > External Tools
  2. Click '+' button under 'External Tools' panel
  3. In the 'Create Tool' dialog, enter the below values:
    • Name: Robot
    • Program: [Path of Pybot.bat e.g.C:\Python27\Scripts\Pybot.bat]
    • Parameters: $FileName$
    • Working Directory: $FileDir$
  4. Click OK

Once the above configuration is done, we get the option 'Robot' in the context menu on the test in the IDE. Choose that option to run your test suite in PyCharm.

The most straightforward way is to create a run configuration, and then using the Run commands.

Here's a sample screenshot - it's invoked in the menu Run->Run Configurations, explanations follows:

1) in the screenshot is the location of the RF run.py file - it is located in the directory Lib\site-packages\robot in your python install - or virtualenv as in the shown case.

2) is the very same python interpreter - make sure it's the same as the one used in 1) (or it may get messy :)

3) are the parameters you'd normally pass on to robot when running it from the command line. The bare minimum is to provide the path to the suite(s) that must be ran - the last parameter in the example screenshot.

PyCharm doesn't have the option to "run this specific test case" by right-clicking on it - because RF depends this information (which case exactly) to be provided on the CLI.

This case selection can be done in a number of ways - just look at the Robotframework's execution selectors (by tags, by case names, etc). All of these options are set in the "Script parameters:" box in the run config; for example, to run tests having a tag Sanity, use --include sanity, to run a specific test case - --name "My test case", and so on.


By the way, one of the greatest benefits of using run configuraitons is that you can debug the execution - i.e. using an IDE for what it's best suited :)

A run configuration does not depend on any plugin being installed - though IntelliBot is an "absolute must" for developing the cases IMO, as seen from the steps it has no relation to the execution/running.

How to run tests through test configuration 1) Add a new Python configuration in ‘Run/Debug Configurations’ dialogue (Run -> Edit Configurations…) with next settings Set ‘Script’ to point to the run.py file in RobotFramework folder. Set ‘Script parameter’s to the list of parameters you want to execute your tests with. (these are the parameters you pass to pybot command). Set ‘Working directory’ to the test project working directory

Save it and it will create a new configuration for you.

2) Run configuration that you will be able to run by pressing run button. And see the test output in tests output window.

How to run tests with one click (from the context menu) What you could do is to setup the external tool in Pycharm/IntellijIDEA to do it. 1) Open File -> Settings (Alt+F7) and search for 'External Tools', click Add to add new configuration and set fields not next values external tool

Duplicated values here:

C:\Python27\Scripts\pybot.bat
<your variables> --test "$SelectedText$" TestSuite
$ProjectFileDir$

Save the changes

2) Run tests by highlighting test case name and running external tool: right click -> External tool -> Individual test

BTW, you can also debug your tests (python code) from test configs. Hope it helps.

I have a detailed blog post on how to run tests with Pycharm/IntellijIDEA, feel free to give to it a check.

For Robot Framework integration in PyCharm, make sure you're using the IntelliBot @SeleniumLibary Patched plugin

go to File--Settings--plugins--(Search for IntelliBot)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!