8
votes

I started using PyCharm with the robot framework, but I'm facing an issue. How can I run my tests? All the time I right click on my tests folder, I get an Empty test suit message from the console log.

Is there any way to run each test separately like right click on the test case and hit the test runner?

This is my code:

*** Settings ***
Library     Selenium2Library
Resource    /steps/keywords.txt

*** Variables ***
${URL}         http://www.google.com

*** Keywords ***
Open browser with URL
    [arguments]     ${url}
    Open Browser    ${url}  browser=gc

Set input on text box
    [arguments]     ${xpath}    ${text}
    Input text      ${xpath}    ${text}

Push button
    [arguments]     ${button}
    Click Button    ${button}

*** Test Cases ***
Google Access
    Open browser with URL   ${URL}
    Set input on text box   //*[@id="gbqfq"]    Critical Software
    Push button             //*[@id="gbqfba"]

    #Close Browser    
4

4 Answers

7
votes

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.

5
votes

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:

Sample RF run config in PyCharm

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.

0
votes

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.

0
votes

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

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