Designing Tests

Documentation

 

In BlueDuck SDA tests scripts are composed of statements coded in the AutoIt v3.

Before you begin creating a test, ensure that your System Under Test and BlueDuck SDA are set to match the needs of your test.

In order to create and run the tests in there are a few things we need to download and install:

  • Download Selenium RC
  • Download and install Java which is required for running Selenium
  • In order to run Selenium tests we need to run Selenium Server which is shipped with Selenium RC. Since it’s a Java program we run it by typing java –jar selenium-server.jar in a console window.

Simple Test without object repository

Designing Tests

 

Purpose: to demonstrate the following SDA functionality:

  • select Objects from repository
  • entering text into a text field
  • clicking a button
  • checking to see if a page contains text.

Including SDA Core

#include <../../lib/sda.core.au3>
						

Get a new Test object instance

Func SimpleTest()
	Local $oTest,$oRepo,$Page
	
	;New Test object
	$oTest = NewTest("Simple Test")
	;Start Test
	$oTest.Setup()
						

Starting a new Test report and new browser

;New Browser
$oTest.NewBrowser('firefox','http://es.altavista.com/')
$oTest.Browser.start
						

and going to our site

_open("http://es.altavista.com/'")
_windowMaximize()
_type("//*[@id='yschsp']","BlueDuck SDA")
_click("//*[@id='yschbt']")
_waitForPageToLoad("3000")
						

Use checkpoints to verify your results

						
If _isTextPresent("AutoIt driver for Selenium ") = 1 Then
	$oTest.AddStepResult("Step 1","Search",1)
Else
	$oTest.AddStepResult("Step 2","Search",0)
EndIf
						

Close Test and Browser

	$oTest.Report.Close
	$oTest.Browser.stop
EndFunc						
						

Simple Test with object repository

Designing Tests

 

Purpose: to demonstrate the following SDA functionality:

  • select Objects from repository
  • entering text into a text field
  • clicking a button
  • checking to see if a page contains text.

Including SDA Core

#include <../../lib/sda.core.au3>
						

Get a new Test object instance

Func SimpleTest()
	Local $oTest,$oRepo,$Page
	
	;New Test object
	$oTest = NewTest("Simple Test")
	;Start Test
	$oTest.Setup()
						

Starting a new Test report and new browser

;New Browser
$oTest.NewBrowser('firefox','http://es.altavista.com/')
$oTest.Browser.start
						

Get Object repository

														
$oRepo = $oTest.SetRepository("AltaVistaRepo")						
						

and going to our site

;Search in Altavista
$Page = $oRepo.WebPage("Page.AltaVista")
$Page.open("/")
$Page.windowMaximize
$Page.input.item("search").type("BlueDuck SDA")
$Page.button.item("search").click
						

Use checkpoints to verify your results

						
If $Page.WaitForText("Try Blueduck SDA") = 1 Then
	$oTest.AddStepResult("Step 1","Search",1)
Else
	$oTest.AddStepResult("Step 2","Search",0)
EndIf
						

Close Test and Browser

	$oTest.Report.Close
	$oTest.Browser.stop
EndFunc						
						

Running

SimpleTest()						
						


Running Test


It is possible to take your Test script and compile it into a standalone executable; this executable can be used without the need for AutoIt to be installed and without the need to have AutoIt3.exe on the machine. In addition, the compiled script is compressed and encrypted and there is the option to bind additional files (also compressed/encrypted) to the exe using the FileInstall function. Also, any #include files will also be compiled into the script so they are not required at run-time.

Aut2Exe can be used in three ways:

  • Method 1 - Start Menu

    • Open the Start Menu and browse to the AutoIt v3 group./li>
    • Click Script Compiler \ Convert .au3 to .exe
    • The main Aut2Exe interface should appear.

    • Use the Browse buttons to select your input (.au3) and output (.exe) files.
    • If you like you can change the icon of the resulting .exe - just browse to the icon you want (some example icons are supplied in Program Files\AutoIt3\Aut2Exe\Icons).
    • The only other option you might wish to change is the compression level (especially if using FileInstall to add extra files). Use the Compression menu to set this. As with all compression routines the better the compression you select the slower it will be. However, no matter what compression level you select the decompression speed (when the .exe is run) is the same.
    • Click on Convert to compile the script.

  • Method 2 - Right Click
    • In Explorer browse to the Test file that you wish to compile
    • Right-click the file to access the pop-up menu.


    • The file will be silently compiled with the same filename - just with a .exe extension.
      When compiling in this way, Aut2Exe uses current icon/compression settings (from the last time Aut2Exe was run manually as in method 1).

  • Method 3 - The Command Line

    The Aut2Exe.exe program can be run from the command line as follows:
    Aut2exe.exe /in (infile.au3) [/out (outfile.exe)] [/icon (iconfile.ico)] [/comp 0-4] [/nopack] [x64] [/bin (binfile.bin)]

Analyzing Run Results

Designing Tests

 

The Result Reports displays the detailed result log of actions performed on a System Under Test (SUT) on each script run.

The Test Results reports contains two sections:

  • Summary section
  • Test Detail section

Add Step Results

Designing Tests

 

You can use the AddStepResult method to determine which steps or types of steps are included in the Test Results.

	
	$TestOne.AddStepResult("Step Name","Step Name",Result (integer))

Result codes

  • 0 Failed - Causes this step to pass.
  • 1 Passed - Causes this step (and therefore the test itself) to fail.
  • 2 Warning - Sends a message to the report without affecting the pass/fail status of the step.
  • 3 Done - Sends a warning status for the step, but does not cause the test to stop running, and does not affect its pass/fail status.

Browsers Manage

Designing Tests

 

New Browser object (via Test object)

	
	;New Test object
	$oTest = NewTest("Simple Test")
	
	;New Browser object (via Test object)
	$oTest.NewBrowser('firefox','http://es.altavista.com/')
	$oTest.Browser.start
	$oTest.Browser.stop

Get Browser object (direct instance)

	
	;New Browser object (direct instance)
	$oBrowser = NewWebBrowser('firefox','http://es.altavista.com/')
	$oBrowser.start
	$oBrowser.stop

Selenium supported browsers include:

  • firefox
  • mock
  • firefoxproxy
  • pifirefox
  • chrome
  • iexploreproxy
  • iexplore
  • firefox3
  • safariproxy
  • googlechrome
  • konqueror
  • firefox2
  • safari
  • piiexplore
  • firefoxchrome
  • opera
  • iehta
  • custom

Browser Object

Designing Tests

 
Method Description Parameters
constructor
  • New_browser - String [optional] "firefoxproxy" for default
  • New_host - String [optional] "locahost" for default
  • New_port - String [optional] "4444" for default
  • New_timeout - String [optional] "3000" for default (in ms)
Start Run the browser and set session id.
Stop Close the browser and set session id null.

Execute custom function

Designing Tests

 

You can execute a custom function in Setup and Teardown method.

Example:

	
;Execute a custom setup function with parameters
$oTest = NewTest("Simple Test")

Local $sPar[2]
$sPar[0] = "CallArgArray"
$sPar[1] = "Test"
$oTest.Setup("_Test",$sPar)																
						

Assertion Method

Designing Tests

 

Key part of writing Fully Automated Tests is to make them Self-Checking Tests to avoid having to inspect the outcome of each test for correctness each time it is run. This involves finding a way to express the expected outcome in a way that can be verified automatically by the test itself. Assertion Methods give us a way to express the expected outcome.

Method Description
_assertEquals Asserts that two variables are equal.
_assertNotEquals Asserts that two variables not are equal.
_assertFalse Asserts that a condition is false.
_assertTrue Asserts that a condition is True.
_assertType Asserts that a variable is of a given type.
_assertLessThan Return a browser object
_assertLessThanOrEqual Asserts that a value is smaller than or equal to another value.
_assertGreaterThanOrEqual
_assertGreaterThan Asserts that a value is greater than another value.
_assertFileExists Asserts that a file exists.
_assertFileEquals Asserts that the contents of one file is equal to the contents of another file.

Screen Capture

Designing Tests

 

When something goes wrong you often need a way to capture the problem. The simplest and fastest way to do this is to take a screen shot of the browser window.

You can enable or disable screen capture in Test case.

Example:

;New Test
$Test = NewTest("TestScreenCapture")
;Start Test
$Test.Setup

;Screen Capture config. (True for default)
$Test.ScreenCapture = False

Record screen

Designing Tests

 

BlueDuck SDA can record test results using screen recorder into standard AVI movie files.

Example:

;New Test
$Test = NewTest("VideoTest")
;Start Test
$Test.Setup

;Test Report
$Test.Report.Create
$Test.Report.VideoRecord =  True
$Test.Report.RecordScreenMode =  "native"
$Test.Report.RecordScreenMode =  "camstudio"

BlueDuck has two video record mode:

  • Native
    Uses a native record mode called BlueDuckRec.exe
  • CamStudio
    Uses a record mode called camstudio_cl.exe. Camstudio is an Open source app for video recording

Test Results. Change format

Designing Tests

 

BlueDuck SDA can generate reports inHTML,TXT,PDF and DOC.

Example:

;New Test
$Test = NewTest("TestReportFormat")
;Start Test
$Test.Setup

;Test Report
$Test.Report.Create
$Test.Report.Format =  "HTML"
$Test.Report.Format =  "TXT"
$Test.Report.Format =  "PDF"
$Test.Report.Format =  "DOC"

Test Object

Designing Tests

 
Method Description
Setup BlueDuck SDA supports sharing the setup code. Before a test method is run, a template method called Setup is invoked. Setup is where you create the objects against which you will test.
Teardown Once the test method has finished running, whether it succeeded or failed, another template method called Teardown is invoked. Teardown is where you clean up the objects against which you tested.
NewDataProvider Return a Data Provider object
SetRepository Return a Repository object
NewDataGenerator Return a Data Generator object
NewBrowser Return a browser object
AddStepResult You can use the AddStepResult method to determine which steps or types of steps are included in the Test Results.
RemoveSteps
GetLastStep Return an Arry with last Test Step
CountSteps
GetScreenCapture

Feel free to contribute! Send your example