For a new customer I needed to optimize and extend the current testautomation setup. They work with:

  • Protractor
  • CucumberJS
  • TypeScript

I already worked with Protractor and CucumberJS in my previous assignment, but TypeScript was new to me. And there is nothing better than a new challenge 😉

Compiler

When I dived into the project setup I saw that each time I created a testcase, or changed some lines of code, I first needed to compile the code before I could run my tests. The fist thing I could have done was to adjust the task that executed the compiling, but I found a better solution called the compiler argument. It’s an argument in CucumberJS since version 0.6.0 but I never noticed it.

With the compiler argument you can write step definitions and support files in other languages that transpile to javascript. If you use Protractor, CucumberJS and TypeScript you can use it with this

cucumberOpts: {
    compiler: "ts:ts-node/register",
    require: [..],
    format: 'pretty',
    tags: '@TypeScriptTag'
}

This simple line of code saved me a lot of time when I was adding, changing or debugging testcode.

Boilerplate

After I’ve been playing around with the compiler argument some colleagues, at my new assignment and a direct colleague at the company I work for, asked me if I had a default setup for Protractor, CucumberJS and TypeScript. They made me think about creating a simple boilerplate that could be used within a project. So I sat behind my laptop and created protractor-cucumber-typescript-boilerplate.

protractor-cucumber-typescript-boilerplate is a boilerplate that holds:

  • working configuration out of the box
  • feature and step-file examples about how to use
  • no need to compile TypeScript testfiles before running because of the compiler
  • automatically making screenshots on failed steps

It supports and provides:

and a lot more.

It’s easy to use by just copying the setup to your project. Copy all the dev-dependencies to your projects package.json and do a new npm install of your project. You can use whatever taksrunner you want to run the tests. Simple as that.

I hope you can use it in your project and if you have question feel free to ask them here or raise an issue on https://github.com/wswebcreation/protractor-cucumber-typescript-boilerplate

 

Grtz,

Wim

 

Credits: