Steve's blog

Wednesday, February 14, 2007

Selenium and Ruby: They actually work together!

So we found out this week. Just wanted to do a brain-dump so I could remember how to configure the Selenium Remote Control to work with Ruby on Rails.

For a refresher, Selenium is a testing framework that allows you to test the clicking-around aspect of your web application. It allows you to record clicks and all sorts of actions that you may routinely perform to test whether you have broken something in your web application after changing some code. I recently started using this week after having some major changes in a application that I am working on with a friend.

A major portion of code was changed from being mostly server-side code (with a ton of SQL calls) to client side (using JavaScript). This threw a wrench into our testing of the application because we could no longer test the actions that one might perform on the screen because there were very few calls being made to the server through Rails (it was all being done with JavaScript in the browser). So to test this we decided to go with the most excellent program Selenium. The following is a somewhat detailed overview of how to get Selenium testing working with Ruby and Rails, and by that I mean being able to write your Selenium tests with Ruby code:

  • Get Selenium IDE (the Firefox extension).

  • Install selenium gem (gem install selenium).

  • Install win32-open3 (gem install win32-open3); apparently Selenium needs this to be able to pop open a new browser window, but you may wish to try it without it to see if it still works.

  • Download the Selenium Remote Control and stick the unzipped folder into the lib directory of your application; you may wish to delete all the extraneous garbage, since all you will need is the ruby folder and the server folder.

  • Start a test server (script/server -e test --port 3001) for selenium to work with so it doesn't try to use your development db. Choosing the port number is optional, but you will need to know which port this server is running on to use in your test file.

  • Start a java server (make sure you have JRE 1.5 or higher) by navigating to the selenium/server folder in your lib directory on a command line and type java -jar selenium-server.jar. This will start a Jetty server on port 4444.

  • Make a folder in your test directory named selenium. This is where you will put your selenium tests when you make them.

  • Save some recorded tests from the Selenium IDE in your test/selenium folder. You will need to perform the test in the IDE and then export the tests as "Ruby - Selenium RC". This will package the normal table tests into some handy Ruby code. You will need to rename the test class to be a proper name (something like MyNewSeleniumTest) and also whack the require 'test/unit' and replace it with require File.dirname(__FILE__) + '/../test_helper'.



Your selenium test should look something like the following, and should follow the normal Rails naming conventions "my_new_test.rb":


require File.dirname(__FILE__) + '/../test_helper'
require "selenium"

class MyNewSeleniumTest < Test::Unit::TestCase
def setup
@verification_errors = []
if $selenium
@selenium = $selenium
else
@selenium = Selenium::SeleneseInterpreter.new("localhost", 4444, "*firefox", "http://localhost:3001", 10000);
@selenium.start
end
@selenium.set_context("test_new", "info")
end

def teardown
@selenium.stop unless $selenium
assert_equal [], @verification_errors
end

def test_new
@selenium.open "/"
@selenium.type "b-query", "hey yo"
@selenium.click "b-searchbtn"
@selenium.wait_for_page_to_load "30000"
@selenium.click "link=Privacy Policy"
@selenium.wait_for_page_to_load "30000"
end
end



Pay close attention to this line in the setup method: @selenium = Selenium::SeleneseInterpreter.new("localhost", 4444, "*firefox", "http://localhost:3001", 10000). The "http://localhost:3001" should be the port that your test server is running on. We banged our heads against a wall for quite a while until we figured that out. You can also choose Firefox or (::dread::) IE. Mac users may want Safari, but we haven't checked to see about any surprises with Safari and Selenium.

That should be all you need (not that much, right?). Now you can run your tests from the command line like you would any other individual test (in Win-doze: ruby test\selenium\new_selenium_test). You can set up a rake task to run all of your tests for you pretty easily:


namespace :test do
Rake::TestTask.new(:selenium => "db:test:prepare") do |t|
t.libs << "test"
t.pattern = 'test/selenium/**/*_test.rb'
t.verbose = true
end
Rake::Task['test:units'].comment = "Run the selenium tests in test/selenium"
end



Now you can simply call rake test:selenium from a command line (with your test server and Jetty server running) and your tests will pop up in a new browser window and spit out the results at the end.

Now, go and use this information for the greater good. Share it and love it.

|

Saturday, September 10, 2005

New Gun!

Here it is, my "new" K31 Schmidt-Rubin 7.5x55mm Swiss rifle!!! Bought it from AIM Surplus last week in pretty beat up condition. The metal is in beautiful condition, probably about 80-90% blueing still in great condition and the bore still shiny, but the stock was beat up beyond belief. I had it for about a day, and when I woke up the next morning, staring at the nasty looking stock, I decided that it needed a good refinishing to make it blossom into the gun it was truly meant to be. The following pictures take you through the refinishing process step by step.

It doesn't look too bad in the pictures, but believe me, there were plenty of dents and scratches on the stock. Lots of grime and dirt accumulated over 40+ years didn't make it any better looking either. These soldiers took really good care of the metal, but neglected to keep the stocks in nice shape too.

The next step was to strip that nasty finish off and get down to some bare wood. I did this by filling the bathtub with piping hot water and mixing in about a cup or 2 of Ajax powdered cleaner (the kind with bleach) and scrubbing the stock down 5 or 6 times with some green Scotchbrite scrubby pads. The bleach didn't do too much to the wood, it was the sodium and calcium carbonate that did most of the work. Voila! Bare wood as seen below.

I was originally going to stain the wood and get a cherry colored finsh, but I decided to go against that since I would have to go all the way back to the store and buy some stain. So instead I used the finish that I was originally going to use on the bare wood. I picked up a quart of Formby's Tung Oil Finish for the job. I know that some will say "That's not real tung oil," to which I will say "I don't care." It seemed to work well enough after 6 coats. I'm sure I could get a deeper looking finish and get the grain to stand out more with some more coats, but I was impatient throughout the whole process. Mind you, it only took a total of 3 days from start to finish to get the results shown below. I am pleased, and the gun altogether cost me about $140 (with shipping and transfer fees). The supplies for finishing cost me $10. I had fun, and don't think I would have paid any more money to get a nicer looking gun off the shelf. Tell me what you think.

|

Tuesday, August 16, 2005

Math...gross!!!

Just wanted to comment on what I heard driving home today. There was a 20 second news clip about how 4 out of 10 people hate math, and most blamed it on their public school teachers for not making it more interesting. The part that got me was when one women said that math is "cold and calculating"...well, duh!

I mean, of course math is calculating; and not just because you need a calculator to do it (which you don't). Math is just pushing around numbers and decimal points. I think those people really hate the idea of doing math, and not the math itself.

I then hypothesized a hypothesis on why she thought math was cold. If math can be cold, it can also be hot by the mere definition of the two terms (cold is the absence of heat, so if something is lacking heat, it also implies that it can somehow be made warm or hot). So then, there are two factors which play into how "cold" or "hot" math is (math is represented by numbers, so we will go by how cold or hot numbers are). The sign and the length (not size) of the number play great roles in determining how "hot" or "cold" the number is. The sign dictates which one it will be; ie: if a number is positive it will always be more hot than it is cold, and conversely, if a number is negative it will always be more cold than hot. The length (or amplitude) of the number then plays a role in determining how severe a degree of hot or cold the number is; ie: the longer a number is the more hot or cold it is (eg: the number -17482 is several degrees colder then -328, and 87437928 is degrees of amplitude hotter than 3873. It must also be noted that decimals do not count towards the hotness or coldness of a number unless the numbers in question preceeding the decimal point are the same (ie: the number 237183.787 is slightly colder than the number 237183.925).

If you can still remember what I typed at the beginning (or if you are still reading this nonsense), I would assume that the woman claiming that math is "cold and calculating" was looking at her credit card statement and noticing that she had a sizeable balance (indicating a negative number, which is always cold no matter what).

I had a pretty long drive home.

|

Wednesday, July 20, 2005

Hunting Safety

So, this weekend I took my North Carolina hunter safety course. I wish I could say this it was exciting, but having already taken the same thing in NY when I was about 14, I can't say that it was anything special. But now I can shoot me up some critters! So I guess it was worth it.

I'm looking into getting one of these beauties to shoot aforementioned critters:

SKS, 7.62x39, same round as an AK-47. I've read that it isn't that big of a round, but it will take down anything within about 100 yards. I'm planning on keeping the iron sights on since a scope isn't easy to mount on these things, so 100 yards sounds good for me. I won't have the detachable mag since I've read that they only cause headaches. Come to find out, my father-in-law has one that he hasn't shot in years, so maybe I can pick it up from him for a deal!

One interesting factoid I learned at the safety course is that 4 hunters died in North Carolina last year. Three of them died from falls in treestands. OH NO! 75% of all the hunters killed last year died because of treestands!!! RUN FOR THE HILLS!!! Well, that's what the instructors made it sound like anyway. I figure, if only 4 people died in the whole state last year and 3 of them fell out of treestands, this is not grounds to make a statistic. Maybe if 4000 people died hunting last year, and 3000 of them fell out of treestands, then maybe they would have a statistic. n=4 is not a good sample size!

|

Saturday, July 09, 2005

Spike "Remember that I'm black" Lee

When asked about his take on guns, the blaxploitation film guru replies:

I'm not a fan of the NRA, and until we do something to curb the sale of guns in the US, we will continue to be the most violent country in world history.

Whoa! Stop the bus and get out of the back seat Spike! US is the most violent country in world history? Well then, let's take a look at some of those nasty facts which will help us dispel your laughable viewpoint. We'll start with the most violent country and work our way down to the US:

Murders committed with firearms, total
  • South Africa: 31,918 total in 2000
  • Columbia: 21,898 total in 2000
  • Thailand: 20,032 total in 2000
  • United States: 8,259 total in 1999
  • Mexico: 3,589 total in 2000

OK, now that we see US is #4 for total murders with firearms in the world, let's look at the per capita deaths and see where we fall:

Murders committed with firearms, per capita
  • South Africa, population ~44,000,000: 0.725 per 1000 people
  • Columbia, population ~43,000,000: 0.51 per 1000 people
  • Thailand, population ~64,000,000: 0.313 per 1000 people
  • Mexico, population ~106,000,000: 0.034 per 1000 people
  • United States, population ~295,000,000: 0.028 per 1000 people

Well Spike, from these statistics, and the fact that guns are more readily available now than they have been since their invention, it appears that South Africa is the most violent country in world history (to which that violence can be attributed to gun deaths). Don't worry Spike, this violence rate can't be caused by the noble blacks in South Africa. It must be caused by all those mean whities over there. Go make a movie out of that.

Sources:Population & Murders.

|

Friday, July 08, 2005

Canada

As if those hosers didn't have enough to worry about already, what with socialized healthcare and the French-Canadians, they now have to worry about this. When asked about same-sex marriage, the brilliantly insightful Senator Marilyn Trenholme Counsell said:

As a Christian, I often ask myself ‘what would Jesus do?'... In this case, in this time, I believe he would say yes.

NO!!!

Click here to see what the lovely and oh so bright Penciloid has to say on this subject.

Read the Old Testament! Read the New Testament! Malachi 3:6 - "6For I am the LORD, I change not;...". Is there something she does not get??? I read her bio, and among some of her distinguished honors are the National Adult Literacy Database Award, and she also supports the Library Program of School District #2. You would figure with that kind of support of reading she would be able to read through the Bible and see that God detested homosexuals in the OT, continued to detest homosexuals in the NT, and continues to detest homosexuals today. Maybe her failure to grasp that concept is a sign of why she supports the New Brunswick Learning Disabilities Association, because I don't see how you could say something so blatantly wrong about The Lord and Savior on so simple a subject and not have a learning disability.

One other thing of note is my use of the word "homosexual" instead of "gay". I have begun to prefer the word "homosexual" since it is a gross perversion of the word "gay" to be used in such a context. First they ruin "gay," now they want to ruin marriage. What's next? Shall I be seeing hunters wearing blazing pink hunting vests with purple hot pants, prancing through the woods during deer season?

|

Tuesday, July 05, 2005

Northern Aggression

I've recently been reading The Politically Incorrect Guide to American History by Dr. Thomas E. Woods, Jr., and I must say this book is more than an eye-opener for someone with my seriously lacking, public school, watered-down understanding of history, particularly US history. The section that I have just finished reading goes over the Reconstruction Era, a time many Southerners wished could be blotted out from existence. I always thought the South was just sore from having just lost a war for their right to govern themselves and enjoy their liberty, but according to this book it goes much deeper than that.

What I found particularly interesting was the section on the 14th Amendment. On the first go-around of its ratification, 10 of the 11 Southern states did not ratify it. Why should they?! The 14th Amendment basically said "Any Confederate Officer or soldier during the civil war cannot hold office unless we deem him worthy. Oh, and all of your debts from the war can't be paid back, but ours can. Oh, and you can't be compensated for any of your slaves that were freed using the 13th Amendment. HA!" Any Southerner with a pulse would realize that these terms were humiliating and extremely unfair to say the least. "To the victor goes the spoils" is an understatement. This was like kicking someone in the head while they're down.

So, the South says "Go find someone else to torment" with their non-ratification of the Amendment. So what does the North have to say? Wisconsin Senator James Doolittle: "The people of the South have rejected the constitutional amendment and therefore we will march upon them and force them to adopt it at the point of the bayonet". Well, if that doesn't sound like a compassionate conqueror then I don't know what does.

Spurred on by the South's incorrigible behavior the mostly Radical Republican Congress passed a series of acts that declared the 10 of the 11 Southern States that did not ratify the amendment non-existent governments. Poof! Ten state governments just disappeared and did not exist. Martial law was then imposed and the 10 former states were divided into 5 military districts. The 10 former states were then told that to become states again they would have to:

  • Draw up new state constitutions
  • In the new constitutions, acknowledge abolition of slavery, introduce black suffrage, and admit the unlawfulness of secession
  • Ratify the 14th Amendment

Woods makes the point that if these state governments did not exist, then exactly how did they have the ability to ratify the 14th Amendment? It was all just bullying and scare-tactics by the North to make the South pay for their insurrection.

The more I read about the Civil War and its subsequent proceedings, the more I side with the South. Dio Vindice!

|

Monday, July 04, 2005

UK in the Gutter

HUNDREDS of Church of England clergy doubt the existence of God and fewer than two thirds believe in miracles, a study out today says. The report, published on the eve of the General Synod, refers to “very fragile faultlines along which the Church of England could be torn apart”. Congregations are much more conservative than most of the comparatively liberal clergy preaching to them.

The report says that if committed Anglicans are clear about one thing it is the existence of God: 97 per cent have no hesitation in affirming His existence. Yet, it contyinues, one in 33 clerics doubts the existence of God. If reflected throughout the Church’s 9,000 clergy the finding would mean that nearly 300 Church of England clergy are uncertain that God exists.

This, ladies and gentlemen, is a disgrace to God and a defamation to all those who faithfully follow him. The article goes on to tell how the clergy and the laity differ over the morality and viability of a homosexual becoming a priest. Clergy in favor: 33%; Laity in favor: 25%. OK, correct me if I am wrong, but shouldn't both of those numbers be ZERO?!! It makes you wonder if there is something in the water over in England. Some parasite seething in the drinking supply, infecting the brains of wayward Anglicans and pushing them to the progressive viewpoint of "whatever makes you happy is alright with me."

It's almost as if, wait... could it be, that very few to none of the people in favor of these blasphemies are reading their Bible? If I were a betting man, which I'm not, I would wager that most of the anti-Biblical leanings are caused by a simple lack of Christians reading their Bibles. And if these "Christians" aren't reading thier Bibles, then how do they know that they are Christians? Answer: they don't! It would be like me calling myself a golfer if all I did was hang out with a guy named Basil who shanks the ball all day every day out on the course, and then he comes in to tell me how well he did and what I need to do to play as well as he does. It's the same with these Christians: they say they are Christians even though they don't read their Bible, don't believe in Biblical truths, and listen to preists and pastors who give them their opinion of the Bible. You cannot have opinions about the Bible. It's all or nothing; Either you believe in the Bible as God inspired truth, or you think it is a crock and use it to prop up a wobbly chair.

If you are a Christian and haven't been reading your Bible lately, pick it up, dust it off, and find a cozy chair and read up. If you're not a Christian, go find a Bible (probably under your wobbly chair) and start reading. It could save your life.

|

Manly Gun

This is a mans gun. I can tell because the grips smell like cigars.

My dad gave this (Colt 1911A1 .45ACP) to me as a Christmas present since he never shot it and got it for about $100 from an old WWII vet. I'm not exactly sure how many Nazis the old-timer shot with this, but I'm hoping that it was... a lot. All in all, it's a sweet gun. It has some weight to it, so it doesn't kill me with the recoil like some of the light-weight, polymer frame 9mm's can. It's a pretty decent shooter too. I wouldn't go as far as trying to use this as a CCW, mainly due to it's weight, but it is a nice gun to have. I feel a little more secure at night knowing that if someone broke in and wanted a fight, they would have to deal with the business end of this machine.

|