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

Wednesday, 10 March 2010

Blank cells in step tables in cucumber 0.3.11 is represented as nil

In my current job, I have been doing a lot of acceptance test using Cucumber, Watir and RSpec, obvious all in Ruby. I have been using Cucumber 0.6.x, in which blank cells in the step table are represented by empty string (""). This was okay for me until today when i had to use a previous version of Cucumber 0.3.11 due to reasons including compatibility with other projects in the CI build. And my tests start failing because blank cells are represented as nil.

There was fix put in the current release of cucumber to change blanks to be represented as empty and not as nil(for whatever reason, which i don't really care, as both nil and "" has got its own arguments.)

Some code to explain this, Assuming i have a step table as below:

Given that i have the following detail in my app
|Header1|Header2|Header3|Header4|
|Body1 |Body2 |Body3 | |

Notice that the last column of the second row is blank, this would be represented as nil in cucumber 0.3.11 while it is represented as empty string "" in cucumber 0.6.x

In my step definition file, I have fixed this by converting every nil value to empty ("")

Given /have the following detail/ do |table|
table.rows.each do |row|
row.map! {|value| convert_nil_to_empty_string(value)}
# do some other stuff with row as every nil object has been converted to empty string
# The map! method for Array, allow you to invoke the block for the array and it amends
# the existing array
end
end

The method which i call to convert nil to empty is below:

def convert_nil_to_empty_string(test_string)
if (test_string.nil?)
return ""
else
return test_string
end
end

There might have been a better way to do this but this surely worked for me in this scenario and the reason i decided to use a method was that the map! method would only allow me use the variable "value" only once in the block. I am sure there are some rubyist out there, that could advice me on some shorthand for this ....... Hope it helps you too

Friday, 4 September 2009

Selenium Remote cant start firefox session due to lock on file

I am sure you have on this page, because you have run into problem with selenium not been able to run due to a lock on some profile files. Yes, you know what the error is. I really found useful two blogs here and here. However, inas much as i don not want to repeat what has been saidin the blogs i would paste and quote what i found useful and explain a little bit more.

Preparing Firefox profile...

The source of the problem is in the *.rdf files inside the selenium server jar. The Selenium guys have hardcoded a version ceiling for Firefox at version 2.0.0.* (in my case it was 3.5.*). The fix is really simple.

Step 1: Extract the files needing change (from the directory where you have the jar). -

jar xf selenium-server.jar customProfileDirCUSTFFCHROME/
extensions/readystate@openqa.org/install.rdf
jar xf selenium-server.jar customProfileDirCUSTFFCHROME/
extensions/{538F0036-F358-4f84-A764-89FB437166B4}/install.rdf
jar xf selenium-server.jar customProfileDirCUSTFFCHROME/
extensions/\{503A0CD4-EDC8-489b-853B-19E0BAA8F0A4\}/install.rdf
jar xf selenium-server.jar customProfileDirCUSTFF/extensions/
readystate\@openqa.org/install.rdf
jar xf selenium-server.jar customProfileDirCUSTFF/extensions/
\{538F0036-F358-4f84-A764-89FB437166B4\}/install.rdf

Step 2: Change the max version in the rdf (Resource Description Framework) files.

The line of interest looks like this: 2.0.0.*

* you can change this to 4.*, should buy some time.

Step 3: Update the jar with your changes.

jar uf selenium-server.jar customProfileDirCUSTFFCHROME/
extensions/readystate@openqa.org/install.rdf
jar uf selenium-server.jar customProfileDirCUSTFFCHROME/
extensions/{538F0036-F358-4f84-A764-89FB437166B4}/install.rdf
jar uf selenium-server.jar customProfileDirCUSTFFCHROME/
extensions/\{503A0CD4-EDC8-489b-853B-19E0BAA8F0A4\}/install.rdf
jar uf selenium-server.jar customProfileDirCUSTFF/
extensions/readystate\@openqa.org/install.rdf
jar uf selenium-server.jar customProfileDirCUSTFF/
extensions/\{538F0036-F358-4f84-A764-89FB437166B4\}/install.rdf

That's it, once that's changed you should be good to go for testing against Firefox 3!

So that was a summary of what i found, but my case was a bit different as the version of firefox that was hardcoded in the selenium-server 1.0.1 was 3.5.* and my version of firefox was 3.5.2, so naturally i expected firefox to work for me. But as it did not work, as a trail and error, i changed the hardcoded version to 4.5.*. and voila it worked for me.

Also i did not use the jar uf command, what i did was to temporarily change the extension of the selenium server jar file to a .zip file and then i opened the zipped file created with winzip.

I then extracted the 5files which i need to amended to my desktop, amended the file with a text utility and then drop the files back into the zippped selenium server file. Lastly i changed the extensions back to .jar.

And it worked. i hope this works for someone as well

Saturday, 31 January 2009

Need to get a value of an attribute using selenium

I was in this situation when i needed to get the value of an html attribute and i found the selenium.getattribute very handy .....

Okay the scenario was such that there was an element which is collapsible on the page and the only attibute for that element that indictated the status of the collapsible element was the 'Class'. when the element was collapsed, the value of the class attribute was 'asleep' and when the element was expanded, the value of the class atttribute was 'awake'.

The script used to determine the status of this element is
selenium.GetAttribute("elementLocator@nameofAttribute");

so if the id of my element is FundingClass and the attribute we are interested in is the 'Class'

The selenium code will be
selenium.GetAttribute("FundingClass@Class");

Hope this helps someone .....

Tuesday, 23 December 2008

Using selenium.GetEval(script)to execute Javascript

The task at hand was to navigate through the DOM of a particular webpage and check the
style.display attribute of an object or element if you prefer. There are two elements on this page that displayed either success or failure messages.(msgSuccess and msgFailed)
For perfomance reasons, if previously a successful message was displayed and subsequently the you get a failure message, what the developers of the page did was to amend the style.display attribute.

<span style="display: none;" id="msgSuccess" class="MyMsgSuccess">

The HTML code above implies the element 'msgSuccess' would not be displayed

<span style="" id="msgSuccess" class="MyMsgSuccess">

In the second case, the msg success would be displayed ....

The problem i encountered was, sometimes i would have

< span style="display: none;" id="msgSuccess" class="MyMsgSuccess" > Operation Successful </span >

If i do a selenium.GetText("msgSuccess"), i get the text returned even though the style.display is set to none. Hence the need for the Selenium.GetEval to check the value of the style.display attribute as that seem as a true test for the web page

I have done:

const string script = "document.getElementById(\"msgSuccess\").style.display";
string evalResult = selenium.GetEval(script);

The above script failed as selenium was executing the javascript in the selenium console and not on the Application under test (AUT)
and searching the internet got me doing:

const string script = "selenium.browserbot.getCurrentWindow().document.getElementById(\"msgSuccess\").style.display";
string evalResult = selenium.GetEval(script);

This way i got the javascript to be run on the Application under test ....