Skip to content

Instantly share code, notes, and snippets.

@kurko
Created December 4, 2012 22:35
Show Gist options
  • Save kurko/4209648 to your computer and use it in GitHub Desktop.
Save kurko/4209648 to your computer and use it in GitHub Desktop.
Javascript Acceptance tests framework

Javascript Acceptance test framework

This is a draft for an Acceptance testing framework in Javascript. See the example code.

Benefits

  • Server agnostic.
  • Tests in parallel.
  • The developer can stop a running test whenever he wants.
  • The framework can keep failed tests in iFrame instances, allowing the developer to debug them in the browser easily.
  • Given tests aren't run by default upon page load, the developer can start the current page's tests with a keyboard shortcut (e.g Ctrl+T).

Workflow

  1. The framework is added in the page header.
  2. The framework runs the acceptance tests (see example file).

Each function (such as visit(), fill_in()) triggers the correct events and automagically asserts results.

Testing multiple page requests

Upon page load, body is replaced with an iFrame which loads the same page URL. The tests will run inside this iFrame, allowing the page to load different URLs without stopping the testing framework.

e.g if we open www.example.com, the framework creates an iFrame (width and height 100%) that loads www.example.com. The test framework can trigger events inside the iFrame normally.

feature("User sign in", function() {
scenario("As an admin, I want to sign in", function() {
visit("/admin");
page.should.have_content("Enter your credentials below");
fill_in("email").with("admin@example.com");
fill_in("password").with("123456");
click_button("Sign in");
page.should.have_content("Welcome, Alexandre!");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment