Skip to main content

Zombie.js is a fast headless browser with all the JavaScript support Node.js provides. This package provides a function decorator, which allows Python doctest-style functional JavaScript testing using Python-like CoffeeScript.

Disclaimer: This is mostly an experiment. This wouldn’t ever replace your existing Selenium-stack, because Zombie.js, even when it works, is just an another browser with its own quirks.

Requirements

  • a UNIX like environment

  • Node.js must be installed

  • npm must be installed

  • coffee-script, zombie and async packages must be installed using npm

  • coffee-executable must be found on the path

The requirements should be filled, when you can run the following command on a console without it printing anything (returning any errors):

$ echo "require 'zombie'; require 'async'"|coffee -s

Example of use (with plone.app.testing)

Start with defining a functional testing fixture with ZServer (that will run your Plone on localhost:55001 by default):

from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import FunctionalTesting

from plone.testing import z2

FUNCTIONAL_TESTING = FunctionalTesting(
    bases=(PLONE_FIXTURE, z2.ZSERVER_FIXTURE), name="PloneFixture:ZServer")

Then write your functional JavaScript test as a doctest for your testmethod using CoffeeScript instead of Python. Define the context (URL) of your test by using the decorator (@browser) from collective.zombiedoctesting as shown below. You may use all the JavaScript that’s provided by your context and the global browser that represents Zombie.js’ browser:

import unittest

from plone.app.testing import TEST_USER_NAME
from plone.app.testing import TEST_USER_PASSWORD

from collective.zombiedoctesting import browser

constants = {
    "TEST_USER_NAME": TEST_USER_NAME,
    "TEST_USER_PASSWORD": TEST_USER_PASSWORD
    }


class LoginOverlayTest(unittest.TestCase):

    layer = FUNCTIONAL_TESTING

    @browser("http://localhost:55001/plone/", mapping=constants)
    def test_login(self):
        """
        Let's start by looking up the login link using the jQuery available
        on our site:

        >>> console.log $("#personaltools-login").text()
        Log in

        Clicking that link should not redirect us anywhere, but give us an
        AJAX overlay with a login form.

        >>> $("#personaltools-login").click()
        >>> console.log window.location.href
        ... console.log $(".pb-ajax #login-form").text()
        http://localhost:55001/plone/
        Login Name
        Password

        Let's store that form as global (to be available between different
        doctest examples) and fill it...

        >>> global.form = $(".pb-ajax #login-form")
        ... form.find("#__ac_name").val("%(TEST_USER_NAME)s")
        ... form.find("#__ac_password").val("%(TEST_USER_PASSWORD)s")
        ... console.log form.find("#__ac_name").val()
        ... console.log form.find("#__ac_password").val()
        %(TEST_USER_NAME)s
        %(TEST_USER_PASSWORD)s

        ... and click the button to log in.

        >>> form.find("input[type='submit']").click()
        >>> console.log window.location.href
        ... console.log browser.text(".documentFirstHeading")
        http://localhost:55001/plone/login_form
        You are now logged in

        Uh oh, we were properly logged in, but we were redirected also, so
        zombie is not a perfect browser yet.

        Also, notice, that we couldn't use jQuery in testing the document
        first heading (we used zombie's custom browser API), because the
        context after the click is an AJAX-response without jQuery or any
        other javascript.
        """

Note that every parsed doctest-example (a line starting with >>>) is executed separately, but you may use Node.js’ global to make variables available between doctest-examples.

If you’d like to see the complete JavaScript generated to be run with zombie, you may add debug=True into @browser-decorator call.

Changelog

1.1.0 – 2011-10-30

  • First (hopefully) non-broken release.

Release files for collective.zombiedoctesting 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for collective.zombiedoctesting 1.1.0
File Size Uploaded
collective.zombiedoctesting-1.1.0.zip 17.0 kB Details

Release files / collective.zombiedoctesting-1.1.0.zip

Download URL collective.zombiedoctesting-1.1.0.zip
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
36b19aa70754ab6538484382d77a1f7bfd66d2e38fae83c266c80b8eea564fde
BLAKE2b-256 checksum
How to use checksums
b1828d0d397c7ae62ca02b7daf48a36db9bed350803d889a5f69206f154aaa0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.1.0 This release

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page