Karate v0.9.5 Release Notes

Release Date: 2020-02-16 // about 1 month ago
  • The Big One

    🚀 This took a while ! The last release was in July 2019 - but it does indicate that 0.9.4 was super-stable and that Karate for API testing is quite feature-complete. So what's new ? Web Browser Automation !

    🍱 A lot of work went into this area, and the feedback from early adopters who used 0.9.5.RCX has been extremely encouraging. And now 🥁 we consider it ready for use.

    karate-arch

    👍 To know more about how Karate is different from (and better in our opinion than) the competition - please read this blog post: The world needs an alternative to Selenium - so we built one.

    🚀 One additional point that is going to give us an edge over other browser-automation solutions is this - because Karate embeds a web-server (via the test-doubles capability) you can submit a self-contained snippet of HTML as a full-fledged project - to demo or replicate issues. The beauty of this is that it would run completely locally, yet perfectly replicate any exotic edge case. We put a lot of thought into Karate to make it easy for developers to build, extend and maintain, and if you find any gaps in the web-browser automation - we should be able to release minor / dot-releases pretty quickly.

    💥 Breaking Changes

    The Debugger

    💻 What we used to call the "Karate UI" (implemented in JavaFX) has been retired.

    Now we have what we feel is a game-changer - a debugger which is part of the Visual Studio Code extension for Karate created by Kirk Slota. This debugger is special - it can not only step-through code, but step backwards and hot-reload code. Note that this works for any Karate test, so API and UI automation is covered. See this video of the Karate-Runner in action. Thanks also to @peterquiel who contributed syntax-coloring support to the Karate-Runner.

    🚀 Note that you can point the Karate-Runner to an existing Maven (or even Gradle) project, and it will work fine. The new ZIP Release is ideal for especially non-Java teams - who don't want to use Maven or Gradle.

    We know of many .NET, JS and Python shops using the Karate standalone JAR - and the ZIP Release makes a very compelling case for Karate and UI automation. There is no need to compile code, and reports are built-in.

    🔧 configure abortedStepsShouldPass

    You will need to be aware of this only if you use the karate.abort() keyword and an old version of the cucumber-reporting library - and if you want steps after an "abort" to pass - #755

    Notable Improvements

    • ✅ Karate used to create a lot of log files on the file-system when running tests in parallel - and in rare cases, would exceed OS limits, not any more - #860
    • 0️⃣ karate.get() now takes a default value, which is very useful for conditional logic and "called" features where a variable has not been "pre-defined". Note that karate.get() is very flexible, it can evaluate even Json-Path and XPath - not just variable references
    • 🐎 Gatling tests would freeze in some cases, performance issues have been fixed - #845
    • An ExecutionHook interface has been introduced for more control over the life-cycle and for teams that need to integrate with 3-rd party reporting solutions and the like, and you can inject your custom implementation via the parallel Runner - #855
    • 🌲 And you can now "mask" parts of the HTTP log to avoid sensitive data such as Authorization headers and passwords being persisted and leaked - #699
    • Distributed Testing - that should solve for "scaling out" UI or Gatling tests
    • 👀 Introducing Karate Robot (experimental) for desktop app automation and native mouse / keyboard events, you can navigate using images, see video - we know that many teams need this, there is a severe lack of solutions in this space - so please get in touch and contribute if you can !
    • 🖨 karate.log() now "pretty prints" JSON and XML, so you don't have to resort to things like JSON.parse() and JSON.stringify() in your JavaScript snippets. Note that you should never need to use things like JSON.parse() - and they cause problems in the long term.
    • There is no need to use the @KarateOptions annotation for the parallel runner any more. Use the "builder" methods on the Runner class, which handles multiple features (or just directory / paths), tags, and the number of threads. Going forward, as a best-practice, you are recommended to not use the annotations any more - and if you use JUnit 5, you don't need it at all, see the example below
    • 👀 JUnit 5 API - a little less verbose syntax via Karate.run(), see below:

    image

    🚀 For a list of all fixes in this release, see here.

    Contributors

    Thanks to @paaco, @Celeo, @peterquiel, @ghostwriternr, @sivachithambaram, @BadgerOps, @man007yadav, @Nishant-sehgal, @TamannaBhasin27, @benjaminqc, @babusekaran, @celcius112, @khanguyen88 and @kirksl for pull-requests and other contributions. You rock !


Previous changes from v0.9.4

  • 💥 Breaking Change

    There is only one and only for those who use the standalone JAR file. When tests are run - the cucumber-json and junit-xml report output files will now be in target/surefire-reports not directly in the target directory. This prevents the inclusion of other JSON files into the report generation routine which would break the HTML report.

    Notable Improvements

    🛠 There are some bug fixes, and the main improvement is that the eval keyword is un-necessary (optional) for most cases - which makes Karate very close to pure JavaScript as a scripting language.

    Also - the Maven archetype (quickstart) now uses JUnit 5 instead of JUnit 4 - which simplifies the code a lot for newcomers.

    There is a bug in the quickstart, please read this as well: fix for 0.9.4 Maven archetype.

    👀 See complete list of fixes here.

    eval keyword optional for most cases

    Which includes any method call or operations on variables in scope and where you "don't care" about the returned value. Examples are:

    # using any API on the "karate" helper\* karate.env# where "foo" is of type function(){}\* foo()# where "bar" is a variable in scope\* bar.baz()# if statements for conditional logic\* if (responseStatus == 200) karate.call('delete-user.feature')
    

    🤡 This greatly simplifies Karate mocks as evident in this diff below !
    image

    Note that now we recommend that you directly use JavaScript instead of the set keyword when needing to "update" an existing JSON variable. If you need to remove a JSON key where the key name is dynamically derived, use karate.remove() as shown above.

    Note that these rules apply to the Left Hand Side of the match keyword - so you can do things like this now - note the combination of match and karate.filterKeys():

    \* def schema = { a: '#string', b: '#number', c: '#boolean' }\* def response = { a: 'x', c: true }# very useful for validating a response against a schema "super-set"\* match response == karate.filterKeys(schema, response)\* match karate.filterKeys(response, 'b', 'c') == { c: true }\* match karate.filterKeys(response, ['a', 'b']) == { a: 'x' }
    

    In initial versions of Karate, you had to split the last 2 match steps above into 2 steps.

    🆕 New karate.filterKeys() API #810

    📚 And an example appears above. This is very useful for cases where you want to use a "super set" schema that is defined once and you want to re-use. Also in situations where you quickly want to "select" only a few keys out of a given JSON. See the documentation on JSON transforms for more.

    🆕 New karate.start() API

    ✅ To start a Karate mock directly from a feature file without needing to write Java code. Refer to the docs here.

    🆕 New karate.os API

    📚 To get meta-data about the runtime operating system, that can be used to drive conditional logic - for example to run a slightly different set-up routine for Mac OS X versus Windows. See documentation here. Here is a representative example:

    # looks for "common-windows.feature" or "common-macosx.feature"\* call read('common-' + karate.os.type + '.feature')
    

    call read fileNameString

    A short-cut to inject all key-values of a given JSON file into the variables context is now possible, more details in this comment.

    💻 Karate UI has a "pre step" hook option

    Best explained in this video.