<?sphp $this->text('pagetitle') ?>
 
Home of the Squeezebox™ & Transporter® network music players.

SqueezePlay Macros

From SqueezeboxWiki

Revision as of 12:23, 12 May 2008 by Bklaas (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

SqueezePlay Macros can be used for automated testing, and are used for the SqueezeOS Smoke Tests. The macros simulate user input, for example key presses, scrolling and motion events. Screenshots are used to verify the actions that the macros make.

Running Macros

You can find macros in the Extras > Text macros menu. From this menu it's possible to run a single macro, or a set of automated tests. The automated tests are used for the SqueezeOS Smoke Tests, and the test sequence continues to run even when the Controller reboots (for example as part of a Factory Reset test). The success or failure of the automated tests is indicated graphically in the menu.

Writing a new Macro

To add a macro first the Macro needs defining in the Macros.lua file, a simple file follows with comments.

return {
  -- auto start is the list of macros for the automated testing
  autostart={ "playmode" },
  -- auto is the index of the next macro to run for the automated testing
  auto=1,
  -- macros defines the macros in the system, add to this list when creating new macros
  macros={
    playmode={
      desc="Playmode tests (stop/pause/play).",
      file="PlaymodeMacro.lua",
      name="Playmode" 
    },
  } 
}

Each macro must be defined with a name, description and the macro file itself. The Playmode macro tests that the stop, play and pause functions in SqueezePlay work correctly. This PlaymodeMacro.lua file contains:

-- go home
macroHome(500)

-- select Now Playing
if not macroSelectMenuItem(100, "Now Playing") then
	return macroFail("Now Playing")
end

-- key go into Now Playing
macroEvent(1000, EVENT_KEY_PRESS, KEY_GO)

-- stop (hold pause), wait until after show briefly
macroEvent(5000, EVENT_KEY_HOLD, KEY_PAUSE)
if not macroScreenshot(1000, "PlaymodeStop") then
	 return macroFail("Playmode Stop")
end

-- play, wait until after show briefly
macroEvent(5000, EVENT_KEY_PRESS, KEY_PLAY)
if not macroScreenshot(1000, "PlaymodePlay") then
	return macroFail("Playmode Play")
end

-- pause, wait until after show briefly
macroEvent(5000, EVENT_KEY_PRESS, KEY_PAUSE)
if not macroScreenshot(1000, "PlaymodePause") then
	return macroFail("Playmode Pause")
end

macroPass("Playmode")

A number of macro functions can be used by the macros to simulate user input, capture screenshots and test results. The macro functions are:

macroDelay(interval)
the macroDelay function will delay for interval ms.
macroEvent(interval, ...)
the macroEvent function will create and dispatch a new SqueezePlay Event object, then delay for "interval" ms. Any event type can be send, including key presses, key holds, motion, etc.
macroSelectMenuIndex(interval, index)
the macroSelectMenuIndex function will select the menu item with the given index, then delay for interval ms. The index is selected using Key Down or Key Up events.
macroSelectMenuItem(interval, pattern)
the macroSelectMenuItem function will select the menu item where the text matches the lua regex pattern, then delay for interval ms. The menu is navigated using Key Down and Key Up events.
macroIsMenuItem(pattern)
the macroIsMenuItem function returns true if the selected menu item has text that matches the lua regex pattern.
macroTextInput(interval, text)
the macroTextInput function enters the text using Key Up, Key Down and Key Right events in a TextInput widget, then delays for interval ms.
macroHome(interval)
returns to the home menu, then delays for interval ms.
macroScreenshot(interval, file, limit)
captures or compares the screenshot in file, then delays for interval ms. When comparing the screenshot limit specifies what percentage pixel accuracy is required, this default to 100% or an exact match. Any areas of the reference screenshot colored in pink are ignored, see the examples below.
macroParameter(key)
returns a parameter value from the Macros.lua file for this macro.
macroPass(msg)
logs that this macro has passed, entering msg in the system log.
macroFail(msg)
logs that this macro has failed, entering msg in the system log.

Reference Screenshots

<to do add screenshots>