这个环境搭建遇到了挺多麻烦,最终还是没能自己解决,幸好有同事“青蛙”的帮忙解决了这个问题!在这里把本人亲测步骤给大家列一下,希望给大家提供方便!
安装pear:
Go-pear.phar下载地址:http://download.csdn.net/detail/e421083458/4602207
下载go-pear.phar文件到C:\wamp\bin\php\php5.3.13\PEAR中
然后执行以下命令:
[plain] view plaincopyprint?
- cd C:\wamp\bin\php\php5.3.13
- php -d phar.require_hash=0 PEAR/go-pear.phar
然后就是遇到回车就回车,输入Y就Y。安装之后它会提示你双击一下。
c:\wamp\bin\php\php5.3.13\PEAR_ENV.reg 以添加环境变量 照做就是。为了下面操作和以后使用方便需要将php添加到环境变量里面。
升级pear :
直接安装phpunit它会提示版本过低 这里就要升级pear了
[plain] view plaincopyprint?
- Pear clear-cache
- pear upgrade pear
成功升级后的截图:
[plain] view plaincopyprint?
- Pear upgrade-all
产品升级后的截图
安装phpunit
[plain] view plaincopyprint?
- pear clear-cache
- pear channel-discover pear.phpunit.de
- pear channel-discover components.ez.no
- pear channel-discover pear.symfony-project.com
- pear install -a -f phpunit/PHPUnit
安装成功截图:
安装phpunit扩展
[plain] view plaincopyprint?
- pear channel-discover pear.symfony.com
- pear install phpunit/DbUnit
- pear channel-discover pear.phpunit.de
- 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
成功截图:
安装selenium扩展
[plain] view plaincopyprint?
- pear install phpunit/PHPUnit_Selenium
成功截图:
调试selenium
selenium-server-standalone-2.6.0.jar下载地址:http://download.csdn.net/detail/e421083458/4882037
打开selenium-server
[plain] view plaincopyprint?
- java -jar C:\wamp\selenium-server-standalone-2.25.0.jar -interactive -log selenium.log
成功截图:
安装firefox的selenium IDE插件
地址:http://seleniumhq.org/download/
点击1.9.0 进行selenium IDE安装。
具体录制方法见:
http://blog.163.com/lgh_2002/blog/static/44017526201259113351146/
测试脚本:
baiduCase.php
[php] view plaincopyprint?
- <?php
- class Example extends PHPUnit_Extensions_SeleniumTestCase
- {
- protected function setUp()
- {
- $this->setBrowser("*firefox");
- $this->setBrowserUrl("http://www.baidu.com/");
- }
- public function testMyTestCase()
- {
- $this->open("/");
- $this->type("id=kw", "你好");
- $this->click("id=su");
- $this->waitForPageToLoad("30000");
- $this->assertEquals(0,0);
- }
- }
- ?>
开始测试:
phpunit baiduCase.php
测试成功截图:
参考文档:
http://www.phpunit.de/manual/3.7/en/index.html
http://seleniumhq.org/download/