【发布时间】:2014-02-04 06:03:52
【问题描述】:
我们正在使用 A/B 测试,我们必须设置控制页面的 cookie。我做了一个简单的测试:
cookie.feature
@javascript
Scenario: Cookie test
Given Set cookie "a" = "start" on page "/test.php"
Then wait 5000
When Set cookie "a" = "change" and go to "/test.php"
Then wait 5000
FeatureContext.php
<?php
// ...
/**
* @Given /^Set cookie "([^"]+)" = "([^"]+)" on page "([^"]+)"$/
* @When /^Set cookie "([^"]+)" = "([^"]+)" and go to "([^"]+)"$/
*/
public function setUserCookie($name, $value, $page)
{
$this->getSession()->setCookie($name, $value);
$this->visit($page);
}
/**
* @Then /^wait (\d+)$/
*/
public function iWait($msec)
{
$this->getSession()->wait($msec);
}
test.php
<?php echo $_COOKIE['a'];
当我运行这个测试时,第一页没有 cookie!我在 Fiddler 中检查了它,HTTP 标头首先不包含 cookie,只有第二个。
回复:
- 注意:未定义索引:a
- 改变
如何设置初始化 cookie? (无需加载两次第一页)
【问题讨论】:
标签: php cookies selenium-webdriver behat