<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jay Zelenkov on Medium]]></title>
        <description><![CDATA[Stories by Jay Zelenkov on Medium]]></description>
        <link>https://medium.com/@jayzelenkov?source=rss-58a7a766b43c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*O7nT5SeSrqGJojzX6ci2AQ.jpeg</url>
            <title>Stories by Jay Zelenkov on Medium</title>
            <link>https://medium.com/@jayzelenkov?source=rss-58a7a766b43c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 02:53:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jayzelenkov/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ECMAScript 6 in depth — classes]]></title>
            <link>https://medium.com/@jayzelenkov/ecmascript-6-in-depth-classes-1ce442e0ca53?source=rss-58a7a766b43c------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ce442e0ca53</guid>
            <category><![CDATA[ecmascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Jay Zelenkov]]></dc:creator>
            <pubDate>Sun, 21 Jun 2015 16:29:05 GMT</pubDate>
            <atom:updated>2016-03-21T01:01:57.927Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a8Ump6FlDIgiz_RqXtwaZg.jpeg" /><figcaption>image copyright Kinchloe photography: <a href="http://flic.kr/p/pFw3r6"><strong>http://flic.kr/p/pFw3r6</strong></a></figcaption></figure><h2>ECMAScript 6 in depth — classes</h2><p>ECMAScript 6 brings a notion of classes. Despite the name, the new classes in JavaScript are not classes at all. This blog post is an attempt to demystify common misconceptions.</p><h3>What is a class</h3><p>In classical languages, objects are created from a blueprint. That blueprint is called a “class”. Class describes which methods and attributes should an instance of an object have, their visibility (private, public) and some other properties. When an instance of an object is created from a description of a class (the blueprint) all methods and attributes are <em>copied</em> into the resulting instance of an object. The only exception are static attributes and methods.</p><p>In JavaScript, when the <strong>new</strong> keyword is used nothing gets copied. Instead, the newly created object gets a <em>reference</em> to the function’s prototype. All values present in the prototype are not copied, they’re merely referenced. This means that all object instances constructed from the same function using <strong>new</strong> keyword will share the same prototype. If at some point one object will alter the prototype all other object instances will also see that change.</p><blockquote>In JavaScript all values present in the object prototype are not copied,<br>they are merely referenced.</blockquote><h3>What is a class in ECMAScript 6</h3><p>The new class in ECMAScript 6 specification is a syntactic sugar for working with prototypes. It doesn’t add any new features, it merely allows the easier way of using what is already available in the language.</p><p>Let’s have a look at a few examples:</p><pre><strong>function</strong> Location(lat, long) {<br>    this.lat = lat;<br>    this.long = long;<br>}</pre><pre><strong>Location.prototype.geolocation</strong> = function() {<br>    return google.whereami(this.lat, this.long);<br>}</pre><pre>// static function. Doesn’t depend on instance’s state<br><strong>Location.distance_between</strong>(first, second) {<br>    return google.distance(first.lat, first.long, second.lat, second.long);<br>}</pre><p>The same written using <strong>class</strong> notation:</p><pre><strong>class</strong> Location {<br>    constructor (lat, long) {<br>        this.lat = lat;<br>        this.long = long;<br>    }<br><br>    <strong>geolocation</strong>() {<br>        return google.whereami(this.lat, this.long);<br>    }</pre><pre>    // static function. Doesn’t depend on instance’s state<br>    <strong>static distance_between</strong>(first, second) {<br>        return google.distance(first.lat, first.long, second.lat, second.long);<br>    }<br>}</pre><p>Under the hood JavaScript runtime produces exactly the same functions. Their prototypes look the same and the static function is added directly to the <strong>Location</strong> function.</p><p>The instance of a class is created using the constructor call with <strong>new</strong> keyword, just like before:</p><pre>var here = {lat: 52.529507, long: 13.401894};<br>var oberholz = <strong>new Location</strong>(here.lat, here.long);</pre><pre><strong>oberholz.geolocation</strong>();</pre><pre>var road_home = <strong>Location.distance_between</strong>(oberholz, home);</pre><p>At the end, it is just plain old functions and prototypes.</p><h3>But…why???</h3><h4>Language evolution</h4><p>Classes provide a higher-level way to work with functions and objects. They simplify operations for rewiring the prototype chains.</p><p>Classes are fully backwards-compatible. In fact, you can mix classes and prototype chain manipulation operations as you please.</p><h4>Tooling</h4><p>Usage of the <strong>class</strong> keyword helps static analysis tools to make more sense out of our code.</p><h4>Making it easier for the new developers to join</h4><p>This is probably the biggest reason. The popularity of JavaScript is surging in recent years. More and more developers are switching to JavaScript. The notion of classes should help them get up to speed with JavaScript and start hacking away.</p><p>Developers still need to remember that classes in JavaScript are not the same as they are in C++ or Java.</p><p>They will still need learn about prototypes and constructor calls at some point. It just doesn’t need to happen on their very first day.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ce442e0ca53" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make the web browsers test for you. Part 1: Selenium WebDriver]]></title>
            <link>https://medium.com/@jayzelenkov/make-the-web-browsers-test-for-you-part-1-selenium-webdriver-d1824493f436?source=rss-58a7a766b43c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1824493f436</guid>
            <dc:creator><![CDATA[Jay Zelenkov]]></dc:creator>
            <pubDate>Wed, 16 Jul 2014 18:57:16 GMT</pubDate>
            <atom:updated>2014-07-16T18:57:16.031Z</atom:updated>
            <content:encoded><![CDATA[<h4>The missing introduction to Selenium WebDriver</h4><blockquote>This article is roughly based on <a href="https://speakerdeck.com/jzelenkov/make-your-browsers-work-for-you">the talk</a> I gave at <a href="http://frankfurtjs.org/">FrankfurtJS</a>.</blockquote><h3>Introduction</h3><p>Front end development has grown a lot in recent years. Modern websites, or rather web applications, have a lot of states and usually there is more than one way to get to the same state.</p><p>Furthermore, modern web applications are expected to run on anything from an iPhone to the 40&quot; Smart TV in your living room. Running unit tests on the JavaScript modules individually is still helpful but it is no longer enough. We should run our tests the same way our users actually interact with our web application.</p><p>Do they use the mouse, their thumbs or special keys on their remote control? Maybe a combination of everything at the same time? We should ensure that the right data is made available on different states and that transitions between pages (or states) happen as expected.</p><p>The solution is known as integration tests. Integration tests are executed in real browsers, real DOM events are triggered (<em>click, touch, submit,</em> etc) and real DOM elements are modified.</p><blockquote>Integration tests are also referred as end to end (E2E) tests.</blockquote><h3>Browsers explained</h3><p>When it comes to E2E testing we have a number of options in which browsers our tests could run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HBmM2-Zkfx8H_1Ykw_0Npg.png" /><figcaption>Browser ponies taken from <a href="https://github.com/alrra/browser-logos#browser-ponies">https://github.com/alrra/browser-logos#browser-ponies</a></figcaption></figure><h4><strong>Real</strong></h4><p>Running tests in real browsers is the best approach to E2E testing. It also requires the most time for setup and maintenance.</p><h4><strong>Headless</strong></h4><p>One of the alternatives to running tests in real browsers is headless browsers. They contain web browser engines of the real browsers. <a href="http://phantomjs.org/">PhantomJS</a> is based on WebKit browser engine and <a href="http://slimerjs.org/">SlimerJS</a> is based on Mozilla’s Gecko engine.</p><blockquote>SlimerJS is not a fully headless browser yet and still requires a windowing system because of nature of XULRunner applications. Furthermore, SlimerJS currently does not implement WebDriver API at all. It can be scripted either directly or using <a href="http://casperjs.org/">CasperJS</a> but that is outside of scope of this article.</blockquote><p>Headless browsers are not very good candidates for running E2E tests. Primarily because your users do not use them. Both PhantomJS and SlimerJS are based on significantly older versions of browser engines. It can happen that your E2E tests would pass in the headless browsers but fail in real ones and vice versa.</p><blockquote>PhantomJS implementation of WebDriver API is known as <a href="https://github.com/detro/ghostdriver">GhostDriver project</a>.</blockquote><h4><strong>Unreal</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*7nRH4J9Mtl0KqcCww1EpjA.png" /><figcaption>yes, the logo is real <a href="http://zombie.labnotes.org/zombie.pdf">http://zombie.labnotes.org/zombie.pdf</a></figcaption></figure><p>And then there are unreal browsers. <a href="http://zombie.labnotes.org/">ZombieJS</a> is a pseudo-browser. It is a collection of npm packages for parsing HTML, CSS, managing cookies, evaluating JavaScript code, and so on. Again, nobody really uses ZombieJS for browsing the Internet so test results could be very different from real browsers. ZombieJS does not implement WebDriver API and is mentioned here for completeness.</p><h3>A brief history of Selenium</h3><p>The initial approach for integration testing was record and play. An automation tool would record keyboard and mouse interactions storing timings between events and precise coordinates of mouse clicks.</p><p>In the year 2004 Jason Huggins came up with an idea to make a better tool for browser automation. He developed a JavaScript library that could drive interactions with the page, allowing the user to automatically rerun tests against multiple browsers. That original library is referred now as Selenium Remote Control (Selenium RC).</p><blockquote>The name Selenium comes from a joke made by the original developer in an email, mocking a competitor named Mercury, saying that you can cure mercury poisoning by taking Selenium supplements. The others that received the email took the name and ran with it.</blockquote><p>The JavasScript automation engine used by the Selenium RC was limited by security restrictions implemented in the browsers.</p><p>In 2006 a developer at Google, Simon Stewart, released a tool that spoke directly to the browser using the native method for the given browser and the operating system, thus avoiding the restrictions of a sandboxed JavaScript environment. He called it WebDriver.</p><p>In the year 2009, the two projects were merged into one. The merged project received an official name <em>Selenium WebDriver</em>.</p><h4>Selenium WebDriver name confusion</h4><p>There is a lot confusion about the terminology used in the Selenium / WebDriver world. Let’s figure it out.</p><p>Since the year 2009 all of these names refer to the same merged project:</p><ul><li>Selenium</li><li>WebDriver</li><li>Selenium WebDriver</li><li>Selenium-WebDriver</li><li>Selenium 2</li></ul><p>The version of Selenium before 2009 is now referred as:</p><ul><li>Selenium 1</li><li>Selenium RC</li><li>Selenium Legacy</li></ul><blockquote>Sometimes you might find services that say they support WebDriver but do not support Selenium. Or somebody saying “Selenium sucks but WebDriver is awesome.” They are referring to the older version of Selenium, currently known as Selenium RC.</blockquote><p>Selenium is distributed only in one form <em>as a single JAR file</em>. It contains both the new Selenium WebDriver and the legacy Selenium RC as well as many other components.</p><blockquote>Some Selenium-WebDriver components are referred by their original names, e.g. Selenium Server. In this case, Selenium-WebDriver Server is meant.</blockquote><h3>WebDriver API</h3><p>To ensure cross-browser compatibility it was decided to standardize the Selenium-WebDriver API under the name <a href="http://www.w3.org/TR/webdriver/">WebDriver API</a>.</p><p>Just like other Selenium-WebDriver components, WebDriver API also has several names. All of these terms mean the same thing:</p><ul><li>WebDriver API</li><li>WebDriver Wire Protocol</li><li>Selenese (domain-specific language)</li></ul><p>WebDriver API commands are nothing more than a specially crafted RESTful HTTP GET and HTTP POST requests containing JSON that are send to the Selenium Server. The only special case is Chromium-derived browsers which will be covered later.</p><p>Selenium Server can be running either locally or remotely occupying the port 4444 by default.</p><p>Selenium Server itself does not know how to interact with the actual browsers. It uses browser drivers to do that.</p><p>A browser driver then spawns a new browser process and instructs that process to perform certain actions. Browser driver is both browser-specific and platform-specific. That means that for example <em>ChromeDriver</em> for Windows and <em>ChromeDriver</em> for Mac OS X are two separate applications.</p><blockquote>Browser drivers are implemented very differently, following the logic: “best tool for the job”. They can be written in any programming language: C#, C++, XUL or something else. Whatever works best for the given platform and the browser.</blockquote><p>Internet Explorer and Chrome browser drivers are implemented as separate applications and distributed separately from Selenium-WebDriver project. Firefox and Safari drivers are implemented as browser extensions and are included in Selenium-WebDriver project distribution.</p><p><em>ChromeDriver</em> comes with an integrated HTTP server and can receive WebDriver API requests directly. So if you are only interested in testing Chromium-derived browsers, there is no need to download and setup Selenium Server at all. Running <em>ChromeDriver</em> alone will suffice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*79x3UCNHDtPiUpoigW7_dg.png" /></figure><p>In our test code, we send a HTTP POST request containing JSON that describes the browser action. Selenium Server receives that HTTP request and forwards it further to one or many browser drivers <em>(alternatively: ChromeDriver receives an HTTP request with the WebDriver command).</em> Browser driver uses inter-process communication or browser API and manipulates the browser to perform a certain action.</p><h3>Selenium-WebDriver JavaScript Wrapper</h3><p>To spare developers from writing raw HTTP requests manually, Selenium-WebDriver provides API wrappers for a number of programming languages. There are also unofficial wrappers available for those languages, that are not supported by Selenium WebDriver team.</p><p>Unlike all other wrappers, operations in the <a href="https://code.google.com/p/selenium/wiki/WebDriverJs">JavaScript wrapper</a> support <a href="http://wiki.commonjs.org/wiki/Promises/A">Promises/A</a> out of the box.</p><p>To illustrate what JS wrapper code looks like, let’s write our first E2E test. Our application has two pages: (1) a form to enter some text; (2) another page showing the entered text. <a href="https://gist.github.com/jzelenkov/65bfdd09abde2d60c17b">Full source is available under this link.</a></p><p>Our test performs the following actions:</p><ul><li>fills in the name in the text field</li><li>clicks a button to submit the form</li><li>waits for a transition to a new page to complete</li><li>verifies that the shown text is the same as that was entered</li></ul><p>The same in JavaScript:</p><pre>driver.findElement(webdriver.By.name(&#39;whoami&#39;))<br>    .sendKeys(&#39;WebDriver was here!&#39;);</pre><pre>driver.findElement(webdriver.By.id(&#39;greet&#39;))<br>    .click();</pre><pre>driver.findElement(webdriver.By.id(&#39;message&#39;))<br>    .getText()<br>    .then(function(val) {<br>        assert.equal(<br>            val, &#39;WebDriver was here!&#39;,<br>            &#39;Messages should be the same&#39;);<br>    });</pre><blockquote>If you are interested, <a href="https://gist.github.com/jzelenkov/65bfdd09abde2d60c17b#file-_readme-md">there is a README file under full sources link</a> that briefly explains how to get this test running.</blockquote><h3>Closing thoughts</h3><p>Selenium WebDriver offers a way to test web applications running in real browsers. The first part of the series offered an introduction to Selenium WebDriver project, an overview of its functionality and a little demo test case.</p><p>Stay tuned for the second part! We will cover some of the popular higher-level WebDriver API JavaScript wrappers. They look similar to the default wrapper but allow you to write more concise commands. Or even replace two or more WebDriver commands with just a single one.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1824493f436" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>