browser_documentation.html.svn-base

来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 448 行 · 第 1/2 页

SVN-BASE
448
字号
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>SimpleTest documentation for the scriptable web browser component</title><link rel="stylesheet" type="text/css" href="docs.css" title="Styles"></head><body><div class="menu_back"><div class="menu"><a href="index.html">SimpleTest</a>                |                <a href="overview.html">Overview</a>                |                <a href="unit_test_documentation.html">Unit tester</a>                |                <a href="group_test_documentation.html">Group tests</a>                |                <a href="mock_objects_documentation.html">Mock objects</a>                |                <a href="partial_mocks_documentation.html">Partial mocks</a>                |                <a href="reporter_documentation.html">Reporting</a>                |                <a href="expectation_documentation.html">Expectations</a>                |                <a href="web_tester_documentation.html">Web tester</a>                |                <a href="form_testing_documentation.html">Testing forms</a>                |                <a href="authentication_documentation.html">Authentication</a>                |                <span class="chosen">Scriptable browser</span></div></div><h1>PHP Scriptable Web Browser</h1>        This page...        <ul><li>            Using the bundled <a href="#scripting">web browser in scripts</a>        </li><li>            <a href="#debug">Debugging</a> failed pages        </li><li>            Complex <a href="#unit">tests with multiple web browsers</a>        </li></ul><div class="content">                    <p>                SimpleTest's web browser component can be used not just                outside of the <span class="new_code">WebTestCase</span> class, but also                independently of the SimpleTest framework itself.            </p>                <p><a class="target" name="scripting"><h2>The Scriptable Browser</h2></a></p>            <p>                You can use the web browser in PHP scripts to confirm                services are up and running, or to extract information                from them at a regular basis.                For example, here is a small script to extract the current number of                open PHP 5 bugs from the <a href="http://www.php.net/">PHP web site</a>...<pre><strong>&lt;?phprequire_once('simpletest/browser.php');    $browser = &amp;new SimpleBrowser();$browser-&gt;get('http://php.net/');$browser-&gt;click('reporting bugs');$browser-&gt;click('statistics');$page = $browser-&gt;click('PHP 5 bugs only');preg_match('/status=Open.*?by=Any.*?(\d+)&lt;\/a&gt;/', $page, $matches);print $matches[1];?&gt;</strong></pre>                There are simpler methods to do this particular example in PHP                of course.                For example you can just use the PHP <span class="new_code">file()</span>                command against what here is a pretty fixed page.                However, using the web browser for scripts allows authentication,                correct handling of cookies, automatic loading of frames, redirects,                form submission and the ability to examine the page headers.                Such methods are fragile against a site that is constantly                evolving and you would want a more direct way of accessing                data in a permanent set up, but for simple tasks this can provide                a very rapid solution.            </p>            <p>                All of the navigation methods used in the                <a href="web_tester_documentation.html">WebTestCase</a>                are present in the <span class="new_code">SimpleBrowser</span> class, but                the assertions are replaced with simpler accessors.                Here is a full list of the page navigation methods...                <table><tbody>                    <tr><td><span class="new_code">addHeader($header)</span></td><td>Adds a header to every fetch</td></tr>                    <tr><td><span class="new_code">useProxy($proxy, $username, $password)</span></td><td>Use this proxy from now on</td></tr>                    <tr><td><span class="new_code">head($url, $parameters)</span></td><td>Perform a HEAD request</td></tr>                    <tr><td><span class="new_code">get($url, $parameters)</span></td><td>Fetch a page with GET</td></tr>                    <tr><td><span class="new_code">post($url, $parameters)</span></td><td>Fetch a page with POST</td></tr>                    <tr><td><span class="new_code">clickLink($label)</span></td><td>Follows a link by label</td></tr>                    <tr><td><span class="new_code">clickLinkById($id)</span></td><td>Follows a link by attribute</td></tr>                    <tr><td><span class="new_code">getUrl()</span></td><td>Current URL of page or frame</td></tr>                    <tr><td><span class="new_code">getTitle()</span></td><td>Page title</td></tr>                    <tr><td><span class="new_code">getContent()</span></td><td>Raw page or frame</td></tr>                    <tr><td><span class="new_code">getContentAsText()</span></td><td>HTML removed except for alt text</td></tr>                    <tr><td><span class="new_code">retry()</span></td><td>Repeat the last request</td></tr>                    <tr><td><span class="new_code">back()</span></td><td>Use the browser back button</td></tr>                    <tr><td><span class="new_code">forward()</span></td><td>Use the browser forward button</td></tr>                    <tr><td><span class="new_code">authenticate($username, $password)</span></td><td>Retry page or frame after a 401 response</td></tr>                    <tr><td><span class="new_code">restart($date)</span></td><td>Restarts the browser for a new session</td></tr>                    <tr><td><span class="new_code">ageCookies($interval)</span></td><td>Ages the cookies by the specified time</td></tr>                    <tr><td><span class="new_code">setCookie($name, $value)</span></td><td>Sets an additional cookie</td></tr>                    <tr><td><span class="new_code">getCookieValue($host, $path, $name)</span></td><td>Reads the most specific cookie</td></tr>                    <tr><td><span class="new_code">getCurrentCookieValue($name)</span></td><td>Reads cookie for the current context</td></tr>                </tbody></table>                The methods <span class="new_code">SimpleBrowser::useProxy()</span> and                <span class="new_code">SimpleBrowser::addHeader()</span> are special.                Once called they continue to apply to all subsequent fetches.            </p>            <p>                Navigating forms is similar to the                <a href="form_testing_documentation.html">WebTestCase form navigation</a>...                <table><tbody>                    <tr><td><span class="new_code">setField($name, $value)</span></td><td>Sets all form fields with that name</td></tr>                    <tr><td><span class="new_code">setFieldById($id, $value)</span></td><td>Sets all form fields with that id</td></tr>                    <tr><td><span class="new_code">getField($name)</span></td><td>Accessor for a form element value</td></tr>                    <tr><td><span class="new_code">getFieldById($id)</span></td><td>Accessor for a form element value</td></tr>                    <tr><td><span class="new_code">clickSubmit($label)</span></td><td>Submits form by button label</td></tr>                    <tr><td><span class="new_code">clickSubmitByName($name)</span></td><td>Submits form by button attribute</td></tr>                    <tr><td><span class="new_code">clickSubmitById($id)</span></td><td>Submits form by button attribute</td></tr>                    <tr><td><span class="new_code">clickImage($label, $x, $y)</span></td><td>Clicks an input tag of type image by title or alt text</td></tr>                    <tr><td><span class="new_code">clickImageByName($name, $x, $y)</span></td><td>Clicks an input tag of type image by name</td></tr>                    <tr><td><span class="new_code">clickImageById($id, $x, $y)</span></td><td>Clicks an input tag of type image by ID attribute</td></tr>                    <tr><td><span class="new_code">submitFormById($id)</span></td><td>Submits by the form tag attribute</td>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?