Best framework to functional test a javascript-injecting bookmarklet - node.js

I've developed a bookmarklet that injects some javascript code to a page and I need to write some functional test to test it. Because this is a bookmarklet so I don't have any html files. It will just open another existing website and inject the javascript to that website. I have looked at mocha, selenium-webdriver and Phantomjs, but I just don't which are the best ways to test my bookmarklet.

Have a look at Sakuli. It combines two Open Source test automation tools (Sahi and Sikuli) and lets you test web applications as well as non-web content (e.g. for 100% GUI e2e tests). Both tools can be used in mixed operation.
You can also run Sakuli within Docker containers.

Related

What is the difference between Geb and Spock testing frameworks

I'm new in the area of software developing, and want to extend my knowledge over automation testing. I read a lot for Geb and Spock testing frameworks, but did not come to the conclusion for what purpose are they.
Am I correct:
Geb is for Page Objects (static covering the UI pages selectors, elements, etc.)
Spock is for writing the test order (Cases/Steps for test) (also is able to run API tests as well, mock data, parameterised endpoints, values and etc.)
--> What other differences they have? I already checked both documentations, but cannot understand.
I will appreciate every practical advice or example, differences between both as well, because I covered a lot of things, but there are only theoretical examples, but the main catch I did not get it.
Thank you in advance!
Geb is a browser/web automation solution. You can use it to test the functionality of your web pages. Geb can automatically launch a web page, fill out form fields and click buttons on a web page. From the official website:
"It can be used for scripting, scraping and general automation — or equally as a functional/web/acceptance testing solution via integration with testing frameworks such as Spock, JUnit & TestNG."
The catch for Geb is web automation.
The catch for Spock is that it is testing and specification framework.
Examples
You can Geb to check the following:
When one opens mywebsite.com/login and enters a wrong username or password an error message should be displayed, say in a div.
When one opens mywebsite.com/submitData, fills in item name and price and clicks on the submit button, expect a message to show like "Thank you, the total number of items is now 5"
GEB is build on top of WebDriver library and is compatible all the Browsers and Drivers which work with WebDriver.
Most commonly used way of achieving UI automation is though implementation of Page Object Model design pattern, Geb supports Page Object Model by implementing all the boiler plate code in its 'Page' class. The custom pages in an Automation Framework are required to extend this 'Page' class in order to access ready made functions and closures.
Some Additional points:
It uses jQuery-ish navigator API to identify elements on the page.
There is a ready made 'js' object which lets you execute JavaScripts on your page.
There are closures which let you switch to another Window/iFrame/Alert of your webpage
Simplified handling of Dropdowns,Radio buttons,File Uploads,Checkboxes etc.
Introduces 'Interact' blocks which builds and perform the user actions (by utilizing Action class of Selenium WebDriver API)
geb.config file allows the developer to add support for multiple environments , drivers, Reporting , waiting etc.
Read more about Geb in the The Book of Geb
SPOCK on the other hand is a BDD Testing and Specification Framework inspired from frameworks like JUnit, jMock, RSpec, Groovy, Scala, Vulcans etc.
SPOCK is highly compatible with Geb and provides a 'GebReportingSpec' class which is required to be extended by the test classes in order to establish compatibility with Geb

What are the benefits of using Chromeless and Puppeter Over Selenium?

We are looking to replace our Selenium approach to automated web data collection and have been recommended Puppeteer or Chromeless.
One of the things I like is the ability to go headless with chrome running on AWS lambda. That reason was sold as the main reason for going with Chromeless or Puppeteer. However, I see posts online indicating that the same can be done with Selenium. If that is true, what over advantages do Chromeless and Puppeteer offer over Selenium ?
We are going to be using NodeJS
Having used both Selenium and Puppeteer, these would be my observations as to why it's currently being recommended so highly:
Puppeteer is really easy to configure and execute. No setting specific drivers required. Just write your test scripts, point node towards your scripts and watch it go. Everything even runs in parallel!
It's a zero setup framework in that it comes bundled with the version of Chromium which it runs best with.
Another benefit is speed. Puppeteer is really fast since it uses headless Chrome.
It integrates very nicely with other popular test frameworks such as jest and mocha.
Using Puppeteers API is really straightforward. Everything is simple to write, easy to understand and basically allows for simple user interactions to be automated using a single line of code.
It's really easy to debug your automation scripts. Simply set headless to false and turn slowMo up from 0 to, say, 250 and you can easily see what's going on and fix any problems you may have.
It's easy to pick up and use no matter what your previous experience levels: on the team I'm working on, everyone (even those with no real automation test script writing experience) has found working with Puppeteer a really nice and relaxed experience. Everyone is getting the grasp of it within a few minutes of basic research and getting scripts running quickly and with no hassle or stress.
It should be noted that Selenium does do everything that Puppeteer does (and vice versa) but that's not the point of Puppeteer. Puppeteer allows for a team to build a large library of automation scripts very quickly using an easy to use API and get tests running now rather than having to deal with building ultra-robust test frameworks which work cross browser and / or cross device.
If you really must have cross browser testing then Selenium or perhaps InternJS (a personal favourite of mine) are still the choices to make.
Puppeteer only supports executing tests on Chrome but, at the end of the day, it's much better to have a lot of tests running (even if it's just on Chrome) as opposed to having none.

Dojo Build for Rhino and browser environments

is it possible to have a dojo build that works fine with rhino and browser environments.
I'm in need making server side export of dojo charts and for the server side dojo charts I'm using rhino.
This question is not very specific. The dojo build can run in node.js and rhino environment. But I assume you need a browser to run a dojo application, no matter if it is built into a 'layer' or not.
Of course -- due to the extensible nature of the dojo build system, you could do some hacks like replacing certain patterns in your code to fix some specific issues.
Maybe you could be more specific about your scenario.

Is it possible to develop Google Chrome extensions using node.js?

I'd like to start developing Google Chrome extension using node.js (since I've already written a "text-to-song" script in node.js, and I'd like to turn it into a Chrome extension.) What would be the most straightforward way of approaching this problem?
Actually it is. Look at this Developers Live-cast. This is something I've been looking for as well, and this would help you.
This brings your node applications bundled to your browser.
Here is the repo!
EDIT:
I've noticed that this old answer of mine keeps getting upvotes now and then (thank you all).
But nowadays I'm more an advocate of using web apps instead of bundling your application into many platforms like the chrome store or whatever.
You can check the google's post here and here indicating some directions.
In practice I advise for you to start building a progressive web app (PWA) with offline capabilities using service worker and progressive stuff.
There are plenty of resources around the web nowadays and you can offer a much richer application that may achieve a much broader audience if you do it the right way.
Thanks again, and good coding.
Simple answer is NO, unless you can find a way to install node.js with an extension using NPAPI.
Nodejs and a Google Chrome Extension do have a couple things in common i.e they both understand javascript and they both use the v8 javascript engine.
Google Chrome Extension
"Google Chrome Extensions are small software programs that can modify and enhance the functionality of the Chrome browser".
To develop a Google Chrome Extension you should write some javascript and or html/css.
Then you can run the extension in your browser.
If you wish for others to download your extension you will have to provide config.json file that describes you extension sets permissions etc.
Nodejs
"Node.js is a platform built on Google Chrome's JavaScript runtime for easily building fast, scalable network applications".
To develop applications in nodejs you write some javascript and or html/css for web applications.
If wish for others to use you application you start you nodejs server and listen for incoming requests.
Summary
Despite some of the similarities a Google Chrome Extension and Nodejs have nothing to with each other. You cannot use them together in some special way outside of the normal client/server communication.
You can use a WebPack (GitHub) or Browserify (see handbook) to build web-browser extension based on the node.js code.
With Browserify, to convert your code, you can simply run:
browserify node-code.js -o node-code-out.js
Read more:
Browserify vs Webpack.
Build a Chrome Extension with Preact and Webpack (see: Preact Chrome Extension Starter).

Rails Integration Testing

I'm looking to set up a bunch of integration tests for an Rails 3 app that is already built.
The app is built with Rails 3 and Ruby 1.9.2. I've seen recommendations for Capybara, Cucumber and RSpec 2 but I'm not sure what the advantages of each are.
I've also noticed that they seem to be closely tied together. The post I've seen always seem to talk about using Capybara with Cucumber, or using Rspec with Cucumber.
What are the advantages/disadvantages for each of them? Are there certain combinations that work best together?
All these test tools fall in different parts of the testing environment.
If you want to set up integration tests, then you should use Cucumber because it has no real alternative. Cucumber is designed to easy Behaviour Driven Development but even if you don't BDD it is perfect for integration testing.
Capybara mission statement is "webrat alternative which aims to support all browser simulators". So to simulate the browser part (http request, DOM manipulation, etc) you have two alternatives Webrat or Capybara. Cucumber integrates fine with both of them. In fact it detects which one you have installed in your system and by default uses it.
On the other side is Rspec. Rspec is not a tool for Integration Testing but for Unit Testing (with a BDD approach). In http://www.pragprog.com/titles/achbd/the-rspec-book it is explained very clearly. Cucumber is in an outer circle of application behaviour and rspec is in an inner circle of class behaviour. The alternative to rspec is classic Test::Unit classes.
For more information see:
Cucumber
Capybara
Webrat
RSpec
Test::Unit
In summary, use all three.
Use RSpec...
...for testing methods in your models, controllers, and helpers in isolation.
Also known as Unit testing.
Use Cucumber...
...for testing high level features of your application.
Also known as integration testing. Verifies that all the pieces work together.
Good for testing from a user's perspective.
Use Capybara with Cucumber...
...for navigating your app like a user would through the browser.
...for testing your views contain the content that a user would expect to see.

Resources