Archive for category How-to

Reusing browser instance in Geb UI tests

Tags: , , ,

UPDATE

When I originally wrote this post, I was Geb newbie. Despite the fact that approach presented below is valid and works, there is a much simpler solution to this problem incorporated by Geb itself and I strongly suggest using it instead of mine, home-crafted hack. All credits go to Artur Gajowy for showing me better approach.

I have added short paragraph about this simpler solution at the end of this article, probably you should go directly there :) .

 

Geb is next-generation UI testing library that frees developer from dealing with Selenium API which is in many cases not so friendly. The most important feature of Geb is its support, or I would even say, strong encouragement to use Page Objects in your UI tests. Page Objects are also present in Selenium, but they are not as intuitive and east to use as in Geb.
But enough about Geb itself. Today I will share with you simple trick how to share one browser instance when running many Geb UI tests. This will significantly reduce time needed to execute UI tests and also reduce memory usage on test machines.
Continue reading this post …


Be Sociable, Share!

Easy Html/Javascript JSON escaping in Scalatra

Tags: , ,

logo-scalatra
Scalatra is a small web-framework that allows to easily build Rest API for web applications. We are using it in two projects to serve JSON data consumed by AngularJS based front-ends. And in one of this project we had a problem with text messages that could contain Html/Javascript elements. User could save message and then this message could be used on two pages. On first we need to display escaped data (read-only view) and on second (edit page) we wanted to display message in the exactly same way as user typed it.
So basically we needed easy and declarative way to define which Scalatra Rest end-points should return escaped and not-escaped JSON data.

Basic Scalatra project

To show how it could be accomplished, we need a simple sample project using Scalatra. I didn’t want to create it from scratch by myself so I removed some Swagger related stuff from project by my colleague Krzysztof Ciesielski (his post about Scalatra and Swagger) and I was ready to go :) Full commit with this basic project is available here, but the most interesting class is shown below:
Continue reading this post …


Be Sociable, Share!

XStream – XStreamely easy way to work with XML data in Java

Tags: , , ,

From time to time there is a moment when we have to deal with XML data. And most of the time it is not the happiest day in our life. There is even a term “XML hell” describing situation when programmer has to deal with many XML configuration files that are hard to comprehend. But, like it or not, sometimes we have no choice, mostly because specification from client says something like “use configuration written in XML file” or something similar. And in such cases, XStream comes with its very cool features that make dealing with XML really less painful.

xstream

Overview

XStream is a small library to serialize data between Java objects and XML. It’s lightweight, small, has nice API and what is most important, it works with and without custom annotations that we might be not allowed to add when we are not the owner of Java classes.
Continue reading this post …


Be Sociable, Share!

Jasmine tests reporter in TeamCity with Scala and SBT

Tags: , , ,

This post is basically re-post of article I have written on my company blog here. But before you go there to read the full story, please check this short introduction below to decide if you are interested :)

In our company sandbox project called Bootzoooka we are using pretty cool technology stack: Scala, Scalatra, SBT and AngularJS. Of course we have some JavaScript tests that are executed using sbt jasmine plugin from Guardian. Current 0.8 version of this plugin allows to execute these tests in TeamCity and even fails build when any JS test is not passing, but it didn’t provide full test report for these tests. This plugin worked quite well for us, but we wanted something more and that’s why added story saying “As a Developer I want to see jasmine tests in TeamCity report” to our Bootzooka backlog.

To sum up, we have added support to TeamCity Reporting Tests feature allowing CI to react on specific log messages produced during different test execution phases and after that we released our forked version 0.8.1 of sbt jasmine plugin and also made a pull request to Guardian project.

The whole process of plugin modification is described in this blog post mentioned above.


Be Sociable, Share!

Twitter Bootstrap Navbar as AngularJS component

Tags: ,

You all know Twitter Bootstrap, don’t you? It’s the awesome library to make your web application looks pretty good without spending many hours on CSS. We are using Bootstrap based design in our current project that also uses AngularJS and as we are planning to have many new pages, we decided that’s the earlier we introduce some components to our UI the better. And, what shouldn’t be a surprise, navigation bar natually became the first candidate.

Overview

So in this post I am going to show how externalize Twitter Bootstrap Navbar into a separate, flexible AngularJS component. All source code is available in my GitHub repository , so everything should be easy to follow and repeat.

Basic setup

To start from the basics, I’ve prepared three pages that use the same navigation bar. These pages will soon become our super simple web application using AngularJS:

navbar_angularjs1

Next step will be adding AngularJS and converting three pages into one small application. This is done in this commit. And after that we are ready to start working on our Navbar component. Continue reading this post …


Be Sociable, Share!

Running unit tests and integration tests separately with Maven Failsafe and TestNG

Tags: , , ,

Recently for my new pet project I decided that I would like to have some tests executed during standard mvn test and some other ones only during different phase, let’s call it integration phase. I googled and googled and nothing seemed to work, so after struggling with making my setup work I’ve decided to write down my findings how I was able to configure TestNG with Maven to run integration and unit tests separately.

Basic (not working) setup

For integration testing there is a Maven Failsafe plugin that is supposed to do what we want out of the box. Unfortunately, things are not as easy and straightforward as we might expect.
Continue reading this post …


Be Sociable, Share!