我正在處理的項目在登錄後面有一個api。我如何使用Behat和Mink和WebApiContext?
我使用貝哈特水貂登錄:
Scenario: Login
Given I am on "/login/"
And I should see "Login"
When I fill in "_username" with "test"
And I fill in "_password" with "test"
And I press "_submit"
Then I should be on "/"
該工程..
然而,登錄會話沒有存儲每當我想要做的使用WebApiContext如下:
Scenario: Getting the list of pages
When I send a GET request to "/api/pages.json"
Then print response
我在同一功能中使用了這兩種方案。我FeatureContext類看起來是這樣的:
class FeatureContext extends MinkContext
{
public function __construct(array $parameters)
{
$context = new WebApiContext($parameters['base_url']);
$context->getBrowser()->getClient()->setCookieJar(new \Buzz\Util\CookieJar());
$this->useContext('web', $context);
}
}
我加入了cookiejar想法來自this issue沒有成功。當我打印的迴應,我剛纔看到的HTML頁面從登錄屏幕..
沒有人有任何想法,如果我要完全錯誤的方式,或者我有點朝着正確的方向?
不能希望有更好的答案!非常感謝! –