jQuery in selenium

we all love jQuery. so why not use jQuery in selenium? after all it locates elements. jQuery will make it easy, we just have to add a location strategy that uses jQuery to find elements. These two links helped me get started.

http://stackoverflow.com/questions/2814007/how-do-i-add-a-jquery-locators-to-selenium-remote-control

http://stackoverflow.com/questions/4185640/get-element-with-jquery-and-selenium-ide-1-0-8

Here are the steps i followed. I used selenium-server-standalone-2.2.0.jar downloaded from here.

Step 1:

Extract the jar. I used 7zip to extract.

Step 2:

Edit TestRunner.html inside the core folder.
Add the following as said in SO.

<script language="JavaScript" type="text/javascript" src="jquery.min.js"></script> <script language="JavaScript" type="text/javascript"> function openDomViewer() { var autFrame = document.getElementById('selenium_myiframe');         var autFrameDocument = new SeleniumFrame(autFrame).getDocument();         this.rootDocument = autFrameDocument;         var domViewer = window.open(getDocumentBase(document) + 'domviewer/domviewer.html');         return false; } </script>

And add the jquery-min.js in core folder.

Step 3:

Then add the location strategy to your selenium object as follows.

mySelenium.addLocationStrategy("jquery",
"var loc = locator; " +
"var attr = null; " +
"var isattr = false; " +
"var inx = locator.lastIndexOf('@'); " +


"if (inx != -1){ " +
"   loc = locator.substring(0, inx); " +
"   attr = locator.substring(inx + 1); " +
"   isattr = true; " +
"} " +


"var found = jQuery(inDocument).find(loc); " +
"if (found.length >= 1) { " +
"   if (isattr) { " +
"       return found[0].getAttribute(attr); " +
"   } else { " +
"       return found[0]; " +
"   } " +
"} else { " +
"   return null; " +
"}"
);

Note that this is java code.

Step 4:

Add the following function to user-extensions.js in core/scripts folder.

function jQuery (selector)
{
return selenium.browserbot.getUserWindow().jQuery(selector);
}

Step 5:

Now we need to update the jar file. To do that do something like this.
jar -uf selenium-server-standalone-2.2.0.jar core\TestRunner.html
jar -uf selenium-server-standalone-2.2.0.jar core\jquery.min.js
jar -uf selenium-server-standalone-2.2.0.jar core\scripts\user-extensions.js

Step 6:

That’s it. Just start the server as usual using java -jar selenium-server-standalone-2.2.0

Step 7:

To use jquery to select elements, use something like this.
myselenium.click("jquery=#some_id")

hope it helps.

“No such file to load — application” on Passenger and Rails 3

I got this error when i was deploying a rails 3 app in railsplayground. I was using http://wiki.railsplayground.com/railsplayground/show/How+To+use+Phusion+Passenger as a reference. The error was somewhat familiar, as application controller was renamed to application_controller in 2.2 or 2.3 (not very sure when). Then i came across this post, http://groups.google.com/group/phusion-passenger/browse_thread/thread/676a73280221c93f. Which pointed out, we should use RackBaseURI instead of RailsBaseURI. Yep, the solution is, use

RackBaseURI /

instead of RailsBaseURI /

Ruby on rails – Beginning

I’ve started learning ruby on rails. Will share some useful stuffs on that too. To start with, here’s one.

To specify the root of your rails app, you might specify a default root in routes.rb file. Like,

map.root = :controller => ‘some_controller’, :action => “index”

But still you don’t see what you wanted to see?? Still seeing the Welcome aboard page??

Do not forget to remove the index.html file in public directory. :)

Apply style to all the child elements of a parent – CSS

If you want to apply style to all <p> inside <body>, you would write something like this,

body > p { background-color : #00f; }

Let’s say you have a div element and it contains various other elements. And you would like to apply some common style to all the elements. Believe me, there could be reasons for this!

We can’t go and pick all the elements inside <div>. We could just write,

#id_of_div *
{
//some style
}

So this will apply style to all the child elements of <div> with id  ‘id_of_div’. You can overwrite some style for child elements by picking them specifically like this,

#id_of_div #id_of_some_other_element
{
// some style that will override the style given by *
}

insert single quotes – mssql

You enclose strings in single quotes when you are inserting strings in a table on a mssql server. But when the string contains ‘ (single quotes) and you are not using something like a prepared statement(let’s say you wanna make a manual insertion) how would you do it? Simple. Use the single quotes twice. i.e

insert into table_name(string_column) values ('how're you?')

would become

insert into table_name(string_column) values ('how''re you?')

Cheers. :)

Fix for – E: Could not get lock /var/cache/apt/archives/lock – open (11: Resource temporarily unavailable)

E: Could not get lock /var/cache/apt/archives/lock – open (11: Resource temporarily unavailable)
E: Unable to lock the download directory

to fix these errors, see if any packet manager is running or any update is going on. if u didnt start any of these and have no idea what to do, just do the following

sudo killall apt-get

hope that solves your prob.