Example: Basic Test

Source Code

exampleNet1.html

functionrunTest(){// A message displayed within Firebug tracing console.FBTest.sysout("exampleTest.START");// A message displayed under the test within Firebug test console.FBTest.progress("This is a progress message");// VerificationFBTest.ok(true,"This is a positive verification");FBTest.ok(false,"This is a negative verification");// VerificationFBTest.compare("Expected","Expected","Compare test (positive)");FBTest.compare("Expected","Actual","Compare test (negative)");FBTest.testDone("exampleTest.DONE");}

Notes

runTest is the test entry point. It's automatically called by Firebug test harness framework). This is where the test starts and it must be part of every test.

Example: Network request in the Net Panel

This test is intended to verify that a network request is properly displayed in the Net Panel. The test is composed from three files:

Notes

FBTest.waitForBreakInDebugger() waits till the script execution halts in the debugger.

FBTest.clickContinueButton() clicks on the Resume button to resume debugger's state.

Additional code that verifies some other aspects of the Firebug state can be within the callback.

FBTest.waitForBreakInDebugger(chrome, lineNo, breakpoint, callback)chrome Current Firebug's chrome object.lineNo Expected source line number where the break should happen.breakpoint Set to true if the break should happen on a breakpoint.callback Handler that is called when break happens.

Example: Firebug Library API Test

This example is intended to show how to create a test for a library functions. In this example only a test driver is implemented.

Notes

FBTest.enableConsolePanel() This method enables the Console Panel, reloads the page and as soon as the page is loaded it executes the callback function.

FBTest.waitForDisplayedElement Waits till a div element with classes logRow and logRow-log is created within the Console panel. The proper element is passed into the callback function as row parameter.

Example: Asynchronous tasks within a test

This example shows how to create a test that is composed from a set of asynchronous tasks.
The test is implemented as test-driver only:

Example: Command Line

Source Code

exampleCommandLine1.html
The only goal of the test page is to provide a description for manual verification of the test. See the SVN for more details.

exampleCommandLine1.js

functionrunTest(){FBTest.sysout("examples.commandline.START");FBTest.openNewTab(basePath+"examples/exampleCommandLine1.html",function(win){FBTest.openFirebug();FBTest.enableConsolePanel(function(win){varconfig={tagName:"span",classes:"objectBox objectBox-number"};FBTest.waitForDisplayedElement("console",config,function(row){FBTest.compare("3",row.textContent,"Number 3 must be displayed");FBTest.testDone("examples.commandline.DONE");});FBTest.executeCommand("1+2");});});}

Notes

FBTest.executeCommand() The most important method of this test. This one executes provided expression in the Command Line.

FBTest.waitForDisplayedElement This method waits till the result of the expression (evaluated on the Command Line) is displayed in the Console Panel. In this test it should be: 3.

In case of a test that executes more than one expression, it's effective to utilize FBTest.TaskList(). As an example see commandLine/dom.js test-driver.