Tuesday, November 19, 2013

Quick Switching Between Demo Configurations

I’ve got a couple demos where I have to do some quick code changes, rebuild a project, then get a browser opened up to show changes on the UI. The point of this is to help folks understand how to avoid tests breaking when the sort order changes, or columns move around on the UI.

Before:

image

After:

image

Making my audience sit through the code changes is a waste of time—the code changes simply update sort and column order. My talk is on how to write good tests to deal with these situations, not show the code causing the changes.

Instead, I wired together a couple things to give me a hotkey that fires off the changes, builds the system, and launches a browser to the right page. First off is a Ruby script to copy files, build the project, and use Watir to launch the page:

require 'watir'
require 'optparse'
require 'fileutils'
 
 
def copy_start_files
    FileUtils.rm %w(Default.aspx Contacts.cs), :force => true
    FileUtils.cp("Contacts-Start.cs", "Contacts.cs")
    FileUtils.cp("Default-Start.aspx", "Default.aspx")
end
 
def copy_end_files
    FileUtils.rm %w(Default.aspx Contacts.cs), :force => true
    FileUtils.cp( "Contacts-End.cs", "Contacts.cs")
    FileUtils.cp( "Default-End.aspx", "Default.aspx")
end
 
def build_it
    system("C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild.exe RadControlsExamples.csproj")
end
 
def parse_opts
    $options = {}
    opts = OptionParser.new
    opts.banner = "Usage: ChangeSite [options]"
 
    opts.on("-s", "--start", "Set site to START") do
        $options[:start] = true
    end
 
    opts.on("-e", "--end", "Set site to END") do
        $options[:end] = true
    end
 
    opts.on("-h", "--help", "Display this screen") do
        puts opts
        exit
    end
 
    opts.parse(ARGV)    
    
    if ($options[:start].nil? && $options[:end].nil?)
        puts "Missing options"
        puts opts
        exit
    end
end
 
def launch_site
    $browser = Watir::Browser.start "http://localhost/WorkingWithLocators"
end
 
def do_the_work
    if $options[:start]
        copy_start_files()
    end
 
    if $options[:end]
        copy_end_files()
    end
 
    build_it()
    launch_site()
end
 
parse_opts()
do_the_work()

No, this isn’t the most awesomesaucest Ruby ever, but it works. I’ll clean it up when I need to.

The next step is to wire this up in your favorite hotkey/launcher. I use SlickRun because it’s awesome.

image

Now I can use SlickRun to launch my Ruby script. I can continue engaging the audience while the system updates, builds, and a browser shows up with the new content.

There are many ways to solve this particular problem. The steps above are how I chose to do it this time. Hopefully it’s useful to you!

Subscribe (RSS)

The Leadership Journey