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条)

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?