My blog has moved!
You should be automatically redirected in 5 seconds. If not, visit http://samueladesoga.wordpress.com and update your bookmarks.

Monday 11 April 2011

My notes from the selenium conference 2011

I had the opportunity to attend the selenium conference and loads of good stuff, i must tell you. This post is an attempt to highlight the conference talks/ seminar that i really enjoyed.

1. Page Object 101: This was a workshop delivered by Patrick Wilson Welsh and Adam Goucher. Even though I have done a lot of page objects in the past, at a glance i like the way patrick has approached html elements, (wraping each html elements in a class), it feels like writing selenium code in a watir way.

The full source code of Patrick's work be found here:

https://github.com/PillarTechnology/SeleniumPatterns/tree/master/selenium-rc-patterns


I hope to have a closer look, and learn one or two things to do page object better in the future. Note that Patrick's work has been done in selenium 1.

2. There were a number of talks about what Selenium 2 bring to the testing table. I noted a few things from several workshops and presentations.

- Generally Simon Stewart claims that Selenium 2 is much more faster than Selenium 1. This should be evident i believe from some example i hope to explain below.

Locating Elements by XPaths

- If i have the followin code snippet in selenium 1:
selenium.click("//div[@id = 'some_id']//*[@class = 'some_class']");

This would be written as:
driver.findElement(By.id('some_id')).findElement(By.className('some_class')).click;

From the example above, this eliminates the need for the use of xPath and as a result would increase the speed of such tests.

Waiting For Elements to Appear

In selenium 1, if you use the Wait class you would do

new Wait("Couldn't find close button!") {
boolean until() {
return selenium.isElementPresent("button_Close");
}
};
In the code snippet about, the test would spend have some time to wait for the element to appear, and then you would something like:

selenium.click("button_Close");

In selenium 2, this would be replaced with

WebElement close_button = new WebDriverwait(driver, 10).until() {
driver.findElement(By.id('button_Close'));
}

close_button.click();

The difference is that the 'until' methods of the WebDriverWait class waits until the condition evaluates to a value that is neither null nor false. So this means it would return any object be it boolean or a WebElement object.
NB: note that the code is for illustration, you might need to tweak for it to work properly.


Sleeps

In the talk by Dante Briones, I can remember a section in which he talked about the dangers of using sleeps in tests and I loved his suggestions of wrapping Thread.sleep() in an appropriately named methods such as:

couldNotDoTheNeccessaryHardWorkAsIWasLazy();

I think the morale of the story is that using sleep in your tests is evil.
Nice :)

3. There were also several sessions around Web Performance testing and this was more educating for me as i learnt a few things that i hope to explore in great depths in the future
- I learnt about the BrowserMob proxy which can be used as a DesiredCapability in association with Firefox2. These can also be used for blacklisting/whitelisting urls, redirecting urls, setting internet speed and many other uses.

- Also learnt that we can do similar things with the FiddlerCore Api but this would only work on .Net platforms.

- There was also a slide about platform specific tools that can be used to capture performance metrics. Tcpdump for windows platforms and PCap for linux/ Unix platforms.


its always nice to know about more tools that would make me a better technical tester and i hope to explore these tools in depth at a future date.

4. At the end of the conference, Simon Stewart took a few of us through the selenium source code and he was talking about how to build the source. I can guarantee that it would have been impossible to build the source without someone holding your hand (not literarily). I learnt that the build scripts is based on rake, but the guys have a build grammar called 'crazy-fun'.


As i use selenium more and more, i am hoping to be able to contribute to this wonderful tools, but i still have a lot of personal work to do in other to understand all that simon said at that talk.

There were loads of other talks at the conference and as soon as the source code / slides / videos are posted. I would update this post with some more links.


Enjoy!!!

Wednesday 22 December 2010

Rails3 'link_to' displays literal HTML on front end

In the last month, I have been working on a rails3 app and I ran across this interesting problem where I need to create a href link to a another page from my current page.

In my view i have written

<%= "Please click on this link #{link_to('here', new_house_path)}" %>

And interestingly this is displayed as

Please click on this link <a href="http://localhost:3000/houses/new">here</a>

on the front end.

Hours of frustration and google searches leads me to doing this:

<%= ("Please click on this link #{link_to('here', new_house_path)}").html_safe %>;

which then is displayed correctly on front end

Please click on this link here

if that isnt clear enough, the trick is you need to wrap the string with a 'html_safe' method

Off i go to learn more stuff .....

Tuesday 12 October 2010

Installing mysql on snow leopard

I have always struggled with install mysql on my snow leopard, as a result i have decided to keep a link on this blog for this:

http://www.icoretech.org/2009/08/install-mysql-and-mysql-ruby-gem-on-snow-leopard-64-bit/


Hopefully that link would be up for a very long time and i hope it is useful for someone else as well.

Friday 3 September 2010

A tester's reflection on kanban plus BDD

So i have just finished an engagement with a client where the development process used include
kanban and BDD. Kanban for us meant that we give priority to work on the right side of the board.
So as a tester, I would rather spent my time doing some manual testing on a story that is in the QA queue, than writing automated acceptance tests for a stroy in the queue for Accetance Tests.

Maybe it would be worth while to draw a representation of the way in which work flows through our kanban board

Analyis > Queue > Accetance Tests in Progress > Queue > Dev in progress > Queue > QA in progress > Smoke Test > Queue > UAT Deployment in progress > Queue > UAT in progress > Queue > Live Deployment in Progress > Deployed.

The good thing is that everyone in the team has a visibility of work up till deployment. For more information, read up kanban

The BDD framework used was Cucumber + Watir + Rspec, and developers would only start developing software when the tests have been written for the acceptance criteria. (Acceptance criteria is written by Analysts in a text editor in the cucumber format). The acceptance tests is jointly owned by developers and testers. If as a tester i am busy doing some other tasks further down in the work flow, the developers were happy to write the failing automated test for the acceptance criteria before development commences.

As a result of these good practices:

1. The team was always in good spirit and which improves the effectiveness
2. The number of defects raised was low, this was achievable because for a developer to move a story to the QA queue, the automated acceptance criteria must have been passing.
3. There wasnt a defect management system because testing is carried as close to the development time, and if the business believes the defect is critical to the functionality, the functionality of story does not progress further in the kanban board, but it is blocked until fixed and verified.

One downside is that because we wrote acceptance test for virtually every functionality that is testable, the acceptance test grew so quick that the time taken increased from about 20mins to about 1.40mins and this time kept growing. A side defect of this is that feedback time increased and as a result developers would not run the complete test suite before checking their code in. This was however managed by doing some exploratory manual testing around the functionality being developed.

All in all, it was a good experience for me and i just hope i get to work on more projects such as this.

Friday 25 June 2010

Watir: Search for elements on page using multiple attributes

I ran into a situation today where i wanted to scan through a page and return a table based on the table matching 3 attributes

Before:

browser.tables.find do |table|
table.class_name == 'my_class_name' and
table.cell(:class, 'class_1_name').text == 'some_text_1' and
table.cell(:class, 'class_2_name').text == 'some_text_2'
end

This was taking about 3minutes as there were about 86tables on this page under test. I was worried but the tables on this page was gonna increase with time which meant the time for this stage of the test was bound to increase.

In my search for how to search for a single table using multiple attributes:

I found this:

After:

browser.table(:class => 'my_class_name', :text => /#{'some_text_1}/, :text => /#{'some_text_2}/)

Believe it or not, i got my test time reduced to 3secs, awesome isnt it?

Enjoy!!!!!!

Friday 23 April 2010

Implement 'Select column_name from table_name where condition' in Active Record

I need an array from the data contained in a particular database column based on a condition, so i get the array of active record rows:

array_of_rows = TableName.find(:all, :conditions => {:column_name => ['col_data1','col_data2']})

Then use the array map! function to replace the active record objects with the column_name value
array_of_rows.map!{|item| item.column_name}

Doing some search got me:

array_of_rows = TableName .find(:all,:select=>'column_name' :conditions => {:column_name => ['col_data1','col_data2']}).map(&:column_name)

And i like this better, concise ....
update:

I've had to update the active record query above by removing the :select option

array_of_rows = TableName .find(:all, :conditions => {:column_name => ['col_data1','col_data2']}).map(&:column_name)

This is because if i have a method

def find_some_data
TableName .find(:all,:select=>'column_name' :conditions => {:column_name => ['col_data1','col_data2']})
end

I am able to do:

find_some_data.map(&:column_name)

but i cannot do

find_some_data.map(&:another_column_name)

throws: missing attribute: another_column_name (ActiveRecord::MissingAttributeError)

because i have only retrieved 'column_name' values from the table

In other to be able to create any array composed of data from any column_name, i have

def find_some_data
TableName .find(:all, :conditions => {:column_name => ['col_data1','col_data2']})
end

Tuesday 6 April 2010

Active Record find by Column Name

In recent days been doing a lot of ruby, which means i tend to use Active Record as well.

I had written some scripts where i was selecting records that matched a criteria such as:

@table1.table2s.select{|e| e.column_name == 1234}

but as i need to sort my result and also give some more conditions to filter the data, i need alternatives to this above query and i ended up with the two lines of code below:

@table1.table2s.find(:all, :conditions => {:column_name => 1234})
@table1.table2s.find_all_by_column_name(1234)

Please note that the two lines above does same thing, the second one is just a lil but shorter and more readable the the 1st one.

using the second one i can now do stuff like

@table1.table2s.find_all_by_column_name(1234, :order => "col_2 ASC")

which would order my results based on the column that i have specified and i could have ASC - ascending and DESC - descending.

I have learnt something else today .... Have you?