Processing defaults in watir elements

Looking at watir code there is a nice patterns for accepting defaults for ‘how’ in method names for elements. Currently for frame, form and button.

like this:

I like this solution for my test framework. I have been thinking of making a small change to my snagit screenshot.
Basically be default I want it to take a screenshot of a :desktop but I also want it to snag a webpage with scrolling.
I still need to understand why the how.class is compared to String and not to Symbol.

And on another note I need to start watir.testr.us page for all watir related info in one place. - The Place To Put Things is a constant challenge, it seems.

Desktop Screenshots with Watir, win32screenshot, RMagick and Snagit

Here is what I had with win32screenshot and RMagick (later replaced with Snagit)

# Runtime Test Housekeeping place
module TestRun

  # at runtime takes a screenshot of the desktop and saves it in log dir.
  # you must install win32screenshot gem and RMagic package for this to work.
  def self.screenshot(context=nil)
    if $testrun[:screenshot] == true
      # prevent runtime error when screenshot gem and RMagic are not installed on client machine.
      begin
        require ‘win32screenshot’
        require ‘RMagick’
        width, height, bitmap = Win32::Screenshot.desktop
        imglist = Magick::ImageList.new
        imgl = imglist.from_blob(bitmap)
        time_stamp_s = Time.new.strftime(’%m%d_%H%M_%S’)
        screenshot_filename = context ? “#{time_stamp_s}_#{context}.png” : “#{time_stamp_s}.png”
        imgl.write(File.join(logpath,screenshot_filename))
        $log.info(”Screenshot captured: #{screenshot_filename}”)
      rescue Exception => ex
        $log.error(”TestRun.screenshot(#{context} — #{ex}”)
      end

    end

  end

end

#usage
TestRun.screenshot() # => makes a MMDD_HHMM_SS.png file
TestRun.screenshot(’blabla’) # appends the string to filename.

The above is an older solution, I’ve had it working for a while but now it has stopped after I upgraded rubygems system. It still works on my other test machines but not on my primary box.

Instead I have installed snagit 8 and I am using it for web page capture. it’s better, definitely better with the COM interface.
I just wanted to post the code here in case I need to refer to it again in the future. (note: logpath method returns path to log directory. The global $testrun hash holds runtime options for the test framework.

Thanks win32screenshot and thanks RMagick, it was fun using it, moving on to snagit OLE interface.

UPDATE:
Here is my current reimplementation using snagit

def self.screenshot(context=nil)
    if $testrun[:screenshot] == true #runtime options guard access

      begin
        require ‘win32ole’
        snagit = WIN32OLE.new(’Snagit.ImageCapture’)
        time_stamp_s = Time.new.strftime(’%m%d_%H%M_%S’)
        screenshot_filename = context ? “#{time_stamp_s}_#{context}” : “#{time_stamp_s}”
        # config input
        snagit.Input = 0 #desktop
        #configure output
        snagit.Output = 2 #file
        snagit.OutputImageFile2.FileType = 5 #:png
        snagit.OutputImageFile2.FileNamingMethod = 1 # fixed #
        #location
        snagit.OutputImageFile2.Directory = logpath   # set directy where filename will be saved
        snagit.OutputImageFile2.Filename = screenshot_filename
        # do the duty
        snagit.Capture
        # wait for capture to complete
        until snagit.IsCaptureDone do
          sleep 0.5
        end
        $log.info(”Screenshot captured: #{screenshot_filename}”)
      rescue Exception => ex
        $log.error(”TestRun.screenshot(#{context} — #{ex}”)
      end
    end
  end

The above works pretty well. my next thing is to implement taking a screenshot of a page with setting Input active window and scrolling it. It’ll be fun.

Doing the Web Test in 3 acts with Watir

In a Story or UseCase for Web Application you can decompose a test into 3 acts. or Steps. (Actually I don’t like to speak of Preconditions and Steps. I much rather speak of Context and Acts in a Web Application testing).

class ThreeStepTest
  attr_accessor :context

  # config context for the test
  def initizlie(context)
     @context = context
  end

  # act one
  def set_request
    # given context configure the page with data.
    # Delegate to watir implementer here to send data to the page.
  end

  # act two
  def submit_request
    # delegate to watir to click on a page to submit form or request next page
  end

  # act three
  def verify_response
    # get context
    @context =
  end
end

class Context
  attr_accessor :given, :expected, :actual

end

the set_request occurs in a Given Context which was created by the previous verify_response.

So a test scenario can be constructed a series of those 3 acts. Context has a :given as a precondition to start with, :expected and :actual.

Anyway, this is just some thinking about constructing Watir framework

Towards MVC framework for Watir Tests

I was thinking about what I call FUNTOM but more and more I call it Semantic Test Objects. Here is my example unofolding towards an MVC type framework for using Watir as my view through some adapters.

#example of class as Semantic Test Object which has mixing of module providing behaviour.
# This sould be a strategy pattern type thinking but who knows.
# it's just my investigations into watir implementation
module DefaultBehavior
  def wag
    puts 'default wag left to right'
    # here call Watir Adapters to delegate actions to the webpage
  end
  def bark
    puts 'woof woof default bark'
  end
end

module SpecialBehavior
  include DefaultBehavior
  def bark
    puts 'raah raah special bark'
  end
end

class DogAsTestModel
  include DefaultBehavior
end

DogAsTestModel.new.wag
DogAsTestModel.new.bark

class DogAsTestModel
  include SpecialBehavior
end

DogAsTestModel.new.wag
DogAsTestModel.new.bark

class DogAsTestModel
  include SpecialBehavior
  def bark
    puts 'overwrite bark. Woooooof Woooooof'
  end
end

DogAsTestModel.new.wag
DogAsTestModel.new.bark

The idea is that class represents Semantic Test Object. It could be a collection of objects on a page.
more to come I hope.

Using HttpWatch with Watir

HttpWatch is a great add-on tool to Internet Explorer that captures your IE HTTP traffic. The best part for me is that it can be driven programaticly from my Watir Tests. The company Simtec has an example of how to do it on their website. So I would recommend you install HttpWatch and run the example for yourself first or just follow along for some other way of looking at the tool.

The complete API documentation is available as a chm file you get with installation, I hope they’ll put it as html online rather than chm so you can google it and link to it.

Here are some of my notes when I investigated the tool for my projects. - It works for me out of the box. (I also use Fiddler2, another great HTTP sniffer). HttpWatch fills my immediate need for Http traffic data which IE natively does not provide and a nice color coding logger makes for a sugar candy for managment and testers alike.

For some of you in the dark about how to use it (I was in the dark when I first encountered the tool) here are some notes and how I understand the usage of the tool so far. (check out the mindmap too. I will update soon.)

So let’s begin investigation. it’s best to run everything from IRB (or just jump to watir-console, see
C:\ruby\lib\ruby\gems\1.8\gems\watir-1.5.3\bin\watir-console)

Open IRB and type some infrastructure code:

require 'watir' # watir requires 'win32ole'
ct = WIN32OLE.new('HttpWatch.Controller')
ie = Watir::IE.new
httpw = ct.Attach(ie.ie)

We just created Controller, then IE instance and made a plugin object httpw by attaching our ie.ie object. In Watir IE class maintains an OLE ie object. This is the object use and not the actual IE from Watir, that’s why to confuse you further we used the same name ie for our main IE object.
Now that you may be confused enough we’ll just plunge in more to see what else we can do.

So far I got a blank IE sitting on the desktop (I am using WinXP and IE6x) and an IRB session open.
Let’s start the Recorder (after clearing the Log)

httpw.Clear
httpw.Record

# generate traffic with watir
ie.goto('http://google.com/')
ie.goto('http://yahoo.com/')
ie.goto('http://blablablaichbinnichtda.com')
ie.goto('http://marekj.com/iwasneverhier.html')

For traffic I just visited two sites I know exist and two pages that do not exist to Log errors.
Now you can stop the recording and save your logs (in case you close IE or crash)

httpw.Stop
httpw.Log.Save('temp.hwl')

Let’s do some fact finding about the http sessions.

#How long did all of this take?
httpw.Log.Entries.Summary.Time

Careful: this is the Time it took from the start to the end of the session including all the waiting around and staring at the page, it’s not a true time in how long it took for all the traffic to arrive.

# How many pages did I visit?
httpw.Log.Pages.Count

#Were there any errors?
httpw.Log.Entries.Summary.Errors.Count

For more information just take a look at the API documentation.

The HttpWatch Basic Edition allows you to save as well as load a log file and examine the Entries. That’s very useful. I can log, stop and offload my hwl file for later review or quick audit.

Here is an example of how to create an instance of a log object by loading previously saved log file using Controller.

# load previously saves httpwatch log file
log = ct.OpenLog('temp.hwl')

NBw you can use standalone log object as if it was httpw.Log
I like this feature for gathering statistics on a previously saved test sessions.

That’s about it for the first look.(mindmap to come)

Designer and unintended consequences.

From UML Pattern Language by Paul Evitts quoting Donald Schon passage from The Reflective Practicioner

A designer makes things. Sometimes he makes the final product; more often, he makes a
representation, plan, program, or image of an artifact to be constructed by others. He
works in particular situations, uses particular materials, and employs a distinctive
medium and language. Typically, his making process is complex. There are more
variables—kinds of possible moves, norms, and interrelationships of these—than can be
represented in a finite model. Because of this complexity, the designer’s moves tend,
happily or unhappily, to produce consequences other than those intended. When this
happens, the designer may take account of the unintended changes be has made in the
situation by forming new appreciations and understandings and by making new moves.
He shapes the situation, in accordance with his initial appreciation of it, the situation
“talks back,” and he responds to the situation’s back-talk.
In a good process of design, this conversation with the situation is reflective. In answer to
the situation’s back-talk, the designer reflects-in-action on the construction of the
problem, the strategies of action, or the model of the phenomena, which have been
implicit in his moves.

Old tools rule. New tools only toys?

JP of confused of calcutta writes about visualization and patterns:

As we see information continue to disaggregate and atomise, and as we see its velocity increase, we are going to need better and better visualisation tools and techniques. While there has been much progress in visualisation over the last decade or so (…), for some reason this has not made its way into business life. We’re still stuck in a world of PowerPoint presentations of scorecards and dashboards and RAG indicators, fed by Excel spreadsheets and simple databases, and with considerable manual intervention. Considerable use of derived data. Considerable throwing away of useful information. Considerable scope for sins of omission and commission when interpreting the derived data.(…)

We have the ability to take the sensed information and move it around so much more quickly. And in this digital age, we have the ability to connect different sources of information more effectively, both by use of semantic tools as well as by heuristic learning methods.

Almost everytime I have to search in Lotus Notes email for something I keep wondering the same thing. Some say ‘Hyperlinks subvert hierarchy’ but Lotus Notes wins because…?
It makes me wonder if Agile Methodology’s emphasis on proximity, people sitting in the same room within an earshot, so barriers to communication are dealt with ’structurally’ and not ‘politically’ is perhaps a type of subversion rather than natural evolution. It seems there are so many barriers to communication in a modern business organization, one of them for example is the fact that in order to have a meeting you have to reserve a room in advance and if you want a projector you have to reserve that too and somebody from facilities office will show up and open a room for you and set up a projector. Infrastructre is not set up for communiction to occur where immediate feedback and self organizing can produce breakthrough conversations on a project. Communication in such infrastructure is all about manually planning the maybeness of some sort of kind of knowledge transfer that might happen, sort of.

What I am saying is that we waste enormous amounts of time and effort using tools that aren’t fit for purpose, and then somehow we manage to convince ourselves that all is well

Test Oracle Generators. How do you know a bug is a bug?

I stumbled upon Cem Kaner’s notes Examples of Test Oracles

An oracle is a mechanism for determining whether the program has passed or failed a test

A complete oracle would have three capabilities and would carry them out perfectly:

  • A generator, to provide predicted or expected results for each test.
  • A comparator, to compare predicted and obtained results.
  • An evaluator, to determine whether the comparison results are sufficiently close to be a pass.

The ‘generator’ seems to be the source of distinguishing ‘expectations’ and any deltas as defects. One time a manager on a project told us - ‘anything that makes us look bad is a bug’. I guess he was a ‘generator’ in that moment.

Whenever I analyze UseCases or requirements and everything looks ‘ok’ and mainly ‘right’ I usually add a section to my analysis called ‘Risks’ where I list all possible ‘issue’ that may come up as defects to anticipate future user’s interactions with a particular feature. Then in the future when I get a bug report from the ‘customers’ I can compare my Risks section to see if I have ‘predicted’ it for myself. I try to build a ’smell’ generator from those notes.

Argument against Waterfall

As I am reading Robert Martin’s old Engineering Notebooks on Iterative and Incremental Development I came across a business argument, perhaps the best non-engineering argument of which I have many; against following Waterfall software methodology. You are welcome to download all his PDF docs from ObjectMentor’s site via this googleq:

The iterative process is producing data about the schedule. The completion times of the slices are giving us unambiguous empirical measurements that help us predict when the project will be complete. There is a wonderful thing that mangers can do with these measurements – with this data managers can… manage. They can stop dictating, stop motivating, stop losing control Don’t let this article mislead you. If you follow the advice above and begin developing projects in an iterative and incremental way, bluebirds will not fill your sky. Schedules will still be missed, there will still be bugs, problems, and mis-aligned expectations. Software is, after all, software; and software is hard. However, what you will be doing is using a process that produces data; whereas waterfall produces none. With that data, managers can try to manage the project. (…)a process that produces data can be managed. A process that does not produce data, cannot be managed.

I dig this argument: producing data about the schedule. I can see why in Scrum you should be keeping track of past Sprints and why you should be looking at how many backlog items are “YET TO BE DONE” and not DONE VERSUS PLANNED as happens to be the model in Waterfall. I think this is an important distinction. - In traditional Waterfalll you Plan what will be done with the assumptions that no changes will occur - but what if you can produce data everyday about how many items are yet to be done? how many are planned? you can calculate your running conversion, hence burndown chart, hence velocity as a measure of effectiveness.

I don’t have much experience with Scrum since most of my work has been on Test Design in what I would call Waterfallish type of project, however I must admit that my engineering process for Testing software has been iterative. I devised plans that were based in uncertainty but I never tracked data about my schedule, partly because I never designed it nor have never been on teams that designed it. Since Test Management is about repeatablitlity let me make a strong recommendation to myself and my team now to implement such a measure.

Infrastructure for Sofware Production

How do you manage means of communication as infrastructure for production of software?
Is this an appropriate question to ask about Means of Production in Software Age?

In the context of Industrial Age Means of Production (MoP. Der Produktionsmittel) was described as:

“combination of the means of labor and the subject of labor used by workers to make products. Means of labor include machines, tools, plant and equipment, infrastructure, and so on: “all those things with the aid of which man [sic]
acts upon the subject of labor, and transforms it.”
The subject of labor includes raw materials and materials directly taken from nature. Means of production by themselves produce nothing — labor is needed for production to take place.”

In the context of Software Age; what is the subject of labor? what are the means of labor? what is the worker? what is transformed? what is raw material?

Means of labor - “all those things with the aid of which man acts upon the subject of labor and transforms it” - Transforms it into what? Usable Code, Working Software that produces values. OK, so what is subject of labor acted upon? Can lines of code be a raw material? But they were invented. Lines of Code don’t exist in the wild that you can fish for, hunt, dig for…

What is a capital asset identified as means of production?

more questions…