7 ms·
For automated testing, why Puppeteer instead of Selenium?
by sebazzz 7y ago
For automated testing, why Puppeteer instead of Selenium?
- d33 7y agoMuch better access to low-level information. You can hook (and mock) requests, see what POST data was sent and basically do lots of magic. Also, my experience with Selenium under Python is that doing anything bigger quickly turns into one giant timing hack.
- rat87 7y agoback when I did selenium (with python) I wait-ed for the wait for next page to load (html element becomes stale) and for textbox/checkbox/etc. you are selecting to be present with a few tiny helper functions. That took most of the magic sleeps out although I still needed timeouts on the waits
- HunOL 7y agoIf it really E2E from user perspective you shouldn't doing any magic and manipulate POST data.
- danShumway 7y agoYou're not technically wrong, but unit/integration/E2E are not hard categories for tests, they're just points along a continuum. Sometimes I want to directly control a browser to run a test or examine a UI component, but I still want to mock parts of my application. This is one of the biggest weaknesses with Selenium -- it takes a very narrow view of what testing is, so it becomes much less useful as soon as you're trying to do anything interesting. Different applications call for different testing strategies. Selenium could be a low-level browser controller that allows you to write strict E2E tests, but instead it's a low-level browser controller that is almost fanatical about only supporting strict E2E tests, even when it means that basic actions need to be more complicated. I think that's a design mistake, but whatever.
- Qerub 7y ago> Sometimes I want to directly control a browser to run a test or examine a UI component, but I still want to mock parts of my application. If you're building a SPA, you can mock out the backend and control the backend mock behaviour in your Selenium test.
- danShumway 7y agoIt's not that Selenium makes it impossible to do things like this, it's that it makes it arbitrarily harder. If you want to do something like request interception, you have to point your front-end at a proxy server and mock things there. If you want to test a file upload, you have to simulate typing into the dialog and then use a literal file on the disk. It's just pointless friction for most testing setups. It's not that E2E testing is bad, it's that in some projects there's room for a Selenium-style tool across the entire spectrum from E2E testing to unit testing; particularly if I'm testing something like D3 code, or parts of a CSS layout. It's all doable, it's just that Selenium makes it all needlessly difficult, because its point-of-view is that your front-end should be treated mostly like a black box, and that any mocking that does exist should be happening via endpoints and application connectors. I like Selenium -- I prefer using an Open protocol over Puppeteer. I just feel like that protocol could use a lot more design work.
- bluntfang 7y ago>This is one of the biggest weaknesses with Selenium -- it takes a very narrow view of what testing is Selenium/WebDriver isn't a testing tool. It's a a W3C protocol for remote control of web browsers. I think once you get over that misconception, selenium starts to make a lot more sense.
- danShumway 7y agoThat still doesn't explain to me design decisions like how WebDriver's file upload works. If I'm remote-controlling a browser over a network, wouldn't I occasionally want to send it an arbitrary file upload? Why do I need to separately transfer the file using a different service, and then refer to it with the disk path? The only reason I can think of is, "normal users couldn't do that." But normal users also can't control a browser over a network. There's no reason to restrict a control protocol to only things that normal users can do.
- deleted 7y ago[deleted]
- Tinfoilhat666 7y agoDoes puppeteer work with Safari and MS browsers or is it another Chrome only tool (and now Firefox)?
- leadingthenet 7y agoIt's yet another Chrome only tool.
- hans-claasen 7y agoIt works very well for Microsoft Edge too (latest DEV version of it) - https://github.com/GoogleChrome/puppeteer/issues/4185#issuecomment-511648269 https://github.com/GoogleChrome/puppeteer/issues/4185#issuec...
- oneshore 7y agoYou mean it will work with Microsoft Edge when Microsoft Edge becomes Chrome.
- azangru 7y agoJavascript-based instead of java-based api?
- rehemiau 7y agoSelenium / WebDriver has a HTTP API so you can have clients in any language, not just in Java
- canada_dry 7y agoIt would be awesome to have Puppeteer support Python... then I'd drop Selenium from my toolbox.
- pmdarrow 7y agoMy company is using https://github.com/miyakogi/pyppeteer https://github.com/miyakogi/pyppeteer in production and it has worked great. I suggest checking it out.
- ozim 7y agoI am done with selenium because you cannot make stable tests. They are always flaky.
- tnolet 7y agoJust download both and try doing the same test suite. See which one hurts the least. I'm 99% sure Puppeteer will feel like a breath of fresh air to you. CasperJS was OK, even better with Nightwatch but Puppeteer is quicker, more stable and actively developed.
- mceachen 7y agoThat was what I found, as well, for my PhotoStructure tests. It's great to have them driven by gitlab's ci and have cross-platform tests run automatically, and it will be great to now have them run cross-browser, as well.
- XCSme 7y agoSelenium feels old and outdated, it's always a hustle to install it/get it running and I have to use WebdriverIO with it in Node. I tried Puppeteer a few days ago, I just did `npm i puppeteer` and it worked as expected.
- ppf 7y agoHow would you describe the npm install process?
- mceachen 7y agoJust like any other module, but slower. There's a substantial bag of bits it needs to fetch (chromium), but that's cached. I've also noticed that sometimes (in CI, less than 5% of the runs) the installation or run will fail deep in chromium. It's actually spawning a chrome process and tunneling remote commands to the child process to do work, so, I guess the flakiness is (almost) excusable? Restarting the test always resolves the issue, fwiw.
- jamesgeck0 7y agoYou can install Puppeteer without downloading the bundled Chromium (PUPPETEER_SKIP_CHROMIUM_DOWNLOAD env variable), but you need to be careful to use it with a version of Chrome/Chromium that has a compatible dev tools api version. I too have experienced flakiness in CI where Chrome doesn't always seem to start or quit within a reasonable amount of time. I get around this in production with timeouts that give any lingering Chrome processes a series of increasingly aggressive requests to quit, but my hosted CI environment doesn't like it when I send kill signals to random PIDs. I'm hoping that this Firefox client will be somewhat more reliable in that regard.
- ppf 7y agoI meant installing npm itself.
- XCSme 7y agoSimple, 0 configuration, fast. With a new installation of Selenium I always have to download the Firefox/Chrome drivers, have to setup paths, debug startup erros, plus it crashes pretty often.
- kbumsik 7y agoPuppeteer covers more browser-native features. For example Puppeteer can capture HTTP traffics.
- paulryanrogers 7y agoWith WebDriver becoming a standard it's sad the browser vendors didn't work together to improve that. Instead Google made their own thing and now the world has to follow
- eternalny1 7y agoAgreed. Any idea why Google didn't work with WebDriver and decided to spin-off yet another homegrown tech? My conspiracy-laden mind veers towards the obvious but I'd prefer a better explanation.
- swsieber 7y agoI'm using puppeteer at work to dump dom changes, console logs, network requests, css and images to create a test bundle that can be replayed with a test bundle viewer (ie. move the slider to move the browser view of the test through the changes). Puppeteer is powerful enough to let that happen! And overall Puppeteer has caused us less headaches than Selenium