【问题标题】:Selenium and Laravel 5.2硒和 Laravel 5.2
【发布时间】:2016-06-21 18:24:10
【问题描述】:

我很难过,

我使用 Laravel 5.2,并且正在开发我的单元测试。

在 Laravel 5.1 中,您可以使用强大的集成库来使用 selenium,但它似乎在 Laravel 5.2 中不起作用

所以基本上,L5.2 和 Selenium 之间是否有任何集成,或者说不能很好地使用它?

在这种情况下,我绝对应该留在 L5.1,因为测试是我的应用程序的基本部分:(

【问题讨论】:

标签: laravel selenium laravel-5.2


【解决方案1】:

你需要使用 composer 安装 PHPUnit_selenium 包

composer require --dev phpunit/phpunit-selenium

在 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;
    }
}

并为访问主页 url 创建新的测试用例

<?php    
class ExampleTest extends SeleniumTestCase
{
    /**
     * A basic functional test example.
     *
     * @return void
     */
    public function testTitle()
    {
        $this->visit('/')
            ->see('Site title','title');
    }
}

并从终端运行命令 PHPunit test

java -jar /usr/local/bin/selenium-server-standalone-2.35.0.jar

参考文档:

【讨论】:

    猜你喜欢
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    • 2016-10-21
    • 2018-01-08
    • 2016-08-31
    • 2018-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多