phpunit+selenium环境搭建

时间:2023-03-09 13:28:20
phpunit+selenium环境搭建

这个环境搭建遇到了挺多麻烦,最终还是没能自己解决,幸好有同事“青蛙”的帮忙解决了这个问题!在这里把本人亲测步骤给大家列一下,希望给大家提供方便!

安装pear:

Go-pear.phar下载地址:http://download.****.net/detail/e421083458/4602207

下载go-pear.phar文件到C:\wamp\bin\php\php5.3.13\PEAR中

然后执行以下命令:

  1. cd C:\wamp\bin\php\php5.3.13
  2. php -d phar.require_hash=0 PEAR/go-pear.phar

phpunit+selenium环境搭建

然后就是遇到回车就回车,输入Y就Y。安装之后它会提示你双击一下。

c:\wamp\bin\php\php5.3.13\PEAR_ENV.reg 以添加环境变量 照做就是。为了下面操作和以后使用方便需要将php添加到环境变量里面。

升级pear :

直接安装phpunit它会提示版本过低 这里就要升级pear了

  1. Pear clear-cache
  2. pear upgrade pear

成功升级后的截图:

phpunit+selenium环境搭建

  1. Pear upgrade-all

产品升级后的截图

phpunit+selenium环境搭建

安装phpunit

  1. pear clear-cache
  2. pear channel-discover pear.phpunit.de
  3. pear channel-discover components.ez.no
  4. pear channel-discover pear.symfony-project.com
  5. pear install -a -f  phpunit/PHPUnit

安装成功截图:

phpunit+selenium环境搭建

安装phpunit扩展

  1. pear channel-discover pear.symfony.com
  2. pear install phpunit/DbUnit
  3. pear channel-discover pear.phpunit.de
  4. pear install phpunit/PHPUnit_Story

如此步骤遗漏的会产生以下错误:

Invalid response while accessing the Selenium Server at 'http://localhost:4444/selenium-server/driver/': Failed to start new browser session: Error while launching browser

Exception: Unable to bind to locking port 7054 within 45000

成功截图:

phpunit+selenium环境搭建

安装selenium扩展

  1. pear install phpunit/PHPUnit_Selenium

成功截图:

phpunit+selenium环境搭建

调试selenium

selenium-server-standalone-2.6.0.jar下载地址:http://download.****.net/detail/e421083458/4882037

打开selenium-server

  1. java -jar C:\wamp\selenium-server-standalone-2.25.0.jar  -interactive  -log selenium.log

成功截图:

phpunit+selenium环境搭建

安装firefox的selenium IDE插件

地址:http://seleniumhq.org/download/

phpunit+selenium环境搭建

点击1.9.0 进行selenium IDE安装。

具体录制方法见:

http://blog.163.com/lgh_2002/blog/static/44017526201259113351146/

测试脚本:

baiduCase.php

  1. <?php
  2. class Example extends PHPUnit_Extensions_SeleniumTestCase
  3. {
  4. protected function setUp()
  5. {
  6. $this->setBrowser("*firefox");
  7. $this->setBrowserUrl("http://www.baidu.com/");
  8. }
  9. public function testMyTestCase()
  10. {
  11. $this->open("/");
  12. $this->type("id=kw", "你好");
  13. $this->click("id=su");
  14. $this->waitForPageToLoad("30000");
  15. $this->assertEquals(0,0);
  16. }
  17. }
  18. ?>

开始测试:

phpunit baiduCase.php

测试成功截图:

phpunit+selenium环境搭建

参考文档:

http://www.phpunit.de/manual/3.7/en/index.html

http://pear.phpunit.de/

http://seleniumhq.org/download/