dtfbj24048 2010-11-17 16:19
浏览 56
已采纳

Selenium 2(WebDriver)和Phpunit?

Any one know how to use Selenium 2 with Phpunit? Are there any Selenium 2 samples in PHP?

  • 写回答

11条回答 默认 最新

  • doushi9856 2011-10-04 10:14
    关注

    Quick update: phpunit does now support Selenium 2


    At the time of writing, PHPUnit does not support Selenium 2.

    php-webdriver from facebook allows the complete WebDriver API to be called from PHP in an elegant way. To quote:

    Most clients require you to first read the protocol to see what's possible, then study the client itself to see how to call it. This hopes to eliminate the latter step.

    It is used by starting up the Selenium 2 server, which provides the interface at localhost:4444/wd/hub.

    /usr/bin/java -jar /path/to/selenium-server-standalone-2.7.0.jar
    

    then running the PHP test code, which calls that interface. For example:

    <?php
    
    require '/path/to/php-webdriver/__init__.php';
    
    $webdriver = new WebDriver();
    
    $session = $webdriver->session('opera', array());
    $session->open("http://example.com");
    $button = $session->element('id', 'my_button_id');
    $button->click();
    $session->close();
    

    The WebDriver API is mapped to PHP methods, compare calling click on element in the example with the element/click API call in the documentation.

    The test code can then be wrapped in regular phpUnit tests.

    This is not native phpUnit support, but it's a quite robust approach.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(10条)

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)