Posted on

PhantomJS + Jasmine vs Selenium Web Driver

Recently I started using phantomjs, which is a headless browser based on web-kit, for automated JavaScript testing.

Now when I was playing around with Selenium @ ABC Family, I really liked how the web driver started a browser instance and executed the test suite within it. This means Selenium is actually a better, or closer match, in terms of automated testing, because the browser is not headless. Although I don’t know all the internals of Selenium, that was my first impression.

But the positive thing about using the grunt, jasmine, phatomjs combo to run unit tests, is that we can start a jasmine server, which lets you check your code in many other browsers. That means you are not limited by the Selenium browser library of supported browsers. You can actually pick up your phone, or tablet, and point the browser to the test server, and see how your code executes on that particular system ( Device, OS, Browser). True this is not something that can be used with 100% automation on its own, but it does give you the freedom to experiment and see the behavior of code in a large variant of systems. This means that with services like DeviceAnywhere, you maybe able to cover and automate the testing of all kinds of strange fringe devices.

Something else that is interesting is that in Selenium, you can’t really hook, or spyOn member methods. While a lot of the tests written in jasmine, can be executed similarly with Selenium, because they just check for a class that has been added or removed from a DOM element, jasmine provides more integration with the code base.

The classes are loaded, along with a html fixture, and then executed. This is how the server works, by creating a #sandbox div where it loads the html fixtures for each test, loading the javascript into the page, instantiating the class, and then begins execution of the test suite. Now the opposite argument is, again, this is not how the site would be like in the wild. Other components would live on the page. So Selenium gives a more accurate assessment of how the code actually works on the end user’s system, since it loads the entire site, via a client side browser.

Now as a Computer Scientist, Java vs JavaScript argument is mute to me when it comes to choosing a “platform”. Because ultimately its like comparing apples to oranges, when you really look at the language structure and what they are designed to accomplish. Two different tools for different jobs. As a front end developer, who wants everything to be easy, there is definitely a benefit to having a unified language for creating build tools, server side applications, and user interfaces. So at some shops, where ROI is important, it’s a good idea to keep the tools all in the skill set of the human resources currently on staff. For UI people, this means JavaScript > Java. This is a good argument for using tools like grunt, and phantomjs, and jasmine, since they are all JavaScript based, they empower the new kingmakers (Open Source Developers).

Which is actually still not a big argument against Selenium Web Driver, because Java is very easy to install, you are not going to be making many changes to the driver itself, and the interface for running the Selenium Web Driver could potentially still be written in JavaScript.

Therefore the argument could be made that Selenium and Jasmine don’t have to be mutually exclusive, while it would bloat the build time to include both systems, a separate box, and process, could be used, to test with both, or the one that is missing in the build process.

While its too soon for me to say, “Dude, Selenium is old news.” I can say that all this merits more experimentation and testing. A very exciting time for Computer Scientists indeed. So much Brain Candy!

Posted on

Goodbye JavaScript

Hello Google Dart

Can’t we just embed a lite JVM into the browser, so I can write groovy.

Whats with all the parentheses.

main(){
var callbacks=[];
for(var i =0; i callbacks.add(() => print(i));
}
callbacks.forEach((c) => c());
}

Sorry, I think groovy is more elegant, with a step in the right direction to remove awkwardly typed characters like the ( and )