Does Python have anything Like Capybara/Cucumber?

Solution 1:

You can test Python code using Cucumber - see the Cucumber wiki on github for more information.

If you want a pure Python solution, check out Lettuce. I've never used it, but there is a fairly useful looking blog entry about it and splinter here.

Solution 2:

A. Cucumber like: ( English like)

  • Lettuce (Approach Gherkin) or
  • Behave (Approach Gherkin) or
  • Robotframework (Approach keyword based) (Additional Info: RF is larger than English Like criteria. Its keyword-based and offers loads of helper method and inbuilt libraries. Great eco-sysstem for external libraries. Any python script can also be modified and used along with RF)
  • Freshen (Approach Gherkin) or
  • Pea (Approach Gherkin) or
  • RedwoodHQ (Approach keyword based) (RedwoodHQ has features larger than 'English-Like' criteria and encapsulates the following features: Keyword based, web-based test-framework, supports python as one of languages and much more. Additional info on RedwoodHQ: Theoretically its possible, all the existing robot-framework inbuilt libraries and all robot-framework external test-libraries or for that matter any python library, can be called or used from this web based test framework with little modification)

  • Gauge (Gherkin approach): Reference for python: (https://gauge-python.readthedocs.io/en/latest/index.html)


Underneath Cucumber, one could have Capybara like abstraction layer that hides/ groups many of selenium actions


B. Capybara like: ( Abstraction: hides / groups action)

As one e.g to click an element, its sufficient to provide command like click(locator) instead of working with raw selenium api, where one needs to find an element and then click. Many more such abstraction exist in the optional libraries below

  • Option-1 (see below)
  • Option-2 (see below)
  • Option-3 (see below)
  • Option-4 (see below)
  • Option-5 (see below)
  • Option-6 : Helium (from others Answer/comment)
  • Option-7 : (see below)
  • Option-8 : (see below)
  • Option-9: (see below)
  • Option-10: (see below)
  • Option-11: (see below)
  • Option-12: (see below)
  • Option-13: (see below)

My research: There exist almost half a dozen a. active, b. mature c.developed options.

python comes with variety of batteries included !!


Option-1: Selenium2Library

Github url: https://github.com/rtomac/robotframework-selenium2library

Developement: Active

Purpose: one of the many libraries of robotframework, can also be used as "standalone" library for your framework (Check e.g below for usage).

Thoughts:

  • It provides an abstraction over selenium
  • input of arguments to methods in this library are lot simpler. Abstraction provided by library, one e.g, hides many of the unnecessary details for finding elements. For more details one needs to understand the library
  • It is possible to use this library outside robot-framework context as such without any modification, though it could be using utilities of robot package. (Its your homework to do further experiments with this lib, on this note!)
  • Therefore, can be used as a standalone library for your framework.

Usage:

pip install robotframework-selenium2library

import in your ipython or idle console and start playing e.g:

>>from Selenium2Library import Selenium2Library
>>start_testing= Selenium2Library()
>>start_testing.create_webdriver("Firefox")
>>start_testing.go_to("http://www.google.com")
>>.
...so on

Option-2: Pageobjects

Github url: https://github.com/ncbi/robotframework-pageobjects

Development: InActive (no show stoppers with latest release)

Purpose: One of the libraries of robotframework. Provides a page object abstraction over Selenium2Library. Can be used as Standalone for your framework (Check e.g below for usage) or can be used along with robotframework.

Thoughts:

  • It provides a "pageobject abstraction" support on top of Selenium2Library
  • It is possible to use this library outside robot-framework context as such without any modification, though it could be using utilities of robot package. (Its your homework to do further experiments on this note!)
  • Therefore, can be used as a standalone library

Usage:

pip install robotframework-pageobjects

e.g: in ipython or idle do:

>>from robotpageobjects import Page
>>start_testing=Page()
>>start_testing.create_webdriver("Firefox")
>>start_testing.go_to("http://google.com")

Option-3: robotframework-pageobjectlibrary

Github Url: https://github.com/boakley/robotframework-pageobjectlibrary

Development: Active

Hopefully Author supports LTS (Long Term Support) : )) , Fingers crossed !!

Usage:

pip install robotframework-pageobjectlibrary

Thoughts:

  • It is NOT possible to use this library outside robot-framework context. A minor change to how the page context is handled would help this library to be used outside robot-framework context (Its your homework to find out how!)

Option-4: Splinter

Github url: https://github.com/cobrateam/splinter

Developement: Active

Usage: splinter.readthedocs.org/en/latest/index.html

pip install splinter

On ipython or idle do:

>>from splinter import Browser    
>>browser = Browser()
>>browser.visit('http://google.com')
>>browser.fill('q', 'splinter - python acceptance testing for web applications')
>>browser.find_by_name('btnG').click()

Option-5: SST library

Github url: https://github.com/Work4Labs/selenium-simple-test

Development: Feature complete / Active

Usage: testutils.org/sst/

pip install -U sst

on ipython or idle do:

>>> from sst.actions import *
>>> start()

    Starting Firefox
>>> go_to('http://google.com')
    Going to... http://google.com
    Waiting for get_element

Option-6: helium Not open source (Commercial)

Option-7: holmium.core

Github url: https://github.com/alisaifee/holmium.core

Option-8: wtframework

Github url: https://github.com/wiredrive/wtframework

Option-9: webium

Github url: https://github.com/wgnet/webium

Option-10: elementium

Github url: https://github.com/actmd/elementium

Option-11: saunter

Github url: https://github.com/Element-34/py.saunter

Usage: saunter

Option-12: webdriverplus

Github url: https://github.com/tomchristie/webdriverplus

Usage: webdriverplus

Comments: repository not maintained but decent reference

Option-12: Simple-Pageobject

Github url: https://github.com/rama-bornfree/simple-pageobject/tree/master/PageObjectLibrary

Comments: Simplest pageobject wrapper built around selenium2library. I am the owner of the repo


Test-setup:

"All" the Test libraries in Option-1-13; can be run using any of the following framework: Lettuce, Behave, Robotframework or for that matter, any unit test framework(e.g PyUnit, Nose)...so on .

Test Framework is in general used to manage test-cases e.g

  • English formats like gherkin, keyword, tabular so on ...
  • reporting a test-run
  • hooking to CI
  • set-up/tear-down of test-cases and test-suites
  • tagging of test-cases
  • other functionalities that one could think on about any test-framework

What matters is how comfortable one gets with libraries in above options.

Option-5: As far as SST is concerned, it has features of a framework itself, e.g it can generate report and do many more things.

So the definition of library and framework in the case of SST is blurred, depending on the extent of features one would like to use from that package


Some Math for Fun:

Total number of ways one could have a good, bad, and ugly Test-setup = (Test framework AND Test library + your custom code sandwiched b/w the framework and library ):

7 * 13 = 91 Ways

Choose the best combination (of Test Framework And Test library) that suits ones need !!

I would personally go for Robot-framework with Selenium2Library or Robot-framework with some pageobject library

ofcourse, I am leaned and positively biased in my post about robot-framework and Selenium2Library

Solution 3:

While the OP was happy with finding a Python Cucumber equivalent, what led me here was the question title: a Python equivalent of Capybara. While Cucumber uses Capybara, Cucumber itself is a whole different "solution" that is only incidentally related to Capybara.

If you're looking for something Capybara-like without having to deal with Cucumber, check out splinter. I don't know what was true when the question was posted, but Splinter is now built on Selenium, and supports other engines as well (Webkit, PhantomJS, zope.browsertest, and others), and supports both visual and headless testing.