Bugs provide unique tools for communication of problems between QA and engineers. Too often, QA engineers enter environments where bugs are written like this:

Title: Something broke
Description: I did some stuff, it broke, I don’t quite know what, or how it broke, but I swear it broke. Developers fix this, it’s super important!

Obviously the above bug report is awful. Zero information is provided to developers or other app-owners. Over time I’ve found a good format for writing good quality, reproducible bugs. This format is system independent, so can be used in nearly any Bug Tracking system(Mozilla, JIRA, Trac, Test director, etc etc). It does take into assumption that some fields are available on the bug tracking system. If they aren’t, just put “Field name: ” in the description field of the bug.

Title: This is a general description of the bug in 1 sentence or less
Priority: The bug priority, usually ranked 1->5 or trivial->blocker. Different organizations have different descriptions of each priority type but I like to stick with the following for myself:

(1)Blocker: Testing can not continue, the system is down, some unrecoverable state. There is no work around.
(2)Critical: Testing can not continue down this path, but there may be a work around.
(3)Major: Testing can continue, but this is a client visible issue that will bite us sometime in the future. It might impact a large client
(4)Minor: Testing can continue, no large client impact.
(5)Trivial: Spelling mistakes, grammar, image problems, etcetera

Steps to Reproduce: This is a numerical list of the exact steps you took to reproduce the bug. If the bug is not reproducible following these steps, the bug should not be filed. I can’t stress the importance of filing reproducible bugs. For example to “Save As” a document in Microsoft Word 2010 the steps are
1) Click File
2) Click Save As
3) Enter a file name in the file name field
4) Click save

Actual Results: This is where you write down what actually happened. For the above steps the actual results are:
The file was saved

Expected Results: This is where you write down what you expected to happen. The above steps had the expected result:
File should be saved

The above fields are a bare minimum for filing any bug on any system. Things like screenshots, attachments, firebug results, stack traces, etc are always useful but if the bug is truly reproducible with the steps provided above, are extraneous information.

When running firebug in firefox via the Selenium webdriver, consider that everytime you run your test, firebug acts like its the first time it’s ever been run(since this is a new browser profile).

I was recently shown a way to disable the first-run tab from appearing.

The Ruby code is below. It also shows how to add firebug and firepath to it as well as setting some custom profile/client rules for firefox


profile = Selenium::WebDriver::Firefox::Profile.new
profile["dom.max_script_run_time"] = 500
profile.log_file = ("C:\\Selenium\\firefox.#{Time.now.strftime("%Y-%m-%d.%H%M%S")}.log")
profile.add_extension("C:\\Selenium\\firebug-1.8.2.xpi")
profile["extensions.firebug.currentVersion"] = "9.99"
profile.add_extension("C:\\Selenium\\firepath.xpi")
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 120 # seconds

driver = Selenium::WebDriver.for :firefox, :profile => profile, :http_client=> client

Using CSS selectors in Selenium

So we all know how CSS selectors work but using them to identify elements on a page can be difficult in Selenium, and especially confusing for the beginner Selenium user.

Lets suppose you have a web element that looks like this

<a target=”foo” href=”bar.htm”>SomeWebLink</a>

How would you reference this element?  Well if its the only <a> element on the page, you can definitely call it using by tag.  However, typically it isn’t the only link on the page.

Here are a few ways to call the element by CSS selector:
a
a[href='bar.htm']

Now lets try a harder example:

<a target=”foo” href=”bar_somerandomnumber.htm”>SomeWebLink</a>

Given that the href is constantly changing(lets assume that the random number changes on every page load), you can’t quite specify the href.  However, we can use the beginning and end if we know it.
a[href^=bar][href$=htm]

The ^ tells it to search from the beginning of the attribute and the $ says to search from the end.

To simulate a grid with multiple machines on your local box, you can actually just open multiple command prompts and run seperate instances of the selenium jar in each.

To do this you need to have 1 command prompt running as the hub:


~$ java -jar selenium-server-standalone-2.5.0.jar -role hub

The other command prompts can be added with a specific type of grid instance running in each


~1$ java -jar selenium-server-standalone-2.5.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 5559 -browser browserName=firefox

~2$ java -jar selenium-server-standalone-2.5.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 5556 -browser browserName="internet explorer",platform=WINDOWS

Note the special browsername specification for IE. This comes from the bottom section of the grid specification where they specify special browserNames for different types of browsers

Unfortunately, I was unable to find this specified in any documentation, so I’m putting it here in hopes people will have the same questions I do.

If for some reason you need to run your webdriver tests in DEBUG mode, and don’t want to use the -r flag next to your ruby call (ruby -r testfile.rb….) you can just put $DEBUG=true at the top of your testfile.rb which will also put webdriver into debug mode.

I recently decided that instead of having a standalone Jenkins task to run a Selenium RC server, I’d have it run only on demand of a script, which means, that I have to create a rake file. Unfortunately the documentation at http://selenium.rubyforge.org/document.html was heavily outdated and in need of updating.

Thankfully after some research and discussion I came to the following solution:

Rakefile:

require 'selenium/rake/server_task'

Selenium::Rake::ServerTask.new do |t|
t.jar = "/mnt/jobs/rake/selenium-server-standalone-2.2.0.jar"
t.port = 4444
t.opts = %w[-some selenium options can go here]
end

Then in my main ruby script which controls most of the jobs inside my automation I added the following:


#at top of code
system('rake -f \'rakefile.rb\' selenium:server:start')
sleep 5

#at bottom of code
system('rake -f \'rakefile.rb\' selenium:server:stop')

I also added an appropriate sleep after the server start, to let it come online. I did 5 seconds, I am sure I could cut that down, but why? One thing to be wary of is the use of the system() function, you might want to consider using IO.popen instead.

Big thanks to jarib and adamgoucher for their suggestions/help

I needed to identify what system I was on today for my automation. I found a quick and simple way to just pull the platform out of an environment variable.

def GetOS()
if RUBY_PLATFORM.include? "mingw32"
return "Windows"
elsif RUBY_PLATFORM.include? "linux"
return "Linux"
elsif RUBY_PLATFORM.include? "darwin"
return "Mac"
end

This function returns a string which contains the platform type.

Recently I encountered a situation where I was stuck trying to figure out a way to set a custom user agent for firefox, without creating a new profile. Since my code base is in ruby, this posed a tricky situation. Watir is significantly easier to use the Selenium due to a nicer programming language/interface, however, Selenium allows us to set profile preferences for Firefox. After some research this was what I came up with to combine the two:


require "selenium-webdriver"
require "watir-webdriver"
profile = Selenium::WebDriver::Firefox::Profile.new
profile['general.useragent.override'] = 'CUSTOM_API'
driver = Selenium::WebDriver.for :firefox, :profile => profile
$browser = Watir::Browser.new(driver)

This allows Selenium to set the browser’s useragent while still maintaining the use of Watir. After much discussion in the Selenium chatroom on Freenode, I was able to get them to modify the selenium FAQ/wiki to the list of Firefox preferences. Before the link was there it was severely confusing

Why must release day always be hectic, crazy, last minute WTFery. PM’s, describe the apps to all people in writing, instead of in a skype conversation. Devs, please when you promise to do something to said PM, do it! QA, test it, test it all. Retest.

Release manager: don’t freak out…2.5 hours left!

Well, after 3+ hours, it turned out another developer had not followed my advice from yesterday, and committed over some good code. Me and him will have a nice chat tomorrow.

© 2012 Randoms from Blackberry Suffusion theme by Sayontan Sinha