Bernard Kobos: Automated Cross-browser Testing with Node

Orde Saunders' avatarPublished: by Orde Saunders

Bernard Kobos (@bkobos) was talking about automated cross browser testing at Scotland.js, these are my notes from his talk.

Why do we need it?

We are human and we make mistakes. We need to make sure that what we build does what we want it to do. In big projects there is a high risk of regression. Bug -> fix -> new bug.

Run your tests on each commit, you get immediate feedback on your code. Automated tests are repeatable and computers don't complain about doing the same thing over and over again.

What should I test?

  • Unit tests: Test your application modules. Mock third party APIs and are very fast. Only tests tiny chunks of code.
  • Integration tests: Simulates reality as best as you can. Checks that the modules work together.

What should I use?

Selenium is an open source tool that is becoming a W3C spec that can automate testing in a large number of browsers and test scripts can be written in a number of languages. Selenium 2 uses WebDriver - don't use Selenium 1.

How does it work?

Your script <-> SE server <-> SE driver (browser) <-> your JS application.

Server communicates over the network so you can run the driver on any machine.

SE Builder

Open source tool, graphical UI (Firefox plugin) which lets you record tests and then export them to many languages. Need to do some tweaking to script to match what's actually in the browser (e.g upper vs. lower case text). Can run tests direct from the builder.

Best practices

  • locators - use selectors that don't rely on layout.
  • spinAssert - loop to check that async functions pass.
  • paralleism - shouldn't assume that other tests were executed before you run a test.
  • end-to-end checks - check that UI actions have correct effect on back end.

Tools

SauceLabs can run tests on browsers in the cloud so you don't need to have everything on your machine. Free for open source projects.

What about mobile?

Native apps: iOS -> UI Automation, Android -> UI Automator. Appium means you can use Selenium syntax for one set of tests that runs on both iOS and Android.

Web: iOS and Android both have WebDrivers but these run in UIWebViews, not actual browsers. Appium (again) can run in the main browser.


Comments, suggestions, corrections? Contact me via this website