Firebug Automated Test API

From FirebugWiki

(Difference between revisions)
Jump to: navigation, search
m (Added "See also" section)
(Linked to other pages in the wiki; corrected spelling)
Line 1: Line 1:
== FBTest Object ==
== FBTest Object ==
-
A test, specifically the test driver part, usually use APIs that are provided by the FBTest framework. The test driver uses them to communicate back to the framework and automate Browser and Firebug UI. All APIs are accessible via FBTest object that is automatically defined as a global variable within a test driver scope. Let's see what methods are available
+
A test, specifically the test driver part, usually use APIs that are provided by the [[FBTest]] framework. The test driver uses them to communicate back to the framework and automate Browser and Firebug UI. All APIs are accessible via FBTest object that is automatically defined as a global variable within a test driver scope. Let's see what methods are available:
-
 
+
* <code>ok(pass, msg)</code> - generates a test report into the test console. If the first parameter is true the report is considered as passing, otherwise failing. If all reports from a test case pass, the entire test case is considered as passing, otherwise failing.
* <code>ok(pass, msg)</code> - generates a test report into the test console. If the first parameter is true the report is considered as passing, otherwise failing. If all reports from a test case pass, the entire test case is considered as passing, otherwise failing.
Line 87: Line 86:
=== Preferences ===
=== Preferences ===
-
Helpers for Firebug preferences. Notice that prefName must be specified without Firebug's preference domain. See example below.
+
Helpers for [[Firebug Preferences]]. Notice that prefName must be specified without Firebug's preference domain. See example below.
* <code>setPref(prefName, value)</code>
* <code>setPref(prefName, value)</code>
Line 102: Line 101:
=== Firefox ===
=== Firefox ===
-
* <code>openNewTab(url, callback)</code> - opens a new Firefox tab with specified URL. As soon as the page is loaded provied callback is executed.
+
* <code>openNewTab(url, callback)</code> - opens a new Firefox tab with the specified URL. As soon as the page is loaded provied callback is executed.
* <code>openURL(url, callback)</code> - opens a specified URL on the current Firefox page.
* <code>openURL(url, callback)</code> - opens a specified URL on the current Firefox page.
Line 108: Line 107:
* <code>reload(callback)</code> - reloads the current Firefox page.
* <code>reload(callback)</code> - reloads the current Firefox page.
-
* <code>cleanUpTestTabs()</code> - closes all Firefox tab that have been opened as part of the testing process.
+
* <code>cleanUpTestTabs()</code> - closes all Firefox tabs, that have been opened as part of the testing process.
=== DOM ===
=== DOM ===
-
* <code>expandElements(parentNode, className [, className, ...])</code> - sends a click event to all child elements that uses specified class(s). This is useful mainly for expanding various panel contents.
+
* <code>expandElements(parentNode, className [, className, ...])</code> - sends a click event to all child elements, that use the specified class(s). This is useful mainly for expanding various panel contents.
-
 
+
<pre>
<pre>
Line 120: Line 118:
</pre>
</pre>
-
Expands all XHR requests within the Net panel (sends click event to all elements that have both netRow and category-xhr classes).
+
Expands all XHR requests within the [[Net Panel]] (sends click event to all elements that have both ''netRow'' and ''category-xhr'' classes).
=== Debugger ===
=== Debugger ===
-
* <code>clickContinueButton()</code> - simulates click on a Continue debugger button (F8)
+
* <code>clickContinueButton()</code> - simulates click on the [[Script Panel#Execution Control Buttons|Continue debugger button (F8)]]
-
=== Miscelanous ===
+
=== Miscellaneous ===
* <code>testDone(msg)</code> - finishes a Firebug related test. This methods also closes Firebug UI, all test tabs and uses specified message as a progress mesasage in the Test console status bar.
* <code>testDone(msg)</code> - finishes a Firebug related test. This methods also closes Firebug UI, all test tabs and uses specified message as a progress mesasage in the Test console status bar.
Line 133: Line 131:
== See Also ==
== See Also ==
-
 
+
* [[Running Automated Test Suite]]
-
[[Running Automated Test Suite]]
+
* [[Firebug Automated Test Examples]]
-
[[Firebug Automated Test Examples]]
+

Revision as of 06:04, 4 May 2011

Contents

FBTest Object

A test, specifically the test driver part, usually use APIs that are provided by the FBTest framework. The test driver uses them to communicate back to the framework and automate Browser and Firebug UI. All APIs are accessible via FBTest object that is automatically defined as a global variable within a test driver scope. Let's see what methods are available:

  • ok(pass, msg) - generates a test report into the test console. If the first parameter is true the report is considered as passing, otherwise failing. If all reports from a test case pass, the entire test case is considered as passing, otherwise failing.
  • compare(expected, actual, msg) - also generates a test report. If the expected string equals to actual, the report is considered as passing.
  • sysout(text, obj) - prints an informative log into Firebug's tracing console. You need to have TESTCASE option selected.
  • testDone() - this method must be called at the end of each test. This informs the framework that a test has been finished.
  • progress(msg) - prints an informative message into the Test console status bar.
  • click(node) - fires a click event on specified DOM node.
  • focus(node) - focuses specified DOM node. Either using a focus method or firing a DOMFocusIn event on the node.
  • mouseDown(node) - fires a mousedown event on specified DOM node.
  • loadScript(scriptURI, scope) - loads additional script file.
  • getLocalURLBase() - returns local path of the home server directory (e.g. C:\firebug\tests\content\)
  • exception(message, err) - generates an exception report into the test console. This report is always marked as failing.


Example of exception logging

function runTest()
{
    FBTest.sysout("exampleTest.started");
    try
    {
        hello.world(); // EXCEPTION
    }
    catch (err)
    {
        FBTest.exception("Test: ", err);
    }
    finally
    {
        FBTest.testDone();
    }
}


Firebug UI

  • openFirebug() - opens Firebug UI as a bar at the bottom of the Firefox Window (reffered as the Firebug Window).
  • closeFirebug() - closes Firebug UI.
  • pressToggleFirebug(forceOpen) - toggles (open/close) Firebug UI.
  • detachFirebug() - detaches Firebug from the Firebug Window.
  • isFirebugOpen() - returns true if Firebug is currently opened.
  • closeFirebugOnAllTabs() - closes Firebug UI on all tabs.


Firebug Activation

Helpers for panel acivation (enablement)

  • enableNetPanel(callback)
  • disableNetPanel(callback)
  • enableScriptPanel(callback)
  • disableScriptPanel(callback)
  • enableConsolePanel(callback)
  • disableConsolePanel(callback)
  • disableAllPanels()
  • enableAllPanels()


Panels

  • selectPanel(panelName) - selects specific panel within Firebug UI.
  • getSelectedPanel() - returns an object that represents currently selected panel.
  • getPanel(panelName) - returns an object that represents specified panel ("console", "script, "net", etc.).
  • selectPanelLocationByName(panel, name)
  • selectSourceLine(url, lineNumber, category)


Preferences

Helpers for Firebug Preferences. Notice that prefName must be specified without Firebug's preference domain. See example below.

  • setPref(prefName, value)
  • getPref(prefName)


var value = FBTest.getPref("showXMLHttpRequests");
FBTest.setPref("showXMLHttpRequests", true);

In this case extensions.firebug.showXMLHttpRequests preference is used.


Firefox

  • openNewTab(url, callback) - opens a new Firefox tab with the specified URL. As soon as the page is loaded provied callback is executed.
  • openURL(url, callback) - opens a specified URL on the current Firefox page.
  • reload(callback) - reloads the current Firefox page.
  • cleanUpTestTabs() - closes all Firefox tabs, that have been opened as part of the testing process.


DOM

  • expandElements(parentNode, className [, className, ...]) - sends a click event to all child elements, that use the specified class(s). This is useful mainly for expanding various panel contents.
var panel = FW.FirebugChrome.selectPanel("net").panelNode;
FBTest.expandElements(panelNode, "netRow", "category-xhr");

Expands all XHR requests within the Net Panel (sends click event to all elements that have both netRow and category-xhr classes).


Debugger


Miscellaneous

  • testDone(msg) - finishes a Firebug related test. This methods also closes Firebug UI, all test tabs and uses specified message as a progress mesasage in the Test console status bar.
  • clearCache() - clear Firefox cache.

See Also

Personal tools