Suppress phantomjs console log in watir webdriver

Reading Time: 1 minute
image credit: phantomjs.org

TLDR

In this short post I will describe how different environment could produce different result for the same tool.

Phantomjs is full web stack that enables tester to run headless browser automation. I am using phantomjs on MacOS and linux, but never on Windows.

When I started browser automation using phantomjs on Windows 7, I noticed a lot of log activity in Windows Powershell console window. That log was not present on MacOS or Linux platform. Log presented phantomjs web activities, like dom manipulation and javascript execution. I could not see more important information, and that was test result!

By using google, I found this switch, here is gist for that:

What is important is that this switch is not supported by firefox web-driver. So be careful how you will use that switch in your script.

Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Validation of record uniqueness in Ruby on Rails application

Reading Time: 2 minutes
credit: http://mahoot.com/

TLDR

In one of my previous posts, I wrote about important software design antipattern. In this post I will explain how to avoid it in Ruby on Rails application.

Important feature of any web application is to have in database unique objects. Uniqueness is usually defined using object properties. Simple example is user that is uniquely identified by email address.

So, in your code, you need to implement uniqueness check. What Ruby on Rails offers in that field? Here is official documentation on active record uniqueness feature:

“””
This helper validates that the attribute’s value is unique right before the object gets saved. It does not create a uniqueness constraint in the database, so it may happen that two different database connections create two records with the same value for a column that you intend to be unique. To avoid that, you must create a unique index on both columns in your database.
“””

Wait, what is this rambling about two database connections? Reality check for a tester. As a tester, you do not need to know how to write uniqueness check in Ruby on Rails application. But you should understand the concept of database connection and parallel client access to database. Databases (like Postgres or MS SQL) have uniqueness check mechanism, and those are unique database indexes. If you do not understand that concept, your responsibility is to learn about it. In this days using the Internet, this is not the problem. Do not hesitate to ask for help from developers. This is important concept, and sometimes it is easier to get the explanation from real person.

Here is Rails example how to write migration class, that will add unique index to my providers active record:

Note that index consists of two attributes, name and url.

And here is uniqueness check in controller class:

Here we check if postgres PG::UniqueViolation exception was thrown. Exception is thrown if unique index is violated on DATABASE LEVEL. That means that uniqueness is check in one central point, and that is your database engine.

Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Wrong design issue

Reading Time: 2 minutes
credit: http://blog.nemetschek-scia.com/

TLDR

In this post I am talking about important tester activity. That activity can be done where there is no single line of code, by just giving critical opinion on product requirements. On concrete example, I will do RIMGEA analysis to better sell described issue.

In order to get client data from current product, I used api of that product. api was sql query based which means that returned rows of data had a number of columns (attributes). Api was well documented.

While I was learning that api, I noticed something strange in documentation, one of returned columns (attribute) was named something like this:

Amount_x

By using query, I hit that design issue. For different ranges in api request, response had a DYNAMIC NUMBER of columns, that contained result data. So if response had two amounts, it contained COLUMNS Amount_1, Amount_2.

Why is this an issue? Because this is in direct conflict with relational database design:

“””
Each database is a collection of tables; these are also called relations, hence the name “relational database”. Each table is a physical representation of an entity or object that is in a tabular format consisting of columns and rows. Columns are the fields of a record or the attributes of an entity. The rows contain the values or data instances; these are also called records or tuples [wikipedia].
“””

From RIMGEA, we will describe Maximize and Externalize. When api call returns only two values, this is not the issue. But when api call request generates 1000 values, you will hit database security constraint, number of columns is exceeded for particular entity.
In order to Externalize it, we need to inform stakeholders that api will not be able to support number of values that are greater than database security setting. We also need to explain that user will often generate api calls that will return that number of values.

Tester of that product could spot that issue by reading the api documentation. And if documentation was not specific how values should be returned, this could be spotted in early stage of api method lifecycle.

Takeaway

If you are tester and spot some design issue, do not be afraid to speak up. Especially when you have RIMGEA as you backup.

Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Where to put rspec expectation in Cucumber project?

Reading Time: 1 minute
credit: cukes.info

TLDR

In this post I will explain how to use rspec expectations in cucumber project that uses page object gem.

In order to be able to use rspec expectations in cucumber project, you first have to include rspec gem in your Gemfile. After that, you have to put in

features/support/env.rb

following line

require ‘rspec/expectations’

You are good to go.

But where I should use rspec matchers, in page class or in step definitions? If you use rspec matcher in page class definition, you will get following exception:

You have to move rspec matchers in step definitions, something like this:

credit: rspec.info

When you think about it, this is logical decision. Page object class should represent page that you interact with with methods that interact with page elements. It should not contain checks of those elements. Step definition contain Then word, so their purpose is to check page elements. For me, that was not obvious so I hope that this post would save you some time.

Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather