【问题标题】:Altering $_POST in PHPUnit/Selenium在 PHPUnit/Selenium 中更改 $_POST
【发布时间】:2010-12-28 22:26:36
【问题描述】:

我需要向 $_POST 添加一个值,特别是“端口”,以便我可以告诉我的测试提交通过 fakemail。

The fakemail documentation 展示了如何使用 SimpleTest 向 $_POST 插入值:

$this->clickSubmit('Send', array('port' => 10025));

在 PHPUnit 中,这不起作用:

$this->click("//input[@value='Send']", array('port' => 10025));

我对测试背后的所有概念都非常陌生,所以这可能比我做的要简单。您将如何使用 PHPUnit/Selenium 完成工作?

【问题讨论】:

    标签: selenium phpunit simpletest


    【解决方案1】:

    尚未在 phpunit 中对此进行测试,但在 Selenium IDE 中,您可以使用 javascript 更改隐藏字段。

    测试页面:

    <html><head></head><body>
    
    <?php print_r($_POST); ?>
    
    <br/><br/>
    <form action="test.php" method="POST">
        <input type="hidden" id="hhh" name="hhh" value="orig"/>
        <input type="text" name="ttt"/>
        <input type="submit" name="sss"/>
    </form>
    </body></html>
    

    脚本(从 firefox IDE 生成,所以没有测试):

    <?php
    require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
    
    class Example extends PHPUnit_Extensions_SeleniumTestCase
    {
      protected function setUp()
      {
        $this->setBrowser("*chrome");
        $this->setBrowserUrl("http://localhost/test.php");
      }
    
      public function testMyTestCase()
      {
        $this->type("ttt", "bbb");
        $this->runScript("javascript{ this.browserbot.getCurrentWindow().document.getElementById('hhh').value = 'new2'; }");
        $this->click("sss");
      }
    }
    ?>
    

    所以只需将port 变量添加为隐藏字段并使用javascript 设置值。

    【讨论】:

      猜你喜欢
      • 2012-07-23
      • 2013-12-19
      • 2015-07-19
      • 2015-03-03
      • 1970-01-01
      • 2011-11-02
      • 2011-11-29
      • 2016-07-26
      • 2014-06-27
      相关资源
      最近更新 更多