Testing phantomJS scripts - unit-testing

I have a phantomjs script that navigates to some pages and store some information about them in a file. Now I want to unit test this script. My problem is that usually the frameworks test my code on client side, so I can't use the PhantomJS API.
I tried to use jasmine-node (https://github.com/mhevery/jasmine-node). It works "server-side", but I can't use all the PhantomJS API because it obviously run my tests with nodejs instead of phantom. Is there a better option to test PhantomJS apps at server-side?

I found two solutions. I think the most complete way to test phantomJS at "server side" is to use CasperJS.
Another solution I have found looking at the phantomjs source code. They use jasmine for testing and it's possible to apply the same idea to my own tests. The run-tests.js is the starting point for this approach.

Related

What is the bare minimum installation suite for unit testing in AngularJS?

I'm attempting to learn AngularJS. One of the things that attracts me is its claim of separation of concerns and unit testability. So it defeats me completely to understand why I should need to install Node.js, or any web server, to test (say) an AngularJS controller which does no DOM manipulation or call out to any web services.
Can anyone give me a definitive bare-minimum list of what is required to unit test AngularJS code?
I'm going assume that you understand the difference between end-to-end testing and unit testing in Angular, so you're only asking about what it takes to do unit testing, right?
Basically you're going to need pretty much everything that comes with the seed project. The seed project uses Karma as the test runner to execute the javascript that you've written. Step 02 of the AngularJS Tutorial (found here) walks through writing some simple tests and executing them using Karma. Everything required to do that comes with the seed-project.
Those required things are:
An angularjs app
Node.js (installed)
Karma
Some jasmine-style unit tests
If you don't want to use the seed project, you can use Step 02 of the tutorial as a spring board and just follow the Karma docs to download and install Karma and get it running.
I hope that helps.

Is it possible to use Selenium / PHPUnit outside the browser?

Right now this is my workflow to write tests for a website:
Record using Selenium IDE plugin in Firefox
Export Test Case As >> PHP (PHP Unit)
Run the tests on a Windows machine that has PHPUnit installed as well as the Selenium extension for it using this command:
phpunit --verbose --log-junit some\path\result.xml some\path\test.php
What this command does is runs the test and saves the output (assertions and failures) in a log file called result.xml. And all has been good.
But now I have run into a need to test a part of the site that involves flash and I am using an application called Arthropod to capture the requests and responses coming to and from the flash component on the site.
Is there any way I can get selenium to to capture the text that appears on this program's interface?
I believe Arthropod is an AIR application. If it is associated with the browser you may try using seleniumForAir for your testing.
You may like to have a look here.

running jstd-maven-plugin tests without a browser

I've got jsTestDriver up and running, and I use jstd-maven-plugin to run the tests during a build.
The plugin needs a browser to be specified in order to work though, and I'd like to use something like rhino or htmlunit that won't actually launch a browser.
The jasmine-maven-plugin does this with htmlunit, and works quite well.
Is there a way to specify a headless browser for jstd-maven-plugin?
One of the reasons that I prefer JsTestDriver over other JavaScript testing frameworks, is that the tests are made on real browsers, and allows me to test on all the major browsers that consumes my application, and verify compatibility issues with older versions of IE for example.
If you prefer to run a complete headless JavaScript testing server, perhaps JsTestDriver is not your best choice. I think CasperJS is a very good alternative to achieve that. It uses PhantomJS, a scriptable headless WebKit engine to run the tests.
In my case, I have a complete headless server running an instance of JsTestDriver, and Other server whit a couple of virtual machines, with common SO/Browsers combinations (Windows/IE7; Windows/IE8; Linux/Firefox...), which have actual browsers connected to the headless JsTestDriver server. But if you don't need to use real browsers, the CasperJS alternative may be a good choice.
JsTestDriver need a browser to run the javascriptcode. So there is no way to run your tests without a browser.
There is a way to open the browser in a virtual monitor. This is described in this question:
Run Headless JsTestDriver?
JSTD maven plugin can be extended to run phanatomjs.

Selenium and Django: how to mock the server?

I'm starting to introduce Selenium tests to my website that is written in Django. The browser that is controlled by Selenium needs some server to connect. So far I just run my full application in a separate process, but this is painful.
I'd like to run some mock HTTP server, make it serve all the necessary static files and render Django templates and return mock responses to some specific requests.
How would you do that?
Can you not run Selenium over django dev server http://localhost:8000/ .
If not perhaps worth looking at http://harry.pythonanywhere.com/ .where there are some good resources
The best thing is to integrate selenium tests into your unit test suite. When Django 1.4 comes out this will be a supported feature, where the Django test runner will run a development HTTP server for you while the tests run, and load all of your test fixtures for you:
support-for-in-browser-testing-frameworks
LiveServerTestCase
Likely you can't wait until the 1.4 release. In the meantime, you can use something called django-nose-selenium to do this:
https://github.com/weluse/django-nose-selenium
There's a good comprehensive guide on how to do this here:
http://timescapers.com/2011/08/27/django-nose-selenium-a-concise-tutorial/
If I may plug-plug my own tutorial, which will allow you to do full selenium testing against the django test server
http://www.tdd-django-tutorial.com/

Selenium - can it test a B2B web service

I've used Selenium to do lots of UI testing from the browser. If you have a web service behind the Java jsp page i.e. in a servlet, you can test it from Selenium.
Can Selenium be used to test a B2B web service i.e. a web service called from a backend that has no browser UI component?
I have used SOAPUI to do this kind of testing in the past but our test department is trying to standardise on Selenium.
You can but I would not recommend it. If the page is returning XML, you won't be able to use the standard Selenium calls to verify what is happening as you won't have access to the DOM. If its returning plain text for JavaScript then you will struggle with verifying the output.
This is a definite case of using the right tool for the job and Selenium is not the right tool for testing web services. I would use soapUI or just use some http library to call the service URL and then verify the results.
If they are looking to standardise they need to standardise tools for their purpose. Selenium for UI, soapUI for webservices,XUnit Framework for unit and integration.
You can, but it's really not the right tool for the job. It's like trying to hammer a nail into a piece of wood using a stapler instead of a hammer.
That said, probably the most appropriate way to create a page with all your input parameters which could do the call for you and echo the results back into a html element. If the service is meant for AJAX calls then this is probably the ideal solution for your service.
The correct approach would be to use a unit testing framework and create a test harness which you can push your parameters into, execute the service call and retrieve the results in a meaningful way for assertion.