Dec 5, 2015

Released version 2.2. Object groups and code blocks in custom rules

I am very excited to announce that the version 2.2 was just released with lots of new features and improvements in Galen Specs language. The complete list of changes is here. The major features added to version 2.2 are:

Object Groups

From now on you can declare groups of objects that allows you to have more readable specs in your tests. Also with spec groups you can perform different types of testing only for a selected group. Imagine that you want to use image spec but only for a specific set of objects. Here is what you can do:

# You can declare all objects on your page @objects header #header icon img caption h1 menu #menu item-* ul li # Now you can group objects like this @groups image_validation header.*,menu.item-*

In the example above we grouped only header.icon, header.caption and all menu.item-* objects under image_validation group. We didn’t group header and menu objects. So now if we want to run image comparison tests we can do it like this:

= Image validation = @forEach [&image_validation] as item: ${item}: image file imgs/${item}.png

In the example above galen will generate image validations for header.icon,header.caption,menu.item-*. As you can see, object groups feature allows you to build a more flexible and expressive page spec. But when combined together with custom rules, you can bring your tests to a new level and achieve estonishing results like in this example

Code blocks in custom rules

In previous versions we have built a custom rules feature that allows you to generate specs based on your custom expressions. In the version 2.2 we have added the support of rules body which could be used as a callback from the rule. This allows you to define your own loops or conditions in a more readable way. Here is an example:

@rule if %{objectName} is visible @if ${isVisible(objectName)} @ruleBody = Main section = # now you can use this rule like this | if banner is visible banner: width 400px height 200px above main_section 20px

Or for example you can create your own loop

@rule every %{objectPattern} is %{spec} @forEach [${objectPattern}] as item: ${item}: ${spec} = Main section = | every menu.item-* is below header 0px

Mask filter and alpha channel in image spec

Sometimes, when using image comparison, you might need to ignore some specific area on the image. This is now possible with version 2.2 because of added alpha channel support. From now on if the pixel has alpha value close to 0 – it will be ingored in image validation. But that is not all of it. If you don’t want to edit all your image samples but you want to change the alpha value for specific region, you can make use of mask filter. The mask filter takes another image and in areas where mask image has white pixel it will not change the alpha value. But on the areas where it has black pixels, it will change the alpha value to zero, so that it is completely ignored in image validation.

= Image validation = header.icon: image file header.icon.png, filter mask header.icon-mask.png

Arguments for component spec

Very useful feature when you want to make your components generic. A very common situation is when you want to move all validation for an object into a separate component (e.g. header), but that object contains elements that vary depending on whether the user is logged in or not. That is just one of the many examples. Lets imagine that you want your component to take two arguments: isUserLogged and loggedUserName. Here is an example of header-component.gspec:

@objects caption #header-caption = Header = caption: @if ${isUserLogged} text is "Welcome, ${loggedUserName}!" @else text is "Welcome!"

Now you can call this component from your main spec file like this:

@objects header #header = Main section = header: component header-component.gspec, isUserLogged true, loggedUserName "Johny"

Download

These are not all features that were implemented in version 2.2. You can find the detailed list of changes here.
To download the new version just follow this link. If you notice anything wrong with it, then let us know on Galen Framework Forum

Kind regards,
Ivan

Comments

We have moved all the discussions to Google Groups. From this moment, if you have problems with your test code or some issues with installation, please ask your questions in https://groups.google.com/forum/#!forum/galen-framework.