如何在验收测试中测试请求GET

时间:2015-12-11 17:35:04

标签: yii2 codeception yii2-advanced-app

我正在测试一个用于注销的脚本,并在您未登录时访问无法访问的URL,但在我的URL LOGOUT中,我收到了响应代码405,这是有问题的。

代码:

$I = new AcceptanceTester($scenario);

$I->amOnPage('/financeiro_legado/finlegado-titulo/index');

$I->wantTo('Logout');
$I->amOnPage('/');
$I->fillField('LoginForm[username]', 'marcelo');
$I->fillField('LoginForm[password]', 'marceloid5123');
$I->click('#login-form .btn');
$I->see('Olá, marcelo');
$I->seeInCurrentUrl('/');
$I->click('Logout', '.nav');

$I->amOnPage('/financeiro_legado/finlegado-titulo/index');

返回:

Logout (LogoutCept)
Scenario:
* I am on page "/financeiro_legado/finlegado-titulo/index"

  [Response] 200
  [Page] http://10.0.0.10/CliPainel/backend/web/index.php/user-management/auth/login
  [Cookies] {"PHPSESSID":"puu268lb5rjl00ml0hk27rm9b0"}
  [Headers] {"Date":["Fri, 11 Dec 2015 17:34:13 GMT"],"Server":["Apache/2.4.17 (Ubuntu)"],"Expires":["Thu, 19 Nov 1981 08:52:00 GMT"],"Cache-Control":["no-store, no-cache, must-revalidate, post-check=0, pre-check=0"],"Pragma":["no-cache"],"Set-Cookie":["_csrf=07c2d101d6c9e8530f7da67a78d451400eea99b70dc8a722a512661501bc4619a%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%2248-nrt97Wc-EEUA0jUh6-USBTS-44ccy%22%3B%7D; path=/; httponly"],"Vary":["Accept-Encoding"],"Content-Length":["3918"],"Content-Type":["text/html; charset=UTF-8"]}
* I am on page "/"
  [Response] 200
  [Page] http://10.0.0.10/CliPainel/backend/web/index.php/user-management/auth/login
  [Cookies] {"PHPSESSID":"puu268lb5rjl00ml0hk27rm9b0","_csrf":"07c2d101d6c9e8530f7da67a78d451400eea99b70dc8a722a512661501bc4619a:2:{i:0;s:5:"_csrf";i:1;s:32:"48-nrt97Wc-EEUA0jUh6-USBTS-44ccy";}"}
  [Headers] {"Date":["Fri, 11 Dec 2015 17:34:14 GMT"],"Server":["Apache/2.4.17 (Ubuntu)"],"Expires":["Thu, 19 Nov 1981 08:52:00 GMT"],"Cache-Control":["no-store, no-cache, must-revalidate, post-check=0, pre-check=0"],"Pragma":["no-cache"],"Vary":["Accept-Encoding"],"Content-Length":["3918"],"Content-Type":["text/html; charset=UTF-8"]}
* I fill field "LoginForm[username]","marcelo"
* I fill field "LoginForm[password]","marceloid5123"
* I click "#login-form .btn"
  [Uri] http://10.0.0.10/CliPainel/backend/web/index.php/user-management/auth/login
  [Method] POST
  [Parameters] {"_csrf":"bWN1ZS1zWTBZW1gLXwdgBzoAWCBoJhgABzYdUwAmCnI5MFhRGRA6SQ==","LoginForm":{"username":"marcelo","password":"marceloid5123"}}
  [Response] 200
  [Page] http://10.0.0.10/CliPainel/backend/web/
  [Cookies] {"PHPSESSID":"6hehrk4ddoroplv5so3l6klkb1","_csrf":"07c2d101d6c9e8530f7da67a78d451400eea99b70dc8a722a512661501bc4619a:2:{i:0;s:5:"_csrf";i:1;s:32:"48-nrt97Wc-EEUA0jUh6-USBTS-44ccy";}"}
  [Headers] {"Date":["Fri, 11 Dec 2015 17:34:16 GMT"],"Server":["Apache/2.4.17 (Ubuntu)"],"Expires":["Thu, 19 Nov 1981 08:52:00 GMT"],"Cache-Control":["no-store, no-cache, must-revalidate, post-check=0, pre-check=0"],"Pragma":["no-cache"],"Vary":["Accept-Encoding"],"Transfer-Encoding":["chunked"],"Content-Type":["text/html; charset=UTF-8"]}
* I see "Olá, marcelo"
* I see in current url "/"
* I click "Logout",".nav"
  [Response] 405
  [Page] http://10.0.0.10/CliPainel/backend/web/index.php/site/logout
  [Cookies] {"PHPSESSID":"6hehrk4ddoroplv5so3l6klkb1","_csrf":"07c2d101d6c9e8530f7da67a78d451400eea99b70dc8a722a512661501bc4619a:2:{i:0;s:5:"_csrf";i:1;s:32:"48-nrt97Wc-EEUA0jUh6-USBTS-44ccy";}"}
  [Headers] {"Date":["Fri, 11 Dec 2015 17:34:18 GMT"],"Server":["Apache/2.4.17 (Ubuntu)"],"Expires":["Thu, 19 Nov 1981 08:52:00 GMT"],"Cache-Control":["no-store, no-cache, must-revalidate, post-check=0, pre-check=0"],"Pragma":["no-cache"],"Allow":["POST"],"Transfer-Encoding":["chunked"],"Content-Type":["text/html; charset=UTF-8"]}
* I am on page "/financeiro_legado/finlegado-titulo/index"
  [Response] 200
  [Page] http://10.0.0.10/CliPainel/backend/web/financeiro_legado/finlegado-titulo/index
  [Cookies] {"PHPSESSID":"6hehrk4ddoroplv5so3l6klkb1","_csrf":"07c2d101d6c9e8530f7da67a78d451400eea99b70dc8a722a512661501bc4619a:2:{i:0;s:5:"_csrf";i:1;s:32:"48-nrt97Wc-EEUA0jUh6-USBTS-44ccy";}"}
  [Headers] {"Date":["Fri, 11 Dec 2015 17:34:19 GMT"],"Server":["Apache/2.4.17 (Ubuntu)"],"Expires":["Thu, 19 Nov 1981 08:52:00 GMT"],"Cache-Control":["no-store, no-cache, must-revalidate, post-check=0, pre-check=0"],"Pragma":["no-cache"],"Vary":["Accept-Encoding"],"Transfer-Encoding":["chunked"],"Content-Type":["text/html; charset=UTF-8"]}
 PASSED 

1 个答案:

答案 0 :(得分:0)

可能您在网络浏览器中使用Javascript处理该点击 Codeii的Yii2模块不执行Javascript。

您的选择是:
a)使您的网站禁用Javascript。 你可以通过改变

来实现这一目标
<a href="site/logout" onclick="logout()">Logout</a>

<form method="POST" action="site/logout">
  <input type="submit" value="Logout" />
</form>

b)使用sendAjaxPostRequest 方法发出POST请求

$I->sendAjaxPostRequest('site/logout', []);