{"id":117926,"date":"2018-04-02T05:03:14","date_gmt":"2018-04-02T05:03:14","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=117926"},"modified":"2018-04-02T05:03:14","modified_gmt":"2018-04-02T05:03:14","slug":"responsiveness-testing-casperjs","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/","title":{"rendered":"Check Responsiveness With Casperjs"},"content":{"rendered":"<p>To test a website it&#8217;s really very hard to open every page, resize them and then take a look on the complete page by scrolling them. We need to make it an automation process so that it can save our time and can remove this restless process.<\/p>\n<p>Casperjs itself has so many predefined methods and by using them you can achieve it. You can follow the following code steps to write your own scripts-<\/p>\n<pre class=\"brush:js\">var casper      = require('casper').create(),\r\nsiteUrl     = \"https:\/\/store.webkul.com\/\",\/\/your website's base URL\r\nurls       = [\r\n    '',\r\n    'Magento-2.html',\r\n    'Magento-Extensions.html'\r\n], \/\/sub urls of your website\r\nscreenWidth = [\r\n    400, \r\n    600, \r\n    800, \r\n    1200\r\n]; \/\/your required width\r\nscreenshotNow = new Date(),\r\nscreenshotDateTime = (screenshotNow.getHours()) + ':' + (screenshotNow.getMinutes()) + ':' + (screenshotNow.getSeconds()),\r\n\r\ncasper.start(siteUrl, function(){\r\nthis.echo('Opening the site URL...', 'COMMENT');\r\n});\r\n\r\nurls.forEach(function(url) {\r\ncasper.thenOpen(siteUrl + url, function() {\r\n    var pageTitle = this.getTitle();\r\n    screenWidth.forEach(function(currentWidth) {\r\n        casper.viewport(currentWidth, 1000).capture('screenshots\/' + pageTitle + \":\" + screenshotDateTime + '\/' + pageTitle + '_' + currentWidth + '.png', {\r\n            top: 0,\r\n            left: 0,\r\n            width: currentWidth,\r\n            height: casper.evaluate(function() {\r\n                return document.body.scrollHeight;\r\n            })\r\n        });\r\n    });\r\n    this.echo('Screenshots successfully captured for- ' + this.getCurrentUrl(), 'COMMENT');\r\n});\r\n});\r\n\r\ncasper.run();<\/pre>\n<p>Let me explain each step one by one-<\/p>\n<pre class=\"brush:js\">siteUrl     = \"https:\/\/store.webkul.com\/\",\/\/your website's base URL\r\nurls       = [\r\n    '',\r\n    'Magento-2.html',\r\n    'Magento-Extensions.html'\r\n], \/\/sub urls of your website\r\nscreenWidth = [\r\n    400, \r\n    600, \r\n    800, \r\n    1200\r\n]; \/\/your required width<\/pre>\n<p>Here, I have taken a variable and siteUrl and assigned my website&#8217;s Url to it. Make sure you assign your website&#8217;s base URL. Then we have taken an array of all the sub URL&#8217;s for which I need to check the responsiveness. I have written everything\u00a0in the script but you can give the URL&#8217;s\u00a0from command line also using &#8220;casper.cli.get(0)&#8221;.<\/p>\n<pre class=\"brush:js\">screenshotNow = new Date(),\r\nscreenshotDateTime = (screenshotNow.getHours()) + ':' + (screenshotNow.getMinutes()) + ':' + (screenshotNow.getSeconds()),<\/pre>\n<p>I am using this piece of code just to take the screenshot with the current date and time name.<\/p>\n<pre class=\"brush:js\">urls.forEach(function(url) {\r\ncasper.thenOpen(siteUrl + url, function() {\r\n    var pageTitle = this.getTitle();\r\n    screenWidth.forEach(function(currentWidth) {\r\n        casper.viewport(currentWidth, 1000).capture('screenshots\/' + pageTitle + \":\" + screenshotDateTime + '\/' + pageTitle + '_' + currentWidth + '.png', {\r\n            top: 0,\r\n            left: 0,\r\n            width: currentWidth,\r\n            height: casper.evaluate(function() {\r\n                return document.body.scrollHeight;\r\n            })\r\n        });\r\n    });\r\n    this.echo('Screenshots successfully captured for- ' + this.getCurrentUrl(), 'COMMENT');\r\n});\r\n});<\/pre>\n<p>Now, I am opening each Url one by one using &#8220;forEach&#8221; and &#8220;casper.thenOpen&#8221;.<\/p>\n<p>&#8220;var pageTitle = this.getTitle();&#8221; is used just to take screenshot with the current page title.<\/p>\n<p>&#8220;casper.viewport();&#8221; allows to change the current view port size.<\/p>\n<p>&#8220;casper.capture();&#8221; allows you to capture the current page.<\/p>\n<p>Hope, this blog will help you. If you have any doubt then please\u00a0leave a comment here.<\/p>\n<p>Thank you\u00a0\ud83d\ude42<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To test a website it&#8217;s really very hard to open every page, resize them and then take a look on the complete page by scrolling them. We need to make it an automation process so that it can save our time and can remove this restless process. Casperjs itself has so many predefined methods and <a href=\"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":66,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4313],"tags":[3505,1482,6449,3250],"class_list":["post-117926","post","type-post","status-publish","format-standard","hentry","category-casperjs","tag-casperjs","tag-responsive-2","tag-responsiveness","tag-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Check Responsiveness With 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\/responsiveness-testing-casperjs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Check Responsiveness With Casperjs - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"To test a website it&#8217;s really very hard to open every page, resize them and then take a look on the complete page by scrolling them. We need to make it an automation process so that it can save our time and can remove this restless process. Casperjs itself has so many predefined methods and [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/responsiveness-testing-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=\"2018-04-02T05:03:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/\"},\"author\":{\"name\":\"Shruti Baranwal\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/d90db6dde51254f8d7bda2539b81386e\"},\"headline\":\"Check Responsiveness With Casperjs\",\"datePublished\":\"2018-04-02T05:03:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/\"},\"wordCount\":236,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"casperjs\",\"Responsive\",\"responsiveness\",\"testing\"],\"articleSection\":[\"CasperJS\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/\",\"url\":\"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/\",\"name\":\"Check Responsiveness With Casperjs - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2018-04-02T05:03:14+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Check Responsiveness With 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":"Check Responsiveness With 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\/responsiveness-testing-casperjs\/","og_locale":"en_US","og_type":"article","og_title":"Check Responsiveness With Casperjs - Webkul Blog","og_description":"To test a website it&#8217;s really very hard to open every page, resize them and then take a look on the complete page by scrolling them. We need to make it an automation process so that it can save our time and can remove this restless process. Casperjs itself has so many predefined methods and [...]","og_url":"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2018-04-02T05:03:14+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.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":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/"},"author":{"name":"Shruti Baranwal","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/d90db6dde51254f8d7bda2539b81386e"},"headline":"Check Responsiveness With Casperjs","datePublished":"2018-04-02T05:03:14+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/"},"wordCount":236,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["casperjs","Responsive","responsiveness","testing"],"articleSection":["CasperJS"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/","url":"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/","name":"Check Responsiveness With Casperjs - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2018-04-02T05:03:14+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/responsiveness-testing-casperjs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Check Responsiveness With 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\/117926","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=117926"}],"version-history":[{"count":6,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/117926\/revisions"}],"predecessor-version":[{"id":118842,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/117926\/revisions\/118842"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=117926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=117926"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=117926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}