10
Automated Web Testing Command-Line & Scripting Interface

Web Browser Scripting

Embed Size (px)

DESCRIPTION

The Scripting Interface of the iMacros Scripting Edition is designed as COM object and allows the user to remote control (script) the iMacros Browser, Internet Explorer and Firefox web browser from any Windows programming or scripting language.

Citation preview

Page 1: Web Browser Scripting

Automated Web Testing

Command-Line &Scripting Interface

Page 2: Web Browser Scripting

Command Line Interface

Typical uses:

Use macro with batch file Integrate with Windows task scheduler Integrate with thousands of other software packages

Commands:

Start the macro: -macro <macroname> Send values to macro: -var_myvar <x> Repeat macro: -loop <x> Keep IM Browser open: -noexit Run in background: -tray / -silent Example: –macro test –var_myvar Hello[SP]World

Page 3: Web Browser Scripting

Command Line Interface (cont’d)

Take values from the command line:

CMDLINE !VAR1 http://www.iOpus.com/iim

Check on the return value:

The Internet Macros executable "imacros.exe" set the predefined batch file variable "%ERRORLEVEL%".

The value is either 1 if the macro was completed successfully or negative if an error was encountered.

Page 4: Web Browser Scripting

Example Batch File

"C:\IIM\imacros.exe" -macro Demo-FillForm -loop 3

if %errorlevel% == 1 goto ok

if NOT %errorlevel% == 1 goto error

:ok

echo Macro completed succesfully!

goto end

:error

echo Error encountered during replay.

echo Errorcode=%errorlevel%

:end

The batch variable %errorlevel% is set by "imacros.exe" upon exit

Page 5: Web Browser Scripting

Demo Project

Set up a test macro that runs once a day and saves the CNN.com home page to a file:

The task scheduler can be accessed via the Windows Control Panel

Page 6: Web Browser Scripting

Scripting Interface

Why use the Scripting Interface?

Works with any Windows Scripting or programming language

Simple but powerful set of commands

Detailed error handling

Windows OS includes Windows Scripting Host (WSH)

Easy database access

Page 7: Web Browser Scripting

The six most important commands:

set iim1= CreateObject (“iMacros")

i = iim1.iimInit (“”)

i = iim1.iimDisplay("This is a test")

i = iim1.iimSet("-var_name1", "Tom Tester")

i = iim1.iimPlay(“Test1")

If i > 0 Then s = "Everything OK”

Else s = iim1.iimGetLastError()

MsgBox s

i = iim1.iimExit

Page 8: Web Browser Scripting

Error Return Codes

All functions return a value > 0 if they succeed, and an error code < 0 in case of problems.

Error codes below -100 are error codes generated during the macro replay. Same code as when macro is run manually.

-1 Macro timeout (Macro takes too long to run)-2 IIM Interface timeout (IM browser does not respond)-3 User pressed STOP button-4 Communication error (should not happen)-5 Browser closed (User pressed EXIT button)

Page 9: Web Browser Scripting

VB6 with Intellisense Support

In order to enable Intellisense support, you need to add the „IInternetMacros“ component to your project („Early binding“). The alternative is to use CreateObject („Late Binding“, no Intellisense support)

Intellisense in action…Add iMacros COM object

Page 10: Web Browser Scripting

Demo Projects

Performance Monitoring

Create response time measurement macro, and return the data to your script for further processing. Use {{!STOPWATCHTIME}} to return the measured time.

Use a script to alert you when response time is above threshold

Create Google News Extractor:

Submit keyword search to Google News Extract headlines from returned search results Store headlines in text file Click NEXT link until all results are extracted