{"id":74318,"date":"2017-02-10T16:16:29","date_gmt":"2017-02-10T16:16:29","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=74318"},"modified":"2018-04-13T06:26:11","modified_gmt":"2018-04-13T06:26:11","slug":"http-status-using-casperjs","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/","title":{"rendered":"Get The Http Status Using Casperjs"},"content":{"rendered":"<p>In testing we do have lots of urls to test. To check the http status of those urls it will be easy to put all the urls in an array and you can check the http responses of all the urls by opening them one by one. For this, best practice is to use an array with a loop which will minimize your code writing and execution time\u00a0as well.<\/p>\n<p>You may check the blog\u00a0<a class=\"inline-block text-capitalize\" title=\"Casperjs : How to Save All href and title in an Array\" href=\"https:\/\/webkul.com\/blog\/casperjs-save-href-and-title-array\/\">Casperjs : How To Save All Href And Title In An Array<\/a>\u00a0to save data in an array.<\/p>\n<p>Here, I have used a\u00a0predefined set of urls. To check that I have used a loop and opened urls one by one and checked the http status of all the urls.<\/p>\n<pre class=\"brush:js\">\/**\r\n* Webkul Software.\r\n*\r\n* @category Webkul\r\n* @package Webkul_CasperJS\r\n* @author Webkul\r\n* @copyright Copyright (c) 2010-2018 Webkul Software Private Limited (https:\/\/webkul.com)\r\n* @license https:\/\/store.webkul.com\/license.html\r\n*\/\r\n\r\nvar casper = require(\"casper\").create();\r\nvar http = require('http');\r\nvar fs = require('fs');\r\nvar j = 0;\r\nvar links = ['https:\/\/store.webkul.com\/', 'https:\/\/store.webkul.com\/ggg'];\r\n\r\ncasper.start();\r\n\r\nfor (i = 0; i &lt; 2; i++) {\r\n\tcasper.thenOpen(links[j], function (response) {\r\n\t\tif (response == undefined || response.status &gt;= 400) {\r\n\t\t\tthis.echo(response.status + ': found at ' + response.url, 'ERROR');\r\n\t\t} else {\r\n\t\t\tthis.echo(response.status + ': found at ' + response.url, 'GREEN_BAR');\r\n\t\t}\r\n\t\tthis.on('http.status.404', function (resource) {\r\n\t\t\tthis.echo('404 found at : ' + resource.url, 'WARNING');\r\n\t\t});\r\n\t});\r\n\tj++;\r\n}\r\n\r\ncasper.run(function () {\r\n\tthis.exit();\r\n});\r\n<\/pre>\n<p>Now you have to run the command- <strong>casperjs your_filename.js<\/strong><\/p>\n<p>You may check the output on the terminal as shown below &#8211;<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-74321\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/02\/CasperHttp.png\" alt=\"\" width=\"573\" height=\"77\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/02\/CasperHttp.png 573w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/02\/CasperHttp-250x34.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/02\/CasperHttp-300x40.png 300w\" sizes=\"(max-width: 573px) 100vw, 573px\" loading=\"lazy\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In testing we do have lots of urls to test. To check the http status of those urls it will be easy to put all the urls in an array and you can check the http responses of all the urls by opening them one by one. For this, best practice is to use an <a href=\"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":66,"featured_media":74323,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4313],"tags":[3505,4484,4445,4485],"class_list":["post-74318","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-casperjs","tag-casperjs","tag-http-response","tag-http-status","tag-use-of-array-in-casperjs"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Get The Http Status Using Casperjs - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get The Http Status Using Casperjs - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"In testing we do have lots of urls to test. To check the http status of those urls it will be easy to put all the urls in an array and you can check the http responses of all the urls by opening them one by one. For this, best practice is to use an [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-02-10T16:16:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-04-13T06:26:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/02\/Code-Snippet-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"825\" \/>\n\t<meta property=\"og:image:height\" content=\"260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Shruti Baranwal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shruti Baranwal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/\"},\"author\":{\"name\":\"Shruti Baranwal\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/d90db6dde51254f8d7bda2539b81386e\"},\"headline\":\"Get The Http Status Using Casperjs\",\"datePublished\":\"2017-02-10T16:16:29+00:00\",\"dateModified\":\"2018-04-13T06:26:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/\"},\"wordCount\":152,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/02\/Code-Snippet-1.png\",\"keywords\":[\"casperjs\",\"http response\",\"HTTP Status\",\"use of array in casperjs\"],\"articleSection\":[\"CasperJS\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/\",\"url\":\"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/\",\"name\":\"Get The Http Status Using Casperjs - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/02\/Code-Snippet-1.png\",\"datePublished\":\"2017-02-10T16:16:29+00:00\",\"dateModified\":\"2018-04-13T06:26:11+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/02\/Code-Snippet-1.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/02\/Code-Snippet-1.png\",\"width\":825,\"height\":260},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Get The Http Status Using Casperjs\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/d90db6dde51254f8d7bda2539b81386e\",\"name\":\"Shruti Baranwal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2ecd6b094113b3e2f346229e04e90fcb6e242f28b3a1dbcb2f44fd9eefb93dbc?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2ecd6b094113b3e2f346229e04e90fcb6e242f28b3a1dbcb2f44fd9eefb93dbc?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"caption\":\"Shruti Baranwal\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/shruti-baranwal890\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Get The Http Status Using Casperjs - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/","og_locale":"en_US","og_type":"article","og_title":"Get The Http Status Using Casperjs - Webkul Blog","og_description":"In testing we do have lots of urls to test. To check the http status of those urls it will be easy to put all the urls in an array and you can check the http responses of all the urls by opening them one by one. For this, best practice is to use an [...]","og_url":"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2017-02-10T16:16:29+00:00","article_modified_time":"2018-04-13T06:26:11+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/02\/Code-Snippet-1.png","type":"image\/png"}],"author":"Shruti Baranwal","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Shruti Baranwal","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/"},"author":{"name":"Shruti Baranwal","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/d90db6dde51254f8d7bda2539b81386e"},"headline":"Get The Http Status Using Casperjs","datePublished":"2017-02-10T16:16:29+00:00","dateModified":"2018-04-13T06:26:11+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/"},"wordCount":152,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/02\/Code-Snippet-1.png","keywords":["casperjs","http response","HTTP Status","use of array in casperjs"],"articleSection":["CasperJS"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/http-status-using-casperjs\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/","url":"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/","name":"Get The Http Status Using Casperjs - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/02\/Code-Snippet-1.png","datePublished":"2017-02-10T16:16:29+00:00","dateModified":"2018-04-13T06:26:11+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/http-status-using-casperjs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/02\/Code-Snippet-1.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/02\/Code-Snippet-1.png","width":825,"height":260},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/http-status-using-casperjs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Get The Http Status Using Casperjs"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/d90db6dde51254f8d7bda2539b81386e","name":"Shruti Baranwal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2ecd6b094113b3e2f346229e04e90fcb6e242f28b3a1dbcb2f44fd9eefb93dbc?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2ecd6b094113b3e2f346229e04e90fcb6e242f28b3a1dbcb2f44fd9eefb93dbc?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","caption":"Shruti Baranwal"},"url":"https:\/\/webkul.com\/blog\/author\/shruti-baranwal890\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/74318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/66"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=74318"}],"version-history":[{"count":5,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/74318\/revisions"}],"predecessor-version":[{"id":120584,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/74318\/revisions\/120584"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/74323"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=74318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=74318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=74318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}