Mats Bryntse
21 December 2015

5 Great Siesta Tips n Tricks For Your Testing Toolbelt

Siesta contains a lot of useful features that you may or may not be aware of. Reading the Siesta docs […]

Siesta contains a lot of useful features that you may or may not be aware of. Reading the Siesta docs is a great way to learn and we also try to post about all the improvements here in the blog. If you keep track of our changelog, you might already be know some of the tips in this post but we’re pretty sure you’ll learn something new so let’s get to it!

1. Accessing the test instance in beforeEach/afterEach hooks

This is a new feature introduced in our latest release. Let’s say you have a large group of application tests in a test file where you want to assert something at the end of every test group. With access to the test instance in your test hooks, you can now easily add assertions to verify certain conditions your care about.

var dataStore = new;

t.afterEach(function(t) {
});'Should do this...', function(t) {
});'Should also do this...', function(t) {
});'Should maybe not do this...', function(t) {

2. Screenshot on a failed test

This has been requested a few times before and might become a supported feature in the future. Until then, here’s how easy it is to take a screenshot of a failed test:

var failCounter = 0;

yourHarness.on('testupdate', function(event, test) {
    if (test.getFailCount() > failCounter) {
        failCounter = test.getFailCount();

        test.screenshot(test.url, function() {});

3. Using the custom :textEquals CSS selector

Support for targeting elements via exact string matching was added recently. Before this, Siesta only supported the :contains selector found in the Sizzle engine. Now it’s very easy to target elements that contain an exact string:

StartTest(function (t) {
    document.body.innerHTML = '<a href="somelink.html">foo</a>'

        { click : 'a:textEquals(foo)' }

4. Using t.iit to run a single test group

When debugging a single test group in a large test file, always isolate that test group using the t.iit API method.'Skipped', function (t) {
    // some assertions

t.iit('Only this test group will execute', function (t) {
    // some assertions
});'Skipped too', function (t) {
    // some assertions

5. Extending Siesta to find more bugs

Since Siesta is extensible and observable you can do some pretty cool things to find bugs earlier. You can for example override the console.error and console.warn methods to automatically fail your tests (we do this in our own test suites).

harness.on('teststart', function (ev, test) {
    var console =;

    if (console) {
        console.error = console.warn = function (msg) {

You can also do global post-test sanity checks very easily. Here’s another nice snippet from our own vaults, detecting suspended layout components (in case someone forgot to call resumeLayouts):

harness.on('beforetestfinalizeearly', function () {
    var win =;

    if (win.Ext) {
        var Ext = win.Ext;
        var suspendedComponents = this.cq('[isLayoutSuspended]{isLayoutSuspended()}');

        // only report in case of failure
        if (suspendedComponents.length > 0) {
            this.diag('POST TEST SANITY CHECKS');

  , 0, 'No components found with layouts suspended');

  'Suspended layouts detected for components', {
                annotation :, function (cmp) {
                    return ( + '(' + cmp.xtype + ') ');

        if (win.Ext.AbstractComponent.layoutSuspendCount > 0) {
  , 0, 'Layouts should not be suspended globally by accident');

Share your tips

What are your favorite testing tricks which find bugs or make you more productive? Please share them with us and the Siesta community. Happy testing! 🙂

Mats Bryntse

Testing Tips 'n tricks