Photo from Chile

Debugging Gaia Tests with PyCharm

I've written about PyCharm before. I is my IDE of preference for Python, and I must admit it does an admirable job for html and Javascript as well. I really like its interactive debugging features, which I use all the time when writing and, more often, fixing, Web QA tests. As I have now started working on Gaia (the UI for Firefox OS) tests as well I wanted to try to use Pycharm to interactively debug them as well. I asked my colleague Dave Hunt to help me figure out how to do so during our work week in San Francisco and together we were able to come up with the following solution:

This post assumes you have the gaia-ui-tests project open in PyCharm.

Step 1 - Create a Run/Debug Configuration for gaia-ui-tests

  1. Type ctrl + alt + R to open the Run configuration selector.
  2. Type 0, or choose the first option (Edit configurations...) from the select list.
  3. Click the + sign to add a new configuration and choose Python from the dropdown.
  4. In the Run dialog, enter the following values:
    • Name: gaia-ui-tests
    • Script: path/to/gaia-ui-tests/gaiatest/runtests.py
    • Script parameters: --address=localhost:2828 --testvars=path/to/b2g.gaia.json gaiatest/tests/test_to_run.py
    • Python interpreter: The interpreter to use for this project. This will likely point to a virtualenv.
    • Working directory: path/to/gaia-ui-tests
    • Make sure the Show settings checkbox is checked. This will allow you to change the name of the test whenever you run one.
  5. Click Apply, then Close.

Step 2 - Debug a test

You should notice a dropdown around the middle of the toolbar that has the PyCharm logo on the left and says gaia-ui-tests. To the right of this is a green right-pointing arrow and to the right of that is a bug symbol with a blue pointing arrow.

You can now run a test by clicking the green arrow or debug a test by clicking the bug symbol. Because you checked the Show settings checkbox on the configuration, the dialog will pop up allowing you to edit the configuration before launching the run or debug session. When that happens, the only thing you need to change is the name of the test file that you wish to run, which is the last thing that you added to the Script parameters: field. Change that and click Debug (or Run as the case may be), and you'll be off to the races.

Step 3 (Optional) - Have adb forward run automatically before any test

When testing with a real device, you need to make sure that Marionette can communicate with the device via port 2828, so you need to have forwarded that port at least once after connecting or rebooting a device before you can run a test. We came up with a little trick to have PyCharm do that for you. To do that, complete the following steps:

  1. Type ctrl + alt + R to open the Run configuration selector.
  2. Type 0, or choose the first option (Edit configurations...) from the select list.
  3. Choose the gaia-ui-tests configuration (which is likely already chosen), which should take you to the now familiar Run configuration dialog.
  4. Underneath the empty box that says There are no tasks to run before launch click the + sign and choose Run External tool.
  5. You should see an empty External tools dialog. Click the + sign to add a new tool.
  6. In the Edit Tool dialog, enter the following values:
    • Name: adb forward
    • Group: adb
    • Description: Android Debug Bridge forward
    • Program: path/to/androidsdk/sdk/platform-tools/adb
    • Parameters: forward tcp:2828 tcp:2828
  7. Click OK, then OK, then Apply, then Close.

That should be all you need to run and debug gaia-ui-tests from within PyCharm. If you run into any problems with this please feel free to leave me a comment below.

TweetBacks
Comments
ctrl + alt + R, i also was test debug, thanks you
# Posted By dong phuc lop | 6/21/13 12:56 AM