2011-07-13

Coronis Test

Last week we also published (republished actually, more on that later) our Coronis Test.

This is an web application test framework similar to Selenium core. In it you can write your web application test following some simple commands and checks. If any of them failed, then your web application is not behaving and the test fail.

Why not selenium?

As you may know Selenium Core is a test framework that do all that. It can do some commands/actions and check some states. If it fail the test fail and goes on to the next.

But it has several problems. First you must feed the data in HTML tables, which makes it... not comfortable. Also when you are using AJAX applications then you know some element will appear later, and you want to click it, always. There is no point in wait for it and then click it as you always do it. If it doe snot appear in some time (the default timeout), then the test should fail, but it should wait for it a little bit. Also is quite slow.

It uses its own selector mechanism, based on Xpath, but its difficult to use.

Finally the extension mechanism requires some internal knowledge of selenium, which makes it difficult to do for easy tasks.

On the nice side is that its been widely used, that you are not forced to use the Core itself, but you can use the number of other language frontends available, and many more.

Anyway, we did not like as it had the bad habbit of failing for no real reason, most of the times because the test had to be very well written, waiting for almost everything to happend, even on normal page loads.

jQuery as the base

When we thought about all these problems we thought that it should not be difficult to build a new Test Framework using jQuery as base. It has all the nice selectors, it has events for almost everything, including page loads, and its quite easy to develop an interactive application just with it. So we gave it a try.

The process

First we had to make it be able to search on the iframe of the real application, so we made our own $$$. It just searches for an element, and 'jQuerifies' it. We had also some problems about simple clicking, and about some other parts, but things were working.

To wait for the elements to appear, all commands may raise an exception "not yet", and Coronis Test will try some times (a hundred by default) every some milliseconds (25ms by default).

We had to make our own parser, for this simple CTest language, and as we had it, we added some nice goodies. On the parser was quite easy to see from the very begining the option to include other tests.

First, variables. On Selenium they exist too, but here you can use them almost everywhere. Its different a variable than a constant string, and you can use them everywhere. Its a bit difficult by the moment to assign new variables as it has to be done with the "concat" command, that concats expressions, but its ok.

As we had variables we thought: 'mhmm... some times I do some things a lot, like login... why not make some kind of macros'. So we did functions. They accept parameters, and are perfectly integrated with the rest of the language. So its almost the same to click('#submit') and to login('admin','password'). Why not?

Finally on some tests we were missing the javascript power to do whatever you want, like changing elements to fake some situations. User can expand the commands.js to add its own commands, but that makes it cumbersome... Why not on the same test? So we added the support for javascript straight into the test files. You can use it whereever you want, in normal flow, or in a function. So actually you can expand the Coronis Test framework pretty easily. Actually you can event change the complete set of default commands with no single line change on the core.

On the GUI side things like breakpoints are nice, as following the execution, and to start the execution from a given point, so they are in. Also there is a log and some more things.

How to use it

I will show here a simple test with all the options. First the code, available here. Check the suite.ctest (edited here):


log("Start the test")
checkElement('#h')type('#h','Hello world')
# We add a button, that sets the #h to -- when clicked
javascript{ 
$$('body').append('<input type="submit">').click(function(){ 
$$('#h').val('--') 
})
}
click('[type=submit]')checkAttr('#h','value','--')
myset = function(text){ 
type('#h',text)
}
myset('Hello world again')errorOnNext()
checkText('world')
javascript{ 
$$('body').append('That was not text, was an attribute!');
}
checkText('attribute')checkAttr('*','value','.*world.*')


As you can see the CTest language is quite straightforward; simple imperative with some extras like the function, and javascript embedded.



Here we can see how to use javascript; it is executed in the ctest context, so to access the elements it must be done with the extra $$$, and then the easiest is to just use jQuery. Of course anything you do on the elements stay, like connecting a signal here.

This example is not very illustrative on how to do testing, as it modifies the testing environment, which should be avoided, but just shows many of the possibilities of Coronis Test.

Feedback

If you wan to contact us about Coronis Test, please do it.

You can of course also fork and use the code as you which on your projects.

The license is AGPL, but that should not be a problem as normally you dont redistribute anything and you are the normal user. We think that this license encourages to share the evolution of the framework, but you are not forced in many cases.

No comments:

Post a Comment