Tuesday, April 8, 2014

Introducing Golem, an Object Oriented C# Framework

Hello everyone, I am pleased to announce the release of Golem, an open source, object oriented C# framework, now available on GitHub.   Golem was an internal tool that ProtoTest has successfully used on a number of our clients' projects, and we like it so much we want to share it with everyone.  It supports a number of automation tools like Selenium-WebDriver, Appium, Microsoft's UIAutomation, and can even test REST services and validate HTTP Traffic.  Tests are written in Visual Studio, using MbUnit, and are executed using Gallio. It's an all-in-one automation tool for anyone working in a .Net environment.  Golem makes building clean, robust, reusable, and scale-able automation easy.  It's available in NuGet now!

Golem has a number of advantages :   
  1. Simple, Object-Oriented API
  2. Advanced features (data driven testing, parallel test execution)
  3. Robust Reporting and Logging 
  4. Multiple Automation Tools Supported
  5. Fully configurable through an App.Config or through code.  
You can find our official announcement below : (Copied from ProtoTest's Blog)


Prepare yourselves; Golem is coming. A creature from myth and legend returns, reborn for the new age. In ancient folklore, a Golem is a mindless automaton, an unstoppable force, yet it obeys those bold enough to command it. And therein lies the danger, for it will perform any command given to it, faithfully and without rest. For it has no mind of its own, it requires an intelligent being to control it. But beware, the ancient proverb ‘He who rides a tiger is afraid to dismount’ has never been truer: holding power is both addicting and hard to relinquish. Once the power of Golem is yours to command, you cannot go back.
 

Introducing Golem

At ProtoTest, we are passionate about the value of test automation. In fact, our motto is: “Automation makes humans more efficient, not less essential.” We think it is a great way to supplement any manual testing effort. Yet we see a number of people (and companies) struggling to implement test automation in a meaningful way.
There is a qualitative leap between recording and playing back a test and building an enterprise-scale automation suite maintained by dozens of people. This is where a test automation framework steps in. It helps to simplify the process of building, maintaining, and executing a large set of automated tests.
Most automation frameworks have three goals: to simplify the process of building tests, to help diagnose why tests fail, and to allow us to share and reuse code. And while there are a number of automation frameworks on the market, we could not find one that provided the level of simplicity, reusability, and elegance we wanted.
So, we decided to make our own. For the past several years, we have been building and tweaking our own framework in C#. We built the framework around MbUnit and Gallio, because they have advanced features for UI based automation. We included support for a number of tools like Selenium-WebDriver, Microsoft’s UIAutomation, and Appium.
Golem supports most commonly tested enterprise platforms: web browsers, mobile applications, Windows applications, HTTP traffic, and REST services. Tests are written using the industry standard, ‘page object,’ design pattern, and the test report includes as much diagnostic information as we could gather.
In addition, we added several advanced features like data driven testing and parallel test execution. Then we made all of it easily configurable. And now, we want to share it with the world. We are officially announcing the release of the Golem open source project, developed by ProtoTest.
The user group : https://groups.google.com/forum/#!forum/prototest-golem
The source code is available on GitHub: https://github.com/ProtoTest/ProtoTest.Golem
The package is available from nuget: https://www.nuget.org/packages/ProtoTest.Golem/
The documentation is available here : https://github.com/ProtoTest/ProtoTest.Golem/wiki

Tuesday, April 1, 2014

3 Cool things you can do with Javascript Injection

Learning how to interact with or modify an application directly is one of the more advanced things to learn as a tester.  But once we have a hook into an application we can do a variety of things: accessing internal variables, calling methods, manipulating the application’s state, or even modifying the code ourselves.  For some types of applications this is extremely hard, for others it’s relatively easy.  One of the easiest types of applications to manipulate directly is a web page.  This is because most of the code is stored locally on the client, none of it is obfuscated, and all of it is modifiable.  This means that there are a variety of fun things we can do through any browser with a console like Firefox or Chrome. 

You can get to the console in Firefox or chrome by right clicking, selecting inspect element, and clicking on the console tab when the new panel opens.  Any commands we enter into the prompt will be fired against the web page.   Just remember that if a new page is loaded, or if the browser refreshes, anything you do is lost.    Alternately, many automated testing tools provide a way to execute code against the page, and this provides an easy mechanism to manipulate the application automatically. 

1) Modify or execute the code

One of the most useful things to do when testing a web site is to access its internal variables and methods.  This allows us to modify the web page even without a UI.  For instance, suppose that after 60 minutes of inactivity the user is supposed to get a prompt asking them to stay logged in.  We certainly don’t want to have to let our computer idle for an hour every time we test this.   Instead, we can set the web page to timeout after 1 minute by changing the time from 60 minutes to 1.  You can typically ask a developer what the variable is called, or use the console to try to find it.     
So let’s assume a developer told us that the variable was named timeoutMin.  Modifying it is easy.  From the console enter:  document.timeoutMin = 60;  Now the web page should use the new value instead of the old one. 

2) Hiding / Showing Elements

Occasionally when working with a web site that is under development, something won’t display correctly.  For example, an extra panel appears covering the web page.  This prevents you from being able to do any work.  Or perhaps the login panel doesn’t appear.  We are prevented from testing any functionality that requires a login until that issue is fixed. 
Hiding or showing elements is easy, provided they have an Id, class, or name.  Using chrome, you can right click on the element, and select inspect element.  If the element’s HTML contains an id attribute you can use it to manipulate the object.  If it doesn’t have an id, you can even add one, or try getElementByClassName, getElementByName, or getElementByTagName.
The command to hide an element :  document.getElementById(“idOfElement”).style.visibility='hidden’;
The command to show an element :  document.getElementById(“idOfElement”).style.visibility=’visible’;

3) Adding / Removing Page Events

A web page works by registering functions to happen when certain events happen.  There are a variety of different types of events that are called whenever the user clicks, types, or moves the mouse.  For example, a button can have a function registered to the click event called “onclick”.  When the user clicks on the button, the function is called.  If we want we can add, delete, or replace these events with our own.  Let’s look at three examples:
1) To illustrate how to replace an event we will try to disable all click events on the page.  To achieve this we replace the document’s onclick function with one that does nothing. 
document.onclick = function() { return false; };
Most click actions on the page are now disabled.
2) If we don’t want to disable them all let’s add an additional event without removing the old one.  We do this by adding a new listener.  We can add an event to either the entire page, or to a specific element.  For example, let’s suppose I wanted to highlight the element that my mouse is over. I’m going to add two listeners, one to highlight an element under my mouse, and one to un-highlight when the mouse leaves. 
document.addEventListener('mouseover', function(e) { e = e || window.event; e.target.style.border='3px solid red}, false);
document.addEventListener('mouseout', function(e) { e = e || window.event; e.target.style.border=''}, false);
3) Lastly, let’s suppose I wanted to add an alert message when I click the login button.  This will “Pause” the web page and allow me to inspect traffic, html, etc. 
document.getElementById(“idOfElement”). addEventListener(onclick, function(e) { e = e || window.event; }, Alert(“Element was clicked”); false);

 As you can see, there are a variety of reasons why we might need to modify a web page.  It’s not the sort of thing that will needed every day, but is a great extra tool to be added to any SQE’s tool belt.