I want to test my AngularJS application using Selenium and PhantomJS, but I am not finding an easy to start resource or video tutorial. Can you please suggest some good resource as a starting point.
Have you looked at this tutorial?
The tutorial itself seems decent. You might have to change some stuff depending on what you choose as your test-runner (this tutorial chose Mocha).
I'd also look at Karma and Protractor which are built by the AngularJS team.
Protractor is targeted more towards end-to-end testing in AngularJS apps.
If you're set on Selenium, you could also look at Nightwatchjs which is also end-to-end and runs against a Selenium server but requires Node.js. Nightwatchjs could be compared to Protractor but seems like it has easier-to-understand syntax.
As #Nima-Vaziri said, you should have a look at Karma to run unit tests on your app. This article will help you on this way.
Then to run e2e tests, the new runner developped by the Angular team is Protractor and you can start with this demo : Protractor demo
To understand, these docs were very useful to me:
Protractor Readme
Setting up your browser
Getting started
If you're going to work with AngularJS: you definitely should know about eggehead.io videos! This one is about Protractor. But, there's a lot of video tutorials very interesting to teach you how to build an Angular app!
Related
I am actually configuring Jenkins to make a continuous integration of a JS project with unit tests. My problem is that after many researchs I didn't found any tutorial or information about how to proceed to write unit tests in Jenkins.
Should I use other tools (grunt, ant...) with Jenkins or could it do the job alone ? Is there any important plugin to install to make it work ?
Thanks for your answers
What you're looking for is a testing framework with a JUnit Reporter. Jenkins can read your test results from the JUnit report and give you metrics from them.
Jenkins is just for handling the automation of building your code and running your tests in whatever language you need. In order to use it for that, you need to use something like Karma, Mocha, HapiJS's Lab, Unit.js, Jasmine, etc. to actually write and test with.
I'm writing an html/js (ember) chat app using socket.io as the backend. (I know: original, much?)
For some of my end to end integration tests (i.e. Client AND Server) I would like to test the interaction between two clients. I know I can get this done with selenium-webdriver and a testing framework such as mocha but I'd really like to use a nice test runner like Karma or the one that comes with QUnit and I'm a bit stumped as to how to get either of those to create and interact with two clients at once.
QUnit in itself is not a test runner. It is a testing framework. Karma on the other hand, is a test runner.
QUnit very much likes to test units of code, just as any xUnit framework does. Running integration tests in unit-testing settings is not advisable. As the comment below from Andy clearly demonstrates, QUnit can be used in different settings, but there not in the sense of an xUnit-type testing framework.
As for testing socket.io applications, this SO answer might be helpful to you?
Swizec Teller has a tutorial on testing socket.io code, and Liam Kaufman has a blog post on testing a chat application written with socket.io.
I am currently working on some test cases for my website. I've managed to test the back-end functionality using the simple-test framework.
I have some important javascript tools that requires some automatic testing. I know javascript is a client side language and it requires a browser, i am just wondering if its something i can do.
Notice the test must run from Linux CLI.
Thank you
You can install node.js with jasmine-node package to run your tests using cli:
Here's a brief intro to Jasmine:
http://net.tutsplus.com/tutorials/javascript-ajax/testing-your-javascript-with-jasmine/
And here's a tutorial on jasmine-node:
http://www.2ality.com/2011/10/jasmine.html
PS
In order to reference the code to be tested is useful to grasp how module.export works on Node.js ... here you'll find all the info you need to get started: http://jherdman.github.com/2010-04-05/understanding-nodejs-require.html (broken link) http://coppieters.blogspot.be/2013/03/tutorial-explaining-module-export.html
Jasmine is what I use for my Javascript testing. It can be found here :
https://github.com/jasmine/jasmine (UPDATED -- 2015)
I also use JSCoverage to test my code coverage. It can be found here : http://siliconforks.com/jscoverage/
There are several unit testing frameworks out there written for javascript.
You could try something like:
http://testcase.rubyforge.org/
I'm looking for the easiest possible Javascript unit-testing system for Rails 3.1 that is specifically capable of working with the asset pipeline out of the box.
I've tried various incarnations of the jasmine gem, including jasmine-rice, headless-jasmine-webkit. Jasmine gem does not appear to work with rails 3.1 out of the box, requiring tweaking of various config files. Jasmine-rice and headless-jasmine-webkit both have complicated dependencies and require more tweaking of the config file.
Any suggestions? Ideally I would need to include HTML/HAML fixtures, and be headless, but at this point I would be happy with anything that allows me to test my javascript with minimal configuration.
Jasmine is the best solution. We're using this to test all our JS code. It works beautifully with CoffeeScript as well.
But don't install the version of RubyGems.org (it's not been updated in a while), just get the latest from github, e.g. add to your Gemfile:
group :test do
gem 'jasmine', :git => 'https://github.com/pivotal/jasmine-gem.git'
end
Then you can run rake jasmine and go to http://localhost:8888 to run your tests. Headless webkit also works.
I was looking for something that would allow me to unit and functional test my javascript within MS Test in visual studio. Took me forever but I found WatiN. What WatiN will do is open internet explorer and run a web page. If you run your IDE as an administrator you can even open local HTML files.
I am currently using it with Visual Studio to run functional and unit tests on all my javascript. I think that so far this is the best solution out of the box for running javascript functional tests from your IDE. For my unit tests I used YUI test, but since you are opening a browser and running javascript within the browser you can use any javascript test framework you want (like qUnit).
I've been using QUnit, a simple yet effective Unit Testing library built on jQuery:
http://docs.jquery.com/QUnit
Hopefully late is better than never... I just wrote a small library that should solve your problem:
https://github.com/proxv/qlive-rails
It injects qunit and your qunit tests into live server responses. It also lets you set state server-side in advance of the tests (like logging in a user and setting content for the page) to reduce client-side mocking.
If you are using rspec, there's also an add-on that will run the qunit tests headlessly along with your other rspec examples.
We have a rich web client. Our controllers and service facades are written in coffeescript (JavaScript) and jquery. In the past they would have been java.
To run our JavaScript jasmine tests from Jenkins/Hudson, we use java's junit and htmlunit to load a test oriented jsp page which includes the jasmine specs.
When the Htmlunit tries to run, it blows up trying to getPage() probably because of an XML parser class path which is extremely challenging to track down in our world.
We just want to be able to run our JavaScript tests from Jenkins and have it report failure if a JavaScript test does not pass. We are just using jsp and htmlunit in order to run JavaScript tests. Can we load the JavaScript tests and javascript code into a JavaScript engine with Jenkins as the thing that kicks it off? If so, how?
Sounds like you're in a Java environment. My jasmine-maven-plugin might be a good fit.
Jasmine Reporters would also be a solution. It has instructions for running headlessly via PhantomJS for example, and it can generate JUnit XML so Jenkins can understand the test results natively, graphing test count, duration, and failure over time.
Also, the "xvfb-run" wrapper often provided with xvfb is a great help here, so you can do "xvfb-run phantomjs.runner.sh ..." in a truly headless environment.
I've previously solved this problem by running the tests with a node.js plugin called jasmine-node
This solution of course requires node.js and a few node modules to properly run the jasmine tests. There is no real browser running the tests, but an emulated one using a module called jsdom, which basically creates a headless browser, and more specifically, a DOM, which the tests can interact with.
There's node modules for jQuery, underscore and propably other too, so these can be tested too. You can even skip the whole browser emulation if you'd rather run the tests in a browser, though I find it too cumbersome compared to automated Jenkins testing.
jasmine-node generates jUnit test reports, which Jenkins can interpret just fine.
I just realized there is some jenkins-jasmine-node plugin that might ease this process.
Grunt is your friend
use grunt http://gruntjs.com/
with grunt jasimine https://github.com/gruntjs/grunt-contrib-jasmine
with nodejs http://nodejs.org/
on jenkins using https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin
got this setup and it's really nice, plus this gives you a place to start making your build server do other nice things such as deployment, unit testing, etc you know, other nice things
Can you use selenium? That would actually use a real browser then and get as close to the real environment as possible.