Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Get started with python behave

Get started with python behave

We will talk about how to get started with Python Behave , but first please allow me to make just a short introduction about my “feelings” when it comes about python.

I really like python because of its values and general development rules , if you ask me my favourites , as a value : “Simplicity is alway better than functionality.” – Pieter Hintjens and as a general development guideline “Explicit is better than implicit” – PEP 20.

Requirements :

You need to have a version of python installed on your system , if you are on mac or linux you should have a default version , if you are on windows you need to install a new one.

You can download python from the official page.

Install pip
sudo easy_install pip
Install behave
sudo pip install behave

If you have any issues of installing behave you can install a specific version of pip for your python version.

You do this in the following way:

curl -O https://bootstrap.pypa.io/get-pip.py
$ sudo python3.6 get-pip.py

You then install things for Python 3.2 with pip-3.6, and you install things with Python 2-7 with pip-2.7. The pip command will en up pointing to one of these, but I’m not sure which, so you will have to check.

As an alternative, you can also use easy_install to install behave:

easy_install behave         # CASE: New installation.
easy_install -U behave      # CASE: Upgrade behave.

Now make a directory called “testingrepository”. In that directory create a file called “testing.feature” containing:

Feature: Open google with behave

  Scenario: run a simple test
     Given I m on google page
      when I search for something
      then behave do that for me

Make a new directory called “testingrepository/steps”. In that directory create a file called “testing.py” containing:

from behave import *

@given(u'I m on google page')
def step_impl(context):
    assert True is not False

@when(u'I search for something')
def step_impl(context):
    assert context.failed is False

@then(u'behave do that for me')
def step_impl(context):
    assert context.failed is False
Run behave:
% behave
Feature: Open google with behave # testing.feature:2

Scenario: run a simple test # testing.feature:4
 Given I m on google page # steps/testing.py:3 0.000s
 When I search for something # steps/testing.py:7 0.000s
 Then behave do that for me # steps/testing.py:11 0.000s

1 feature passed, 0 failed, 0 skipped
1 scenario passed, 0 failed, 0 skipped
3 steps passed, 0 failed, 0 skipped, 0 undefined
Took 0m0.000s

For more informations you can consult the API documetation .

For any other programing languages you can have a look at How to get started with cucumber watir in ruby or how to create a page object model framework in c# .

Happy Testing!

The post Get started with python behave appeared first on TestingRepository.



This post first appeared on Testing Repository - Creating Testing, please read the originial post: here

Share the post

Get started with python behave

×

Subscribe to Testing Repository - Creating Testing

Get updates delivered right to your inbox!

Thank you for your subscription

×