How to automate test cases which need to be run in a clean OS

July 11, 2011 by · 1 Comment
Filed under: automation, test 

Sometimes we need to automatically run some test cases which need to be run in an clean os. Such as application software installation benchmark. If you’d like to test performance of office installation under Microsoft Windows with different antivirus installed. The software installation is a test case, and it should be run in a clean OS.  Here’s the tools and steps. (works on Microsoft Windows XP).

4 Tools need to be prepared:

Grub4dos:  used to load dos image (modify default boot into OS in menu.lst).

Maxdos image (maxdos.img): which is extracted from max dos, and can be used to boot in to pure dos from grub4dos. Also you can use any other dos image which can boot into dos instead. (Images in vFloppy is recommended too)

Win Image: which we need to use for changing content in dos image file. We modify autoexec.bat in dos image to restore OS automatically and reboot.

Ghost: which we need to restore OS ghost image automatically.

5 Steps to automate test cases which need to be run in a clean restored OS:

1. Prepare a clean os, and make a ghost image (ghost\win.gho).

Before make the ghost image,  put your test script (such as start.script.bat) caller file to the  start-up menu in OS.  So that the script will be run automatically once upon reboot.

Make sure you windows system is in NTFS partition, and prepare a FAT32 partition, copy the ghost image win.gho to the FAT32 partition (ghost\win.gho) so that in pure dos we can read and restore the ghost image.

2. Modify c:\boot.ini to boot into grub (follow the readme of grub4dos to install grub on your system before this step).

[boot loader]
timeout=5
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect
c:\grldr=Grub

3. Edit grub boot configs to automatically boot into maxdos image

title restore by MAXDOS
find --set-root --ignore-floppies /boot/maxdos.IMG
map --mem /boot/maxdos.IMG (fd0)
map --hook
chainloader (fd0)+1
rootnoverify (fd0)

4. Maxdos boot into into DOS automatically.

5. In the dos imaged (maxdos.img), modify the autoexec.bat to restore ghost automatically. (You need first extract files from maxdos.img by Win Image, then modify the files, and put the files back to the img file):

ghost.exe -clone,mode=pload,src=c:\ghost\win.GHO:1,dst=1:1 -fx -sure -rb

Plus, if you need to run several different cases, each case need to be run in a clean environment. You can do it in your start.script.bat as the following link:

How to automate test cases need reboot: a simple script solution

Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

How to automatically install/uninstall software without human interaction

July 11, 2011 by · 1 Comment
Filed under: automation, test 

Sometimes we need to automatically install/uninstall software without human interaction, especially for system performance test. How can we make it work?

A simple and easy way is to leverage AutoIt. Auto it can be used to simulate keystrokes and mouse movements automatically. Just download it from here. Then install it.

And open an editor, SciteEditor4AutoIt3 is recommended as a bundle in AutoIt, write autoit script by examples provided by AutoIt help document. During the writing, you can use AutoIt Window Info which is installed with AutoItV3 to capture your software window information. You will need these window information in your scripts.

Here’s the script for automatically install iTunes 9.0:

; filename: install.itunes.au3,  automatic software install
run("iTunesSetup-9.0.2.25.exe")
WinWaitActive( "iTunes + QuickTime" )

; click next
ControlClick("iTunes + QuickTime", "", "[ID:6315]")
WinWaitActive( "iTunes + QuickTime" )

; accept license
ControlClick("iTunes + QuickTime", "", "[ID:6434]")
WinWaitActive( "iTunes + QuickTime" )

;; click next
ControlClick("iTunes + QuickTime", "", "[ID:6315]")
WinWaitActive( "iTunes + QuickTime" )

;;click install
ControlClick("iTunes + QuickTime", "&Install", "[ID:6348]")

;; wait the install successful UI:
While 1
	; find control (Yes button) whose Text is &Finish :
	$var = ControlGetText("iTunes + QuickTime", "", "[Text:&Finish]") 

    If $var == "&Finish" Then
		; tick not to open UI
		ControlClick("iTunes + QuickTime", "", "[ID:6414]")

		; send Alt + F to finish install
		Send("!F")

        ExitLoop
    EndIf

	Sleep(1000)
WEnd

Here’s the script for uninstall iTunes 9.0:

; automatic software install
run("iTunesSetup-9.0.2.25.exe")
WinWaitActive( "iTunes + QuickTime" )

; click remove
ControlClick("iTunes + QuickTime", "&Remove", "[ID:6484]")

; find "Yes" button until it show, and then send Alt + Y
While 1
	; find control (Yes button) whose ID is 6434 :
	$var = ControlGetText("iTunes + QuickTime", "", "[ID:6434]") 

    If $var == "&Yes" Then
		; send Alt + Y to confirm uninstall
		Send("!Y")

        ExitLoop
    EndIf

	Sleep(1000)
WEnd

; find "Finish" button until it show, and then send Alt + F
While 1
	; find control (Yes button) whose ID is 6434 :
	;$var = ControlGetText("iTunes + QuickTime", "", "[ID:6412]")
	$var = ControlGetText("iTunes + QuickTime", "", "[Text:&Finish]") 

    If $var == "&Finish" Then
		; send Alt + F to finish uninstall
		Send("!F")
		;ControlClick("iTunes + QuickTime", "&Finish", "[ID:6412]")

        ExitLoop
    EndIf

	Sleep(1000)
WEnd

sleep(500);

;WinWaitActive( "iTunes + QuickTime" ) ; commented by david, 2010/05/04
; click "No" to not reboot the os:
ControlClick("iTunes + QuickTime", "&No", "[ID:7]")

;MsgBox(4096, $count,"", 5);

The script for install Microsoft Office 2007:

; filename: install.office.au3 ,automatic software install
run("office2007\\setup.exe")

WinWaitActive( "Microsoft Office Professional 2007" )
Sleep(100)
;ControlClick("Microsoft Office Professional 2007", "", "[Text:Continue]")
Send("!c")

WinWaitActive( "Setup" )

ControlClick("Setup", "", "[Text:&No]")

WinWaitClose("Setup")

; Alt + a to accept the terms of this agreement:
Send("!a")
Sleep(100)

; click "continue" button:
Send("{ENTER}");

; Click "Install Now"
Send("!i")

Sleep(500)

;WinWaitClose( "Microsoft Office Professional 2007" )
;WinWaitActive( "Microsoft Office Professional 2007" )

While 1
	; Send Alt + C to "Close":
   Send("!c")

	; find control (Yes button) by Text :
	$text = WinExists ("Microsoft Office Professional 2007", "")

    If $text == 0 Then
	     ;; window not found
         ExitLoop
    EndIf

	Sleep(1000)
WEnd

 

The script for uninstall Microsoft Office 2007:

; automatic software uninstall
run("office2007\\setup.exe")

WinWaitActive( "Microsoft Office Professional 2007" )

; remove:
Send("!m")

; Send Enter to "continue" :
Send("{ENTER}");

; confirm the dialog of "Are you sure you want to remove Microsoft Office professional 2007?":
WinWaitActive( "Setup" )
ControlClick("Setup", "", "[Text:&Yes]")
WinWaitClose("Setup")

While 1
   ; try to Send Alt + C to "Close":
   Send("!c")
   Sleep(100)

	; find control (Yes button) by Text :
	$var = ControlGetText("Setup", "", "[Text:&No]") 

    If $var == "&No" Then
		 ;;WinWaitActive( "Setup" )
		 ControlClick("Setup", "", "[Text:&No]")
		 WinWaitClose("Setup")
         ExitLoop
    EndIf

	Sleep(500)
WEnd
Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

How to automate test cases need reboot: a simple script solution

July 1, 2011 by · Comments Off on How to automate test cases need reboot: a simple script solution
Filed under: automation, test 

During the first 2 years in my career as a tester, I learned that for a tester, everything should be automated if possible. 2 years later I beginning my programming life and found that automation is a must skill for programmers too. There is lots of interesting things on my testings experience, here’s one of them.

The background: Sometimes we need to run some test cases, and each case must be run in a newly booted environment. Or when case B is depended on case A which need reboot after run. And we want automation of the process. (IT software installation, Antivirus performance test, etc is some practice requirement like this).

A simple way to automate such test case is : write the test cases in scripts, define all the
test cases script file name in an array scriptlist,  then run the script files whose name
is defined in the elements of the array one by one.  We can define an index for which script
is to be running in the array.  And each time we run a script file, we save the index, lets
say idx to a file on local disk.

Assum you have 4 scripted test cases to run in order: A.pl, B.pl, C.pl, D.pl (the script
language doesn’t matter, you can choose whatever you love). and after running of each case, need a system reboot.

We can write a new script called reboot-test-manager.pl, and put it to the auto start. Then
run the script manually as a trigger for the starting of all these 4 cases. Then each one
will run and reboot, and continue to run the next one.

Here’s the 4 simple things should be contained in the reboot-test-manager.pl, I’ll
demonstrate it in perl on windows, for linux some command must the changed, you know).

1).Initialize the index(idx) value
If next-file-torun.txt exist, try to read idx value from next-file-torun.txt,  else set $idx  value to zero.

my $idx = 0;
my @scriptlist=  ("A.pl","B.pl","C.pl","D.pl");

2). Save the idx value to a local file called next-file-torun.txt
The idx value indicates the file whose name is equal to scriptlist[idx] will be run.
echo $idx >next-file-torun.txt

3). Run the file indicated by scriptlist[idx] , and then increase idx by 1

my $filetorun = $scriptlist[$idx];
system("$filetorun");
$idx=$idx+1;

4). Reboot by restart command

system("shutdown -r -t 01");

Then script A.pl will be run, then reboot, then script B.pl will be run, then reboot and C.pl
….

This method is really useful on automation lots of software installation for IT if the
software need reboot. Also useful when we need to test some software performance  on a newly booted system, especially for antivirus performance test.

Here’s a sample script for running:

# The script would be run after system reboot

my @filelist =  ("install.a.pl","install.b.pl","install.c.pl");

##
my $idfile="next-file-torun.txt";
open READIN,"< $idfile" or die "can not open file:$!";
my $id = <READIN>;
close (READIN);
print "id=$id \n";

if($id>$#filelist)
{
	print "all files has been run!\n";
	print "\x07\x07"; # ring the bell
	exit(-1);
}

# sleep some seconds to run the following scripts:
print "sleeping...\n ";
sleep(10);

my $filetorun = $filelist[$id];
print "to run file:  $filetorun \n";

$id=$id+1;
open OUT,"> $idfile" or die "can not open file:$!";
print OUT $id;
close (OUT);

system("$filetorun");  ### call the script
system("shutdown -r -t 01"); ### reboot the system
Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)