using puppeteer or puppeteer-core in cli script - node.js

I need to write a node cli script that will run some tests on the forms of a website I'm working on. I want to use puppeteer but I'm a bit confused about the difference between the full version and puppeteer-core. What is the best choice if I want to run the tests from a cli script without opening the browser and only simulating it?

To put it simply, puppeteer-core is for when you already have a browser and don't want to download a whole Chromium which the main puppeteer package does, automatically.
It is better to go with the full puppeteer since this way you will be getting the "batteries included, tested and are guaranteed to work" experience.
Official documentation offers a detailed comparison.

Related

NodeJS: using chrome-remote-interface instead puppeteer

I have a project which uses puppeteer to print PDFs, the problem is the download of chromium is too large to work with servers, so I want to migrate it to chrome-remote-interface instead. There is a better way to do that? I will change too much my code?
You don't even need to switch to such libraries for this problem. Puppeteer already has solution for that.
puppeteer-core
Puppeteer has puppeteer-core library which is without the chrome download and will work with remote interface.
The only difference between puppeteer-core and puppeteer atm is that puppeteer-core doesn't install chromium. So you can just swipe it.
The original difference is described here. The document for .connect is here.
Using the environment variable
You can use puppeteer as usual, except provide PUPPETEER_SKIP_CHROMIUM_DOWNLOAD environment variable to skip the download when doing npm install.

Headless browser automation app via electron js app

I would like to create an electron app that can do some web automation based on user input into a GUI. In my research it seems my two best bets are Phantom and Selenium+Chromedriver.
The thing I'd like to do is have an app that someone else could download and run without any additional setup. It seems with Chromedriver and Phantom that I'd need to have others download and add these things to their PATH. In order to get things functioning.
Is there a way around this? Or is there another approach I should be taking? Any advice is appreciated. Thanks!
First off, you should have a look at Nightmare.js which is like PhantomJS in many ways, but uses Electron under the hood (and that's good, because Chromium in Electron is very fresh compared to PhantomJS engine).
If you still want to use PhantomJS in Electron that's quite fine too. You may bundle it with your application or install npm module as a dependency and require that in your script. The main thing is - PhantomJS will be installed together with your app and you know the path to that folder.

How can I run a Chrome extension in NW.js?

This question is pretty short and self explanatory. I'm wondering how I can run my Chrome extension in NW.js.
I know you can run an app in NW.js and I think you can run extensions as well?
I can't find much on the topic. Back in 2013 the way to do it seemed to be:
nw [path to manifest.json] --load-extension
Any ideas are appreciated!
Yes you can.
First off, download the extension you want. For this example I'll be using this debugging tool, which adds an additional tab in the dev tools window.
Inside your NW.js package.json file, ensure you have an entry called chromium-args.
Ensure its value contains --enable-extensions --load-extension=relative_path_to_extension_manifest.
My package.json looks like this:
After restarting the application, the extension shows up as expected:
Something I'll add is that the full Chrome API might not be available to you. I couldn't find info about what NW.js supports, but Electron definitely does not support the entire API, so this might have similar restrictions.
I also noticed you mention in the comments that you need to assign a hotkey of sorts. I'd need to know what you were trying to do, but essentially you have the option of either using a browser mechanism such as addEventListener('keydown', myHandler) or using the NW.js API depending on your exact needs.

How to test NodeJs CLI javascript

I need to put some tests around a nodejs command line utilities\modules. No browser involved and I'm using a lot of the "fs" module to work the file system, so i'm not sure a browser based test mechanism would work (sandboxing).
any modules that would help here?
Check out Vorpal.js. This lets you create an interactive CLI in node, in which you can then run custom commands to test the various things you want to test.
Disclaimer: I am its author.

Can I use PhantomJS with Cucumber-js

I've been using Zombie.js with my cucumber-js scripts but having a bit of trouble and can't get my issues resolved as of yet. It's extremely late in my game to switch to a different headless browser, but, if I can't solve my issues in zombie, I might need to make the jump.
However, I can't seem to figure out if I can integrate it into my cucumber-js scripts the way I integrated zombie. PhantomJS seems to be a standalone thing, but I need it to run as a required module.
I've scanned the documentation and can't figure out if I can do this.
Is this possible?
Yes. We created an open source package that allows you to do exactly this, it runs Phantom in GhostDriver mode so it runs without selenium.
https://github.com/xolvio/chimp
You also get synchronous javascript for Webdriver (no callbacks, no promises) ;)

Resources