web_tester_documentation.html.svn-base
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 585 行 · 第 1/2 页
SVN-BASE
585 行
<pre class="shell">Web site tests1) Expecting response in [200] got [302] in testhomepage in testoflastcraft in lastcraft_test.phpFAILURES!!!Test cases run: 1/1, Failures: 1, Exceptions: 0</pre> We can modify the test to correctly assert redirects with...<pre>class TestOfLastcraft extends WebTestCase { function testHomepage() { $this->setMaximumRedirects(0); $this->get('http://www.lastcraft.com/test/redirect.php'); $this->assertResponse(<strong>array(301, 302, 303, 307)</strong>); }}</pre> This now passes. </p> <p><a class="target" name="navigation"><h2>Navigating a web site</h2></a></p> <p> Users don't often navigate sites by typing in URLs, but by clicking links and buttons. Here we confirm that the contact details can be reached from the home page...<pre>class TestOfLastcraft extends WebTestCase { ... function testContact() { $this->get('http://www.lastcraft.com/');<strong> $this->clickLink('About'); $this->assertTitle(new PatternExpectation('/About Last Craft/'));</strong> }}</pre> The parameter is the text of the link. </p> <p> If the target is a button rather than an anchor tag, then <span class="new_code">clickSubmit()</span> can be used with the button title...<pre><strong>$this->clickSubmit('Go!');</strong></pre> If you are not sure or don't care, the usual case, then just use the <span class="new_code">click()</span> method...<pre><strong>$this->click('Go!');</strong></pre> </p> <p> The list of navigation methods is... <table><tbody> <tr><td><span class="new_code">getUrl()</span></td><td>The current location</td></tr> <tr><td><span class="new_code">get($url, $parameters)</span></td><td>Send a GET request with these parameters</td></tr> <tr><td><span class="new_code">post($url, $parameters)</span></td><td>Send a POST request with these parameters</td></tr> <tr><td><span class="new_code">head($url, $parameters)</span></td><td>Send a HEAD request without replacing the page content</td></tr> <tr><td><span class="new_code">retry()</span></td><td>Reload the last request</td></tr> <tr><td><span class="new_code">back()</span></td><td>Like the browser back button</td></tr> <tr><td><span class="new_code">forward()</span></td><td>Like the browser forward button</td></tr> <tr><td><span class="new_code">authenticate($name, $password)</span></td><td>Retry after a challenge</td></tr> <tr><td><span class="new_code">restart()</span></td><td>Restarts the browser as if a new session</td></tr> <tr><td><span class="new_code">getCookie($name)</span></td><td>Gets the cookie value for the current context</td></tr> <tr><td><span class="new_code">ageCookies($interval)</span></td><td>Ages current cookies prior to a restart</td></tr> <tr><td><span class="new_code">clearFrameFocus()</span></td><td>Go back to treating all frames as one page</td></tr> <tr><td><span class="new_code">clickSubmit($label)</span></td><td>Click the first button with this label</td></tr> <tr><td><span class="new_code">clickSubmitByName($name)</span></td><td>Click the button with this name attribute</td></tr> <tr><td><span class="new_code">clickSubmitById($id)</span></td><td>Click the button with this ID attribute</td></tr> <tr><td><span class="new_code">clickImage($label, $x, $y)</span></td><td>Click 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>Click an input tag of type image by name</td></tr> <tr><td><span class="new_code">clickImageById($id, $x, $y)</span></td><td>Click an input tag of type image by ID attribute</td></tr> <tr><td><span class="new_code">submitFormById($id)</span></td><td>Submit a form without the submit value</td></tr> <tr><td><span class="new_code">clickLink($label, $index)</span></td><td>Click an anchor by the visible label text</td></tr> <tr><td><span class="new_code">clickLinkById($id)</span></td><td>Click an anchor by the ID attribute</td></tr> <tr><td><span class="new_code">getFrameFocus()</span></td><td>The name of the currently selected frame</td></tr> <tr><td><span class="new_code">setFrameFocusByIndex($choice)</span></td><td>Focus on a frame counting from 1</td></tr> <tr><td><span class="new_code">setFrameFocus($name)</span></td><td>Focus on a frame by name</td></tr> </tbody></table> </p> <p> The parameters in the <span class="new_code">get()</span>, <span class="new_code">post()</span> or <span class="new_code">head()</span> methods are optional. The HTTP HEAD fetch does not change the browser context, only loads cookies. This can be useful for when an image or stylesheet sets a cookie for crafty robot blocking. </p> <p> The <span class="new_code">retry()</span>, <span class="new_code">back()</span> and <span class="new_code">forward()</span> commands work as they would on your web browser. They use the history to retry pages. This can be handy for checking the effect of hitting the back button on your forms. </p> <p> The frame methods need a little explanation. By default a framed page is treated just like any other. Content will be searced for throughout the entire frameset, so clicking a link will work no matter which frame the anchor tag is in. You can override this behaviour by focusing on a single frame. If you do that, all searches and actions will apply to that frame alone, such as authentication and retries. If a link or button is not in a focused frame then it cannot be clicked. </p> <p> Testing navigation on fixed pages only tells you when you have broken an entire script. For highly dynamic pages, such as for bulletin boards, this can be crucial for verifying the correctness of the application. For most applications though, the really tricky logic is usually in the handling of forms and sessions. Fortunately SimpleTest includes <a href="form_testing_documentation.html">tools for testing web forms</a> as well. </p> <p><a class="target" name="request"><h2>Modifying the request</h2></a></p> <p> Although SimpleTest does not have the goal of testing networking problems, it does include some methods to modify and debug the requests it makes. Here is another method list... <table><tbody> <tr><td><span class="new_code">getTransportError()</span></td><td>The last socket error</td></tr> <tr><td><span class="new_code">showRequest()</span></td><td>Dump the outgoing request</td></tr> <tr><td><span class="new_code">showHeaders()</span></td><td>Dump the incoming headers</td></tr> <tr><td><span class="new_code">showSource()</span></td><td>Dump the raw HTML page content</td></tr> <tr><td><span class="new_code">ignoreFrames()</span></td><td>Do not load framesets</td></tr> <tr><td><span class="new_code">setCookie($name, $value)</span></td><td>Set a cookie from now on</td></tr> <tr><td><span class="new_code">addHeader($header)</span></td><td>Always add this header to the request</td></tr> <tr><td><span class="new_code">setMaximumRedirects($max)</span></td><td>Stop after this many redirects</td></tr> <tr><td><span class="new_code">setConnectionTimeout($timeout)</span></td><td>Kill the connection after this time between bytes</td></tr> <tr><td><span class="new_code">useProxy($proxy, $name, $password)</span></td><td>Make requests via this proxy URL</td></tr> </tbody></table> These methods are principally for debugging. </p> </div> References and related information... <ul><li> SimpleTest project page on <a href="http://sourceforge.net/projects/simpletest/">SourceForge</a>. </li><li> SimpleTest download page on <a href="http://www.lastcraft.com/simple_test.php">LastCraft</a>. </li><li> The <a href="http://simpletest.org/api/">developer's API for SimpleTest</a> gives full detail on the classes and assertions available. </li></ul><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> | <span class="chosen">Web tester</span> | <a href="form_testing_documentation.html">Testing forms</a> | <a href="authentication_documentation.html">Authentication</a> | <a href="browser_documentation.html">Scriptable browser</a></div></div><div class="copyright"> Copyright<br>Marcus Baker 2006 </div></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?