2010. június 4., péntek

Selenium Framework Structure - Java

Hi Guys!

Today i want to talk about a topic that is not often talked about. This is the structure of the framework you are building for automated testing and how you could build a framework that is easily maintained and can be expanded any time.

These are general suggestions your implementation may wary based on your environment.

And they will be made using java.

So here goes nothing...

Chapter 1. Technology

What kind of technology do you should use when you want continues integration, nightly builds, any easily executed tests.

First of all... Let go over the basics:

1.1. Continues integration

This means that you always have some functions implemented that you always build integrate and test and that mostly all of these are happening automatically. This means that there is a server or some kind of software that runs builds over night or at weekends if the build is to big.

Example softwares that are free of use are: Hudson, Cruise Control, Apache Maven, Cascade, Buildbot, and so on and so fort. The mainly used are Cruise Control, Hudson, Maven and maybe rationals tool.

These can be configured to build your application every night. These tools work with lots of configuration and lot of ant/nant scripts.

1.2. Automatic Building

So you set up your environment and you have your Maven / Hudson / whatever set and ready to go... What you need now is a building tool. For this there are two great building tools that are used all over the world. These are Ant and Nant. Where nant is a .NET version of ant really.

Ant can be used to build everything really. And it has a lot of other functions too, like. Creating directory, moving files, executing tasks, integrating behavior and lots more.

These you will use to create build.xml-s that build your automation framework and executes the tests you got.

1.3. Test run framework


Next you need a framework that will organize and run your tests. These usually are xUnit where x can be a lot of things like j for java and n for .NET and r for Ruby and p for PHP and so on. And then for java there is testng what i'm currently using. It is a great tool but you have to decide for yourself which one you will use.

1.4. Web Automation Framework

There are a LOT of good automation frameworks out there. And i mean a LOT.

I will just name a few of the big ones.

  • Selenium
  • WebDriver
  • Watir
  • Watin
  • Ranorex
  • Sahi
  • WebAction
So there... These are a LOT of tools. I'm using Selenium currently because i believe that they will rule over all in time. :) For a huge list look at this: http://www.softwareqatest.com/qatweb1.html

Chapter 2. Main structure

So let us talk about how your environment should look like in java...

2.1. Modularity and basic principles


For your environment to work properly you have to consider a few things first...

First, that it will expand beyond any comprehension. This means that whatever you think how big it will get, IT WILL GET BIGGER! You will have over thousands of files that will contain over thousands of code and other stuff.

You will have to write a structure that can handle this kind of load. And you have to write it so that can handle maintenance. That means that if something breaks than you wont lose your head trying to find the problem. And then fixing the problem introduces another couple of problems.

That is something we don't want.

And it can be easily avoided for that matter. You don't need so much fancy Design Patterning or to complicated stuff. There are only a few rules that you have to follow.

Everybody for himself.

Means that everything you write every object every file only needs to be aware of himself. It only needs to take care of stuff regarding to that object only.

For example you have a class that creates ui elements that you work with. That means that everything regarding ui objects is handled in that class. It means that if some kind of problem occurs with an element, like the element is not found, then you know that you have to look in that class and that class only. ( And in the tests because sometimes you just forgot something or misspelled it :P )

KISS - Keep it Simple Stupid.

This is a basic concept and it works. You don't need to fancy tests and scripts that a programmer would create. These are programs of course but they need to be kept as simple as possible. Why? Because not all of your testers have a degree in programing science or even care to have one.

You need to keep it simple for maintainability too because the simpler the easier to edit and poke in it.

Everything in one place.

This is similar to everybody for himself. It means that everything you write or edit needs to be in one place only. This means ui elements, configurations, variables, names, users, passwords, settings, instantiations and so on and so fort.

For example you have selenium and you can start it in more then one way. Than you should have a class dealing with JUST selenium. Or you have a couple of settings like usernames you are using to test with. These should be kept in Java property files.


Chapter 3. Hard facts

So let go forth and present you with an example. Just so you see all these things working together.

For example let's say you have to automate a web page.

Technologies you are using are:

  • Selenium
  • TestNg
  • SimpleXml for Java
  • ReportNG - Reporting for TestNG - Nice piecharts
  • Ant
  • Hudson
Okey. What you want to achieve. You want your tests to run every night and you want your developers to run these tests before they commit. At least a portion of them not all. Just for example the login screen.

First you build your framework.

You have selenium in a separate class taking care of.

You have Base classes for All your tests taking care of functions that all tests should run, like setUp and tearDown.

Your tests should look something like this: doLogin; checkStatus; doLogout;

This is easily achieved too. You just need to hide your logic from your tests. Have test classes and then have Implementation classes. The test would only look like this:

@Test
public void loginTest()
{
LoginPageImplementation loginPageImpl = new LoginPageImplementation(seleniumInstance);

loginPageImpl.doLogin();
loginPageImpl.checkStatus();
loginPageImpl.doLogout();
}

Tada.... You have your test. It is easily readable. You know what it does although your don't have a clue what the implementation looks like. The implementation would be something like this:

public void doLogin()
{
selenium.type(username.xpath);
selenium.type(password.xpath);
selenium.click(loginbutton.xpath);
}

Tada.. Of course there are a bunch of more stuff to it like waiting for a page, and checking if the login was a success but again. It is really simple and you know what it does.. Why?

Here is a trick hidden again. What does username.xpath mean? Well selenium works with locators. These locators find elements on the web page.

Again like i said every man for himself. You need to encapsulate the ui objects on a webpage. How you do that is completely up to you.

I'm using xml Serialization. That is why i'm using SimpleXML for java. I have a class that holds UI objects and an XML telling how does objects are working.

For example:

The xml would look something like this:

//input[@id='usernameInput']
usernameInput
And your object hierarchy would look like UIElement - Elements. And in Elements you would have WebElement value... ( Look under the documentation for SimpleXML it is really simple! )

This way if something on the page changes you again have to look only at ONE PLACE!!

This is really important in ways of maintainability because if something fails and you have to look at at last 5 places to find a bug... well that is a sign you are doing something wrong.

Chapter 4. Last words

So i hope that helped... Any constructive comments are appreciated and tell me if something was too complicated or left out...

Stay Tuned for the next Post on which i explain how to put it together with ANT TestNG and Hudson! :)

Cheers,
Gergely.

2010. június 3., csütörtök

GTD - Getting things done

Hi folks!

Today i want to write about GTD. It is another buzz word that got reinvented and sold to stupid people.

Guess what, I've been doing GTD for at least 10-15 years. We just called it frigging note taking back then. You took your little notebook and a pencil and you started writing down stuff. And if you wanted to scribble something next to an objective then you did it in under half a minute.

GTD didn't require a fancy UI. Fancy UI is just distracting. It takes your heart of the task ahead. And despite any kind of alert you never will use a software for GTD. Because they are cumbersome. They don't work fast enough, they aren't around, you close them or put them on tray and never ever care about them again. And they are slow. Sure you can add a new task in under a minute but you wont. Because you play around with the time and deadline and stuff like that.

You don't have to and it's only distracting you. And if you want to doodle a picture next to a task? Sure you can attach nice picture. Nice pictures are good. BUT THEY ARE NOT HELPING! Why? Because they distract you. You begin to look for the task only to see the nice picture but you aren't actually working on the task.

Imagine i write down a task and draw a little dog next to it. With a pencil? 25 seconds. With the machine? More... You search for the picture, that doesn't quit do it, this one isn't black, on this the dog looks stupid, the task has a false dead line, maybe i add some more... The list looks not organized... etcetcetc...

So I've been doing this for years and now some guy comes around and tells me i gotta give him credit because i'm doing what he said?! Hell no!

Programs will never be able to give you the satisfaction a good pencil and a good moleskine notebook will give you. I'm coming in every day and the first thing i do i writing down my tasks ahead of me for that day. Every day a new page even if i have some tasks left on the other day. then i'm writing then down again. Because you have to remind your brain every day. And then i leave my notebook opened on that day in from of me or next to my laptop. It's always around i can always see my handwriting and the fine paper of the notebook wanting me to write on it. Wanting that i have to complete some tasks and fine some new ones i can scribble down.

So people... Get to it. Get some paper and a good pencil and you will see production increase. And forget GTD it's only a damn word. Do what you like and how you like it. NOBODY can tell you what you want and how you want to do it.

2010. június 2., szerda

Usefull stuff

If you have multiple working environments and machines and you have files that you gather and put it on an ftp server or a usb stick or things like that... Then here is a solution for you:


If you know dropbox then still here is a small tip for you...

You can synchronize your work environment not inly by sharing files... You can share settings too!!!

So if you for example make your eclipse save your profile into a dropbox folder, then when you get home and turn on your home computer, your eclipse will open up where you left it at your work.

Or firefox profile settings into a dropbox and when you get home and open your firefox it will open the same pages that you left open at work.

This is a very effective and very cool way to use dropbox.

Just don't forget to close all the porn pages you left open at home ;))

2010. május 26., szerda

Moving

Moving into a new company is never easy. Except if you hated your old work.

I didn't hate mine. So now i'm working in a new one. It is interesting of course and the work is much challenging and i will post stuff about it after i'm feeling more comfortable and i have the time to do so.

Until then... this is Skarlso, keep your heads up for update... and now. Some music...

2010. május 14., péntek

How does a porn star pay for her speeding ticket?

With money of course...

And if you are a tester and you didn't thought of this idea then you did two things wrong:

  1. You assumed something
  2. You used a stereotype which was present in your head
As a tester your first question should have been:

"Well i'm curious... how?"

As a tester there is a rule of three that you always have to follow no matter how trivial the problem seems.:

  1. Never assume anything
  2. Always question everything
  3. Never trust anybody
This is a good rule of thumb to follow and should be apply to your life as well. If somebody tells you that the apple you are going to buy at a store is really really good would you buy it on his opinion? Of course you would do that. Because you assume that the guy doesn't lie and has tasted the apple before. And then you bring it home and take a bite and immediately spit it out because it's damn sour. And when next time you meet the guy you ask:

- Hey that apple was pretty bad.
- Why?
- It was sour as hell.
- Yeah i like that a lot, i told you it's good.

Yes you see it was good from HIS point of view not yours. So never trust anybody unless all agree and never assume something before you didn't taste the damn thing.

Gergely.

2010. május 11., kedd

Child parenting in the views of a tester

I want to write about something funny this time.

What is the biggest project you can imagine? Empire state building? Two towers? Pyramids?

Yeah there is something much more bigger. Parenting is almost the hardest and most impossible task that you can face in your life. It is easier to jump from a plane with a parachute. There are so many things that can go wrong...

So how about mapping some of the testing heuristics to child parenting.

Let's see...

In the first few months you got to build your framework you got to find out your user stories and do an initial test case identification. You do a basic exploratory testing and find that everything is okey, the child comes around pretty well. You begin to plan for the future, you develop tests and user stories like:
  • As Amy, i would like to go to collage to be able to get a degree
  • As Amy, i would like to get a breast implant so Joey finds me attractive
  • As Mark i would like have my ears pierced so i could sleep with Amy
  • As Amy i would like to have proper parenting so i don't sleep with Mark just because he has a cool ear piercing, and oh my god did you see that biceps?
So you then begin to run some more tests until you can no longer control the child's evolution. And then comes user acceptance testing. You get a lot of feedback from other people about your child's behavior and general working processes. She did sleep with Mark and you are disappointed that there was something wrong during the testing phase. Now you have to re-factor the child.

This is no longer easy since you are over the initial phases so you have to put in a LOT of effort. That costs time, money, nerves, and a new breast implants for Amy. Eventually you get around and can introduce some patch work on Amy and you are over running your User Stories again and again comes user acceptance testing. This time the feedback is good. Amy behaves and it seems everything is working fine.

And then at some point in time without any notice at all a user comes along and says that he saw Amy doing drugs in the ally. You rush to your child you try to reproduce this bug, but you find nothing. You go again to the user and say that could he specify a bit more what he saw and where. The user tries to describe the bug again, says Amy was there at 2010.05.15. And then you realize that it couldn't have been Amy because she was with you on a weekend vacation. So you reject the bug and say that it could not have been her.

After a while the project gets fully out of your hands into the final stage in which whatever you do, you can no longer perform a re-factor because it became to huge to mess with it. You can only provide some workarounds and good documentation to the user. Maybe hide some of the bugs that were found. Or try to introduce new functionality to hide the old faulty one. ( She get's that breast implant after all ).

So folks. Raising a child is like bringing a huge project to success or at least not to a failure. But don't worry, the feedback is pretty good and if you manage your time properly you don't even have to work overtimes...

Gergely.

2010. május 9., vasárnap

No coding required.

hi!

Today i want to write about automation frameworks who try to sell them selfs by saying: "No coding required."

I don't like frameworks like these and i tell you why. Because it's bullshit. And it is dangerous too. Because it gives illusions. It gives false hope to managers it gives you an extra amount of work and extra amount of stress because of illusions.

Basically when there is a framework that tells you that there is no coding required it often means that it can generate code. This is great all in all, but.. It does not mean that it does not require code, because, let's face it. You REQUIRE a robust, working, expendable framework which will work for another one or two or twenty years. And you can have that without coding.

You require coding IF:

  • You want an environment with which it is easy to work
  • You want an environment which can be easily expanded
  • You want an environment which wont fail if you add another test or 200.
  • You want an environment which is portable
  • You want an environment which is configurable
  • You want an environment which can run on every kind of browser and op system
  • etc.
So you don't get to work around coding. You don't get to skip that part. And why is it dangerous? Because your managers will be impressed and passioned about it and you got to suck it up. Because you won't be able to explain them why it is a lie or at least a partial truth.

What i would like to see is adds that say:
- We can generate code
- We can create a partial framework that needs revising
- We can create a framework skeleton

And so on and so fort. So be very careful what you show to your managers and operatives because they tend to believe in adds.

Gergely.