Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHPUnit Selenium 2扩展设置cookies_Php_Selenium_Phpunit - Fatal编程技术网

PHPUnit Selenium 2扩展设置cookies

PHPUnit Selenium 2扩展设置cookies,php,selenium,phpunit,Php,Selenium,Phpunit,我试图在测试前设置cookies,但由于某些原因它们没有设置 下面是我的示例代码: class WebTest extends PHPUnit_Extensions_Selenium2TestCase { protected function setUp() { $this->setBrowser('firefox'); $this->setBrowserUrl('http://dev.local/'); } publ

我试图在测试前设置cookies,但由于某些原因它们没有设置

下面是我的示例代码:

class WebTest extends PHPUnit_Extensions_Selenium2TestCase
{
    protected function setUp()
    {
        $this->setBrowser('firefox');
        $this->setBrowserUrl('http://dev.local/');
    }

    public function testTitle()
    {
        $session = $this->prepareSession();

        $session->cookie()->remove('language_version');
        $session->cookie()->add('language_version', 'en')->set();
        $this->url('/');

        $this->assertEquals('Title in English', $this->title());
    }
}

有人知道怎么做吗?非常感谢您的帮助

cookie不应存在,因此删除操作将失败。Selenium在每次运行测试套件时都会使用新的空配置文件运行浏览器。
.

cookie不应存在,因此删除操作将失败。Selenium在每次运行测试套件时都会使用新的空配置文件运行浏览器。
.

我在Selenium文档中找到了我问题的答案:

如果您试图在开始与网站交互之前预设cookie,并且您的主页很大/需要一段时间才能加载,则另一种选择是在网站上查找较小的页面,通常404页面较小()

现在,我的测试如下所示:

$this->url('/unit_tests.php');
$this->cookie()->remove('language_version');
$this->cookie()->add('language_version', 'en')->set();

$this->url('/');
$this->assertEquals('Title in English', $this->title());

/unit\u tests.php
是一个空的php文件,允许我首先为页面设置cookie。

我在Selenium文档中找到了我问题的答案:

如果您试图在开始与网站交互之前预设cookie,并且您的主页很大/需要一段时间才能加载,则另一种选择是在网站上查找较小的页面,通常404页面较小()

现在,我的测试如下所示:

$this->url('/unit_tests.php');
$this->cookie()->remove('language_version');
$this->cookie()->add('language_version', 'en')->set();

$this->url('/');
$this->assertEquals('Title in English', $this->title());

/unit\u tests.php
是一个空的php文件,允许我首先为页面设置cookie。

删除不存在的cookie实际上不会引发任何异常。但它可能会默默地忽略其余代码。尝试在删除cookie之后立即添加日志或警报,以查看它是否正在运行以下代码。删除不存在的cookie实际上不会引发任何异常。但它可能会自动忽略其余代码。尝试在删除cookie之后添加日志或警报,以查看它是否正在运行以下代码。