Jul*_*oro 8 selenium laravel laravel-5.2
我好难过
我使用Laravel 5.2,我正在开发我的单元测试.
在Laravel 5.1中,您可以使用优秀的集成库来使用selenium,但它似乎不适用于Laravel 5.2
基本上,L5.2和Selenium之间是否存在任何集成,或者使用它是不可能的?
在这种情况下,我应该肯定留在L5.1,因为测试是我的应用程序的基本部分:(
小智 0
您需要使用composer安装PHPUnit_selenium包
composer require --dev phpunit/phpunit-selenium
Run Code Online (Sandbox Code Playgroud)
在 laravel/tests/ 中创建 Selenium 测试用例类
<?php
class SeleniumTestCase extends PHPUnit_Extensions_Selenium2TestCase
{
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected function setUp()
{
$this->setBrowser('firefox');
$this->setBrowserUrl('http://localhost:8000/');
}
protected function visit($path)
{
$this->url($path);
return $this;
}
protected function see($text, $tag = 'body')
{
print_r(request()->session()->all());
//method call by tag name;
$this->assertContains($text,$this->byTag($tag)->text());
return $this;
}
protected function pressByName($text){
$this->byName($text)->click();
return $this;
}
protected function pressByTag(){
$this->byTag('button')->click();
return $this;
}
protected function type($value, $name)
{
$this->byName($name)->value($value);
return $this;
}
protected function hold($seconds){
sleep($seconds);
return $this;
}
}
Run Code Online (Sandbox Code Playgroud)
并创建新的测试用例来访问主页 url
<?php
class ExampleTest extends SeleniumTestCase
{
/**
* A basic functional test example.
*
* @return void
*/
public function testTitle()
{
$this->visit('/')
->see('Site title','title');
}
}
Run Code Online (Sandbox Code Playgroud)
并从终端运行命令 PHPunit test
java -jar /usr/local/bin/selenium-server-standalone-2.35.0.jar
Run Code Online (Sandbox Code Playgroud)
参考文档:
| 归档时间: |
|
| 查看次数: |
937 次 |
| 最近记录: |