4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CasperJSでHTTPステータスコードを取得する

Last updated at Posted at 2014-04-03

response.status です。

casper = require('casper').create()

casper.start 'http://www.yahoo.co.jp/', (response) ->
  @echo '[status code] ' + response.status
  // -> [status code] 200

casper.run()

responseの中にstatusというプロパティがあるのでそこからHTTPステータスコードを取得できます。

テストに使うには

初めからテストに使うと分かっていれば、responseから取得する必要はなく assertHttpStatus というテスト用メソッドが使えます。

yahoo_test.coffee
casper.test.begin 'HttpStatus Test', (test) ->
  casper.start 'http://www.yahoo.co.jp/', ->
    test.assertHttpStatus 200

  casper.run ->
    test.done()
$ casperjs test yahoo_test.coffee

テストのときは test をつけて実行しましょう。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?