{"id":33,"date":"2016-08-31T12:18:12","date_gmt":"2016-08-31T09:18:12","guid":{"rendered":"http:\/\/iamakulov.com\/notes2\/?p=33"},"modified":"2017-05-09T22:09:41","modified_gmt":"2017-05-09T19:09:41","slug":"ui-testing-selenium-mocking-ajax-likely","status":"publish","type":"post","link":"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/","title":{"rendered":"UI testing, Selenium, mocking AJAX requests and Likely"},"content":{"rendered":"<p><a href=\"http:\/\/ilyabirman.net\/projects\/likely\">Likely<\/a> are well-designed social buttons:<\/p>\n<p><a href=\"http:\/\/ilyabirman.net\/projects\/likely\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/iamakulov.com\/notes2\/wp-content\/uploads\/2017\/05\/687474703a2f2f692e696d6775722e636f6d2f697071453554752e706e671.png\" alt=\"\" width=\"964\" height=\"451\" class=\"alignnone size-full wp-image-34\" srcset=\"https:\/\/iamakulov.com\/notes2\/wp-content\/uploads\/2017\/05\/687474703a2f2f692e696d6775722e636f6d2f697071453554752e706e671.png 964w, https:\/\/iamakulov.com\/notes2\/wp-content\/uploads\/2017\/05\/687474703a2f2f692e696d6775722e636f6d2f697071453554752e706e671-300x140.png 300w, https:\/\/iamakulov.com\/notes2\/wp-content\/uploads\/2017\/05\/687474703a2f2f692e696d6775722e636f6d2f697071453554752e706e671-768x359.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><\/p>\n<p>I\u2019m currently working on covering them with UI tests using Selenium. So far, several notes:<\/p>\n<ul>\n<li><strong>Selenium is cross-platform, but different platforms support different sets of functionality.<\/strong> Node.js isn\u2019t the most complete one, unfortunately. If you google how to do something with Selenium, find a StackOverflow reply with the Java API and try to do the same in JavaScript, don\u2019t expect it will definitely work. That API could just be absent.<\/p>\n<\/li>\n<li>\n<p><strong>Selenium 3 is coming, but most tutorials focus on Selenium 2.<\/strong> Selenium 2 was released in 2011, and version 3 is expected to be released this year. In fact, the <a href=\"https:\/\/www.npmjs.com\/package\/selenium-webdriver\"><em>selenium-webdriver<\/em> npm package<\/a> already installs <em>3.0.0-beta.2<\/em>. There\u2019re <a href=\"https:\/\/github.com\/SeleniumHQ\/selenium\/blob\/master\/javascript\/node\/selenium-webdriver\/CHANGES.md\">no major breaking changes<\/a> between 2.53.2 and 3.0.0, but expect that some tutorial code could just not work.<\/p>\n<\/li>\n<li>\n<p><strong>The selenium docs are scattered between different places<\/strong>, and it\u2019s hard to find the right thing when you\u2019re googling something. One part of the documentation is at <em>docs.seleniumhq.org<\/em>, another is in the repository wiki, etc. It was quite hard to find the proper actual API docs for JavaScript, so here are they: <a href=\"http:\/\/seleniumhq.github.io\/selenium\/docs\/api\/javascript\/\">http:\/\/seleniumhq.github.io\/selenium\/docs\/api\/javascript\/<\/a><\/p>\n<\/li>\n<li>\n<p><strong>Mock the external services when doing integration tests.<\/strong> When testing the sharing counters, we rely on responses from the social networks. Turns out these services don\u2019t always work well (especially Facebook and Google+) which makes the tests fail. <a href=\"https:\/\/twitter.com\/vitkarpov\/\">Viktor Karpov<\/a> suggested to mock the responses, and it seems it\u2019s a default way of doing the integration tests which I didn\u2019t know. I\u2019m working on this now.<\/p>\n<\/li>\n<li>\n<p><strong>Mocking AJAX requests with Selenium is hard.<\/strong> I need to mock them to simulate the social network responses (see the previous point). So far, I\u2019ve only found two libraries that can help with this: Sinon.js and xhr-mock. <a href=\"http:\/\/sinonjs.org\/\">Sinon.js<\/a> is popular and heavily featured, but it has <a href=\"http:\/\/sinonjs.org\/docs\/#server\">quite a complex API<\/a>, and I haven\u2019t yet succeeded in making it work. <a href=\"https:\/\/github.com\/jameslnewell\/xhr-mock\">xhr-mock<\/a> is way simpler and can also mock only specific URLs (which is more complicated with Sinon), but it <a href=\"https:\/\/github.com\/jameslnewell\/xhr-mock\/issues\/13\">doesn\u2019t support <em>XMLHttpRequest.prototype.addEventListener<\/em><\/a> and doesn\u2019t have a UMD build. Sadly.<\/p>\n<\/li>\n<\/ul>\n<p>You can follow the pull request I\u2019m working in to stay tuned (and see how we manage to do the AJAX mocking): <a href=\"https:\/\/github.com\/ilyabirman\/Likely\/pull\/73\">https:\/\/github.com\/ilyabirman\/Likely\/pull\/73<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Likely are well-designed social buttons: I\u2019m currently working on covering them with UI tests using Selenium. So far, several notes: Selenium is cross-platform, but different platforms support different sets of functionality. Node.js isn\u2019t the most complete one, unfortunately. If you google how to do something with Selenium, find a StackOverflow reply with the Java API &hellip; <a href=\"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;UI testing, Selenium, mocking AJAX requests and Likely&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3,4,5],"class_list":["post-33","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-likely","tag-selenium","tag-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>UI testing, Selenium, mocking AJAX requests and Likely - Ivan Akulov\u2019s 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:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"UI testing, Selenium, mocking AJAX requests and Likely - Ivan Akulov\u2019s blog\" \/>\n<meta property=\"og:description\" content=\"Likely are well-designed social buttons: I\u2019m currently working on covering them with UI tests using Selenium. So far, several notes: Selenium is cross-platform, but different platforms support different sets of functionality. Node.js isn\u2019t the most complete one, unfortunately. If you google how to do something with Selenium, find a StackOverflow reply with the Java API &hellip; Continue reading &quot;UI testing, Selenium, mocking AJAX requests and Likely&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/\" \/>\n<meta property=\"og:site_name\" content=\"Ivan Akulov\u2019s blog\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/iamakulov.page\" \/>\n<meta property=\"article:published_time\" content=\"2016-08-31T09:18:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-05-09T19:09:41+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/iamakulov.com\/notes2\/wp-content\/uploads\/2017\/05\/687474703a2f2f692e696d6775722e636f6d2f697071453554752e706e671.png\" \/>\n<meta name=\"author\" content=\"Ivan Akulov\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@iamakulov\" \/>\n<meta name=\"twitter:site\" content=\"@iamakulov\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ivan Akulov\" \/>\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\":\"WebPage\",\"@id\":\"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/\",\"url\":\"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/\",\"name\":\"UI testing, Selenium, mocking AJAX requests and Likely - Ivan Akulov\u2019s blog\",\"isPartOf\":{\"@id\":\"https:\/\/iamakulov.com\/notes\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/iamakulov.com\/notes2\/wp-content\/uploads\/2017\/05\/687474703a2f2f692e696d6775722e636f6d2f697071453554752e706e671.png\",\"datePublished\":\"2016-08-31T09:18:12+00:00\",\"dateModified\":\"2017-05-09T19:09:41+00:00\",\"author\":{\"@id\":\"https:\/\/iamakulov.com\/notes\/#\/schema\/person\/ebf7b61bf573e7be5fe438f50ebd9b81\"},\"breadcrumb\":{\"@id\":\"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/#primaryimage\",\"url\":\"http:\/\/iamakulov.com\/notes2\/wp-content\/uploads\/2017\/05\/687474703a2f2f692e696d6775722e636f6d2f697071453554752e706e671.png\",\"contentUrl\":\"http:\/\/iamakulov.com\/notes2\/wp-content\/uploads\/2017\/05\/687474703a2f2f692e696d6775722e636f6d2f697071453554752e706e671.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/iamakulov.com\/notes\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"UI testing, Selenium, mocking AJAX requests and Likely\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/iamakulov.com\/notes\/#website\",\"url\":\"https:\/\/iamakulov.com\/notes\/\",\"name\":\"Ivan Akulov\u2019s blog\",\"description\":\"Ivan Akulov writes about his front-end experience, React, webpack, and performance optimizations.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/iamakulov.com\/notes\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/iamakulov.com\/notes\/#\/schema\/person\/ebf7b61bf573e7be5fe438f50ebd9b81\",\"name\":\"Ivan Akulov\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/iamakulov.com\/notes\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/aec4e9e944911b58f2c3d14b7f9e5412a217e5738359c3f52e824b4de2b2263c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/aec4e9e944911b58f2c3d14b7f9e5412a217e5738359c3f52e824b4de2b2263c?s=96&d=mm&r=g\",\"caption\":\"Ivan Akulov\"},\"description\":\"I'm a software engineer specializing in web performance, JavaScript, and React. I\u2019m also a Google Developer Expert. I work at Framer.\",\"sameAs\":[\"http:\/\/iamakulov.com\",\"https:\/\/x.com\/iamakulov\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"UI testing, Selenium, mocking AJAX requests and Likely - Ivan Akulov\u2019s 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:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/","og_locale":"en_US","og_type":"article","og_title":"UI testing, Selenium, mocking AJAX requests and Likely - Ivan Akulov\u2019s blog","og_description":"Likely are well-designed social buttons: I\u2019m currently working on covering them with UI tests using Selenium. So far, several notes: Selenium is cross-platform, but different platforms support different sets of functionality. Node.js isn\u2019t the most complete one, unfortunately. If you google how to do something with Selenium, find a StackOverflow reply with the Java API &hellip; Continue reading \"UI testing, Selenium, mocking AJAX requests and Likely\"","og_url":"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/","og_site_name":"Ivan Akulov\u2019s blog","article_publisher":"http:\/\/facebook.com\/iamakulov.page","article_published_time":"2016-08-31T09:18:12+00:00","article_modified_time":"2017-05-09T19:09:41+00:00","og_image":[{"url":"http:\/\/iamakulov.com\/notes2\/wp-content\/uploads\/2017\/05\/687474703a2f2f692e696d6775722e636f6d2f697071453554752e706e671.png"}],"author":"Ivan Akulov","twitter_card":"summary_large_image","twitter_creator":"@iamakulov","twitter_site":"@iamakulov","twitter_misc":{"Written by":"Ivan Akulov","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/","url":"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/","name":"UI testing, Selenium, mocking AJAX requests and Likely - Ivan Akulov\u2019s blog","isPartOf":{"@id":"https:\/\/iamakulov.com\/notes\/#website"},"primaryImageOfPage":{"@id":"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/#primaryimage"},"image":{"@id":"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/#primaryimage"},"thumbnailUrl":"http:\/\/iamakulov.com\/notes2\/wp-content\/uploads\/2017\/05\/687474703a2f2f692e696d6775722e636f6d2f697071453554752e706e671.png","datePublished":"2016-08-31T09:18:12+00:00","dateModified":"2017-05-09T19:09:41+00:00","author":{"@id":"https:\/\/iamakulov.com\/notes\/#\/schema\/person\/ebf7b61bf573e7be5fe438f50ebd9b81"},"breadcrumb":{"@id":"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/#primaryimage","url":"http:\/\/iamakulov.com\/notes2\/wp-content\/uploads\/2017\/05\/687474703a2f2f692e696d6775722e636f6d2f697071453554752e706e671.png","contentUrl":"http:\/\/iamakulov.com\/notes2\/wp-content\/uploads\/2017\/05\/687474703a2f2f692e696d6775722e636f6d2f697071453554752e706e671.png"},{"@type":"BreadcrumbList","@id":"https:\/\/iamakulov.com\/notes\/ui-testing-selenium-mocking-ajax-likely\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/iamakulov.com\/notes\/"},{"@type":"ListItem","position":2,"name":"UI testing, Selenium, mocking AJAX requests and Likely"}]},{"@type":"WebSite","@id":"https:\/\/iamakulov.com\/notes\/#website","url":"https:\/\/iamakulov.com\/notes\/","name":"Ivan Akulov\u2019s blog","description":"Ivan Akulov writes about his front-end experience, React, webpack, and performance optimizations.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/iamakulov.com\/notes\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/iamakulov.com\/notes\/#\/schema\/person\/ebf7b61bf573e7be5fe438f50ebd9b81","name":"Ivan Akulov","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/iamakulov.com\/notes\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/aec4e9e944911b58f2c3d14b7f9e5412a217e5738359c3f52e824b4de2b2263c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/aec4e9e944911b58f2c3d14b7f9e5412a217e5738359c3f52e824b4de2b2263c?s=96&d=mm&r=g","caption":"Ivan Akulov"},"description":"I'm a software engineer specializing in web performance, JavaScript, and React. I\u2019m also a Google Developer Expert. I work at Framer.","sameAs":["http:\/\/iamakulov.com","https:\/\/x.com\/iamakulov"]}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/iamakulov.com\/notes\/wp-json\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iamakulov.com\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iamakulov.com\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iamakulov.com\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iamakulov.com\/notes\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":3,"href":"https:\/\/iamakulov.com\/notes\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"predecessor-version":[{"id":37,"href":"https:\/\/iamakulov.com\/notes\/wp-json\/wp\/v2\/posts\/33\/revisions\/37"}],"wp:attachment":[{"href":"https:\/\/iamakulov.com\/notes\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iamakulov.com\/notes\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iamakulov.com\/notes\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}