{"id":1181,"date":"2017-06-06T14:10:07","date_gmt":"2017-06-06T09:10:07","guid":{"rendered":"https:\/\/thedevcouple.com\/?p=1181"},"modified":"2017-07-17T09:16:41","modified_gmt":"2017-07-17T04:16:41","slug":"using-browsersync-synchronised-browser-testing","status":"publish","type":"post","link":"https:\/\/thedevcouple.com\/using-browsersync-synchronised-browser-testing\/","title":{"rendered":"Using BrowserSync for Synchronised Browser Testing"},"content":{"rendered":"<p>As a matter of fact let&#8217;s accept that developers hate doing grunt work. Instead of repeating things again and again, a pro web developer believes in hardcore automation and would love to invest time in automating things. WordPress site setup and browser testing strongly support the DRY \u2014 Don&#8217;t Repeat Yourself philosophy and encourage you to automate the entire process with several automation tools and scripts.<\/p>\n<p><!--more--><\/p>\n<p><a href=\"http:\/\/livereload.com\/\" rel=\"nofollow noopener\" target=\"_blank\">LiveReload<\/a>\u00a0has been a decent choice for many for this very purpose but, let me introduce you to another incredible automation tool i.e. the <a href=\"https:\/\/www.browsersync.io\/\" rel=\"nofollow noopener\" target=\"_blank\">BrowserSync<\/a>. In this post, I am going to discuss how does BrowserSync works and\u00a0which features make it stand out of the lot.<\/p>\n<h2>Synchronized Browser Testing With BrowserSync<\/h2>\n<p>[ecko_fullpage_image]<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-1190\" src=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.54.36.png\" alt=\"\" width=\"2560\" height=\"866\" srcset=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.54.36.png 2560w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.54.36-300x101.png 300w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.54.36-768x260.png 768w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.54.36-1024x346.png 1024w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.54.36-1920x650.png 1920w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.54.36-1680x568.png 1680w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.54.36-1240x419.png 1240w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.54.36-860x291.png 860w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.54.36-680x230.png 680w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.54.36-500x169.png 500w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.54.36-400x135.png 400w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.54.36-200x68.png 200w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.54.36-50x17.png 50w\" sizes=\"(max-width: 2560px) 100vw, 2560px\"><\/p>\n<p>[\/ecko_fullpage_image]<\/p>\n<p><strong><a href=\"https:\/\/browsersync.io\/\" rel=\"nofollow noopener\" target=\"_blank\">BrowserSync<\/a><\/strong> is an intuitive automation tool which helps to speed up your web development. It synchronizes all forms of file modifications and even interactions across numerous display screens.<\/p>\n<p>If you&#8217;re not using BrowserSync to automate your workflow, then you&#8217;re certainly missing out something. It has become an indispensable tool for many web developers and has also helped me improve efficiency and reduce cross-browser inconsistencies.<\/p>\n<p>I completely understand how frustrating it can become to monitor every single change but thanks to BrowserSync whose amazing feature-set helps you to get through it all too quickly.<\/p>\n<h2>Working<\/h2>\n<p>Earlier, whenever you made any changes in your files, you&#8217;ll have to perform a manual reload in your browser. BrowserSync not only detects any type of file changes but also reloads it automatically \u2014 and that too in a fraction of a second. Also if your changes are too small, then\u00a0it will inject them inside the site, without even reloading it. This entire process saves ample time and increases your productivity.<\/p>\n<p>BrowserSync also injects a JavaScript file on every web page. This helps to improve the communication between the client and the server to watch changes in your code or browser action. So whenever a change is detected, it performs a live page reload.<\/p>\n<h3>BrowserSync For Both Static &amp; Dynamic Websites<\/h3>\n<p>BrowserSync works exceptionally well for both static and dynamic sites.<\/p>\n<ul>\n<li>For static web pages, it&#8217;ll create\u00a0an HTTP server which runs your site on the localhost with a particular port.<\/li>\n<li>For dynamic websites, where you&#8217;re running your project on platforms like DesktopServer, things become a little different. Here, the BrowserSync serves as a proxy to boost your dynamic server.<\/li>\n<\/ul>\n<h2>Features<\/h2>\n<p>BrowserSync is equipped with multiple handy features like:<\/p>\n<ul>\n<li><strong>Live Reloading:\u00a0<\/strong>Having the ability to perform live reload on every single file change, is definitely the most important element of BrowserSync. This auto reload feature helps you test multiple things in one go.<\/li>\n<li><strong>Tunneling<\/strong>: The tunneling is yet another distinguishing feature of BrowserSync which allows you to show any of your on-going projects to your teammates or friends. You&#8217;ll just need to change the port and create a tunnel through a random public URL. This randomly generated URL is provided by the BrowserSycn itself.<\/li>\n<li><strong>CSS Injection<\/strong>: It watches all the CSS files and in the case of any change, updates all the connected browsers without letting any web page to reload.<\/li>\n<li><strong>Consolidated Synchronization:<\/strong>\u00a0BrowserSync offers an interacted synchronization i.e. it mirrors all the changes on all the browsers and devices.<\/li>\n<li><strong>Simulate Slower Internet Connections: <\/strong>Figuring out how your site will perform on poor internet speed is an interesting aspect which BrwoserSync has addressed smartly. It offers a feature which you can use to throttle your site connection speed.<\/li>\n<li><strong>Logging URL History:<\/strong> BrowserSync logs all browsing history so you can push a test URL to all devices.<\/li>\n<li><strong>Integration with Tools:<\/strong> BrowserSync quickly gets integrated with third-party development tools like Gulp and Grunt.<\/li>\n<\/ul>\n<h2>A Basic Implementation of BrowserSync<\/h2>\n<p>It\u2019s incredibly simple to get started with a basic setup of BrowserSync. Just follow the steps which I am going to list.<\/p>\n<h3>Install NodeJS &amp; NPM<\/h3>\n<p>Tools like BrowserSync are the node modules. Hence,\u00a0you should have NPM installed already. If you don\u2019t,\u00a0then do it now with the following commands.<\/p>\n<pre class=\"lang:sh decode:true crayon-selected\">node -v\r\n# v7.10.0\r\n\r\nnpm -v\r\n# 4.2.0<\/pre>\n<h3>Installing BrowserSync<\/h3>\n<p>To install BrwoserSync globally, type in your terminal:<\/p>\n<pre class=\"lang:sh decode:true crayon-selected\">npm install -g browser-sync<\/pre>\n<p>The next step is to confirm the successful completion of its setup. This can be done by using the following command.<\/p>\n<pre class=\"lang:sh decode:true\">browser-sync --version\r\n<\/pre>\n<p>Make sure you get the most recent version. In my case, it is\u00a0version 2.18.12.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-1186\" src=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.29.02.png\" alt=\"\" width=\"1234\" height=\"430\" srcset=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.29.02.png 1234w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.29.02-300x105.png 300w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.29.02-768x268.png 768w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.29.02-1024x357.png 1024w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.29.02-860x300.png 860w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.29.02-680x237.png 680w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.29.02-500x174.png 500w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.29.02-400x139.png 400w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.29.02-200x70.png 200w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.29.02-50x17.png 50w\" sizes=\"(max-width: 1234px) 100vw, 1234px\"><\/p>\n<h3>Running BrowserSync<\/h3>\n<p>When it comes to the actual working of BrowserSync, then I&#8217;ve already mentioned that it depends upon whether you&#8217;re working with static or dynamic websites. Let me write the commands for both of these.<\/p>\n<p><strong>For Static Websites:<\/strong><\/p>\n<p>While working with a static website, just open the root folder and type the following in your terminal:<\/p>\n<pre class=\"lang:sh decode:true\">browser-sync start --server --files \"**\/*\"<\/pre>\n<p>This command lets BrowserSync watch all kinds of files and report any changes.<\/p>\n<p><strong>For Dynamic Websites:<\/strong><\/p>\n<p>As far as dynamic sites are concerned, the BrowserSync now behaves as a proxy server. Now its command will be like:<\/p>\n<pre class=\"lang:sh decode:true\">browser-sync start --proxy \"local.dev\" --files \"**\/*\"<\/pre>\n<p>And\u00a0BrowserSync will start watching your dynamic site for changes.<\/p>\n<h3>Tunneling<\/h3>\n<p>Now it&#8217;s time to explain how you can share and showcase a work-in-progress project with its tunneling feature.<\/p>\n<p>Each time you start BrowserSync, just enter the &#8220;<code>-- tunnel<\/code>&#8221; argument to it like:<\/p>\n<pre class=\"lang:sh decode:true\">browser-sync start --proxy \"local.dev\" --files \"**\/*\" --tunnel<\/pre>\n<p>This command provides you with a set of the following information:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-1187\" src=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.40.09.png\" alt=\"\" width=\"1416\" height=\"652\" srcset=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.40.09.png 1416w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.40.09-300x138.png 300w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.40.09-768x354.png 768w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.40.09-1024x472.png 1024w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.40.09-1240x571.png 1240w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.40.09-860x396.png 860w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.40.09-680x313.png 680w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.40.09-500x230.png 500w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.40.09-400x184.png 400w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.40.09-200x92.png 200w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/Screenshot-2017-06-06-13.40.09-50x23.png 50w\" sizes=\"(max-width: 1416px) 100vw, 1416px\"><\/p>\n<p>All these are the clickable URLs which can be shared both locally and globally. However, the URL for the BrowserSync UI&#8217;s has some fascinating facts to reveal. Click this link, and you&#8217;ll be directed to a new browser window from where you can configure all the BrwoserSync settings.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-1188\" src=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/FxJxJfL.png\" alt=\"\" width=\"2560\" height=\"1374\" srcset=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/FxJxJfL.png 2560w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/FxJxJfL-300x161.png 300w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/FxJxJfL-768x412.png 768w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/FxJxJfL-1024x550.png 1024w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/FxJxJfL-1920x1031.png 1920w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/FxJxJfL-1680x902.png 1680w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/FxJxJfL-1240x666.png 1240w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/FxJxJfL-860x462.png 860w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/FxJxJfL-680x365.png 680w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/FxJxJfL-500x268.png 500w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/FxJxJfL-400x215.png 400w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/FxJxJfL-200x107.png 200w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/FxJxJfL-50x27.png 50w\" sizes=\"(max-width: 2560px) 100vw, 2560px\"><\/p>\n<h2>Wrapping Up!<\/h2>\n<p>Apart from this, BrowserSync offers several other exciting features like\u00a0<a href=\"http:\/\/www.browsersync.io\/docs\/options\/\" rel=\"nofollow noopener\" target=\"_blank\">options<\/a>, <a href=\"http:\/\/www.browsersync.io\/docs\/api\/\" rel=\"nofollow noopener\" target=\"_blank\">API<\/a>, and <a href=\"http:\/\/www.browsersync.io\/docs\/recipes\/\" rel=\"nofollow noopener\" target=\"_blank\">recipes<\/a>\u00a0which you can find on their website.<\/p>\n<p>Having the ability to perform all the actions which I&#8217;ve listed above, BrowserSync has helped me become a better developer and has brought consistency in my workflow.<\/p>\n<div class=\"post\">\n<article class=\"post-content\">The <a href=\"https:\/\/twitter.com\/browsersync\" rel=\"nofollow noopener\" target=\"_blank\">team<\/a> behind BrowserSync is kind of cool and is doing some great stuff. Now it&#8217;s your turn to step up your development with this tool. Try it out and let me know through comments. You can also reach out to me through my Twitter (<a class=\"ProfileHeaderCard-screennameLink u-linkComplex js-nav\" href=\"https:\/\/twitter.com\/MaedahBatool\" rel=\"nofollow noopener\" target=\"_blank\"><span class=\"username u-dir\" dir=\"ltr\">@<b class=\"u-linkComplex-target\">MaedahBatool<\/b><\/span><\/a>) account.<\/article>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>As a matter of fact let&#8217;s accept that developers hate doing grunt work. Instead of repeating things again and again, a pro web developer believes in hardcore automation and would love to invest time in automating things. WordPress site setup and browser testing strongly support the DRY \u2014 Don&#8217;t Repeat Yourself philosophy and encourage you [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":1194,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":""},"categories":[18],"tags":[],"coauthors":[],"jetpack_featured_media_url":"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/06\/BrowserSync.jpg","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/posts\/1181"}],"collection":[{"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/comments?post=1181"}],"version-history":[{"count":0,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/posts\/1181\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/media\/1194"}],"wp:attachment":[{"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/media?parent=1181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/categories?post=1181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/tags?post=1181"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/coauthors?post=1181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}