Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from dialex/framework/karate
Framework review: karate
- Loading branch information
Showing
19 changed files
with
227 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,8 @@ png | |
descope | ||
kanban | ||
onboarding | ||
whitespace | ||
standalone | ||
- docs/toolbox/note-taking.md | ||
udos | ||
deas | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
install: | ||
echo "⚠️ Assuming you have Node.JS and NPM installed..." | ||
npm install cypress | ||
|
||
clean: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target/ | ||
karate.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
install: | ||
echo "⚠️ Assuming you have Java 8 or above installed..." | ||
curl -L https://dl.bintray.com/ptrthomas/karate/karate-0.9.5.jar -o karate.jar | ||
|
||
clean: | ||
rm -rf target/ | ||
|
||
test: clean | ||
java -jar karate.jar --threads=4 src/test/karate --clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Karate | ||
|
||
Review [here](https://github.com/dialex/start-testing/tree/master/docs/toolbox/framework/karate.md). | ||
|
||
## Commands | ||
|
||
```sh | ||
make install # Install dependencies | ||
make test # Run tests | ||
``` | ||
|
||
## Automation scope: [Postman API](https://docs.postman-echo.com/) | ||
|
||
- [x] Successful GET | ||
- [x] Successful POST | ||
- [x] Failed method | ||
- [x] Assert response structure | ||
|
||
## Automation scope: Amazon | ||
|
||
- [x] **Smoke Tests** | ||
- [x] Access homepage on browser | ||
- [x] **Functional Tests** | ||
- [x] Search for item | ||
- [x] Add item to cart |
12 changes: 12 additions & 0 deletions
12
code/framework/karate/src/test/fixtures/postman-post-payload.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"some-field": "some value", | ||
"another-field": 2, | ||
"list-of-stuff": [ | ||
{ | ||
"name": "stuff1" | ||
}, | ||
{ | ||
"name": "stuff2" | ||
} | ||
] | ||
} |
17 changes: 17 additions & 0 deletions
17
code/framework/karate/src/test/karate/api-postman-contract.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Feature: Postman Echo GET | ||
|
||
Background: | ||
* url 'https://postman-echo.com' | ||
|
||
# Inspired by https://github.com/intuit/karate/blob/master/karate-junit4/src/test/java/com/intuit/karate/junit4/demos/schema-like.feature | ||
Scenario: Contract of /get response | ||
|
||
Given path "/get" | ||
And param word1 = "Domo arigato" | ||
And param word2 = "Sayonara" | ||
And def schema = | ||
""" | ||
{ args: { word1: #string, word2: #string } } | ||
""" | ||
When method get | ||
Then match response contains schema |
27 changes: 27 additions & 0 deletions
27
code/framework/karate/src/test/karate/api-postman-get.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Feature: Postman Echo GET | ||
|
||
Background: | ||
* url 'https://postman-echo.com' | ||
* def endpoint = "get" | ||
|
||
Scenario: Endpoint /get exists | ||
|
||
Given path endpoint | ||
When method get | ||
Then status 200 | ||
|
||
Scenario: Returns the parameters received | ||
|
||
Given path endpoint | ||
And param param1 = "Hajime" | ||
And param arg2 = "Dozo" | ||
When method get | ||
Then status 200 | ||
And match response == "#notnull" | ||
And match response.args.param1 == "Hajime" | ||
# Assertion using JsonPath (see https://stackoverflow.com/questions/62280561/) | ||
# Option 1: compare JsonPath result with an array (which is misleading) | ||
And match $..arg2 == ["Dozo"] | ||
# Option 2: store JsonPath result in tmp var (which is cumbersome) | ||
* def tmpKarateSupportForJsonPathIsPooPoo = $..arg2 | ||
And match tmpKarateSupportForJsonPathIsPooPoo[0] == "Dozo" |
33 changes: 33 additions & 0 deletions
33
code/framework/karate/src/test/karate/api-postman-post.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Feature: Postman Echo POST | ||
|
||
Background: | ||
* url 'https://postman-echo.com' | ||
* def endpoint = "post" | ||
|
||
Scenario: Endpoint /post exists | ||
|
||
Given path endpoint | ||
And request {} | ||
When method post | ||
Then status 200 | ||
|
||
Scenario: Returns the payload received | ||
|
||
Given path endpoint | ||
And request read('../fixtures/postman-post-payload.json') | ||
When method post | ||
Then status 200 | ||
And match response.data.some-field == "some value" | ||
And match response.data.list-of-stuff[1].name == "stuff2" | ||
|
||
# this is actually the "get started" example from the docs... | ||
# you know, the kind of code you want to always work, | ||
# because it's your first interaction with the tool (ಠ _ ಠ) | ||
Scenario: Failed request returns 500 | ||
|
||
Given url "http://myhost.com/v1/cats" | ||
And request { name: "Billie"} | ||
When method post | ||
Then status 500 | ||
# Then status 201 | ||
# And match response == { id: "#notnull", name: "Billie" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Feature: Amazon UI automation | ||
|
||
Background: | ||
* def baseUrl = 'https://www.amazon.com/' | ||
* configure driver = { type: 'chrome' } # this is optional | ||
|
||
Scenario: Access homepage on browser | ||
Given driver baseUrl | ||
Then driver.url == baseUrl | ||
And assert locate("#twotabsearchtextbox").exists | ||
And assert locate("{}Cart").exists | ||
|
||
Scenario: Search for item | ||
Given driver baseUrl | ||
And def searchTerm = "Explore It" | ||
And def searchTermEncoded = "Explore+It" | ||
# This one-liner should work, but doesn't ¯\_(ツ)_/¯ | ||
# When input("#twotabsearchtextbox", [searchTerm, Key.ENTER]) | ||
When input("#twotabsearchtextbox", searchTerm) | ||
# This should work, but doesn't | ||
# And click("#nav-search-submit-text") | ||
And mouse("#nav-search-submit-text").click() | ||
# This should not be necessary, but it is (╯°□°)╯︵ ┻━┻ | ||
And waitFor('#nav-search-submit-text').click() | ||
Then match driver.url contains "s?k=" + searchTermEncoded | ||
And locate("div.s-result-list").exists | ||
And locate("{span}Explore It!: Reduce Risk and Increase Confidence with Exploratory Testing").exists | ||
# Read more about this issue at https://github.com/intuit/karate/issues/1169 | ||
|
||
# FIXME: I can't get this to work, I give up (╯°□°)╯︵ ┻━┻ | ||
# Scenario: Add item to cart | ||
# Given driver baseUrl | ||
# And def searchTerm = "Cypress" | ||
# And input("#twotabsearchtextbox", searchTerm) | ||
# And mouse('#nav-search-submit-text').click() | ||
# When mouse(".s-result-item .s-image").click() | ||
# And mouse('#add-to-cart-button').click() | ||
# Then match text("#nav-cart-count") == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Karate | ||
|
||
> Karate is the only open-source tool to combine API test-automation, mocks, performance-testing and even UI automation into a single, unified framework. You don't have to compile (Java) code. Just write tests in a readable syntax. | ||
> | ||
> — [Official website](https://intuit.github.io/karate/) | ||
## Code | ||
|
||
Example of automation at [GitHub](https://github.com/dialex/start-testing/tree/master/code/framework/karate). | ||
|
||
| Category | Opinion | Score | | ||
| ----------------- | ------- | :------: | | ||
| _Use cases_ | Automate API tests. It also supports performance and end-to-end (E2E) tests. Mobile testing is in the roadmap. | 🥇 | | ||
| _Learning curve_ | Steep. It's easy to understand how it works, but it lacks an official step-by-step tutorial where each main DSL keyword is introduced, one at a time. It feels like a framework made by and to "hardcore developers". The purpose of using Gherkin is to make the tools accessible to non-devs, yet I never felt productive or in control. | 🥈 | | ||
| _Language_ | Tests are written in [Karate's DSL](https://hackernoon.com/yes-karate-is-not-true-bdd-698bf4a9be39). It uses the syntax of Gherkin and it adds some custom keywords and operators. It also supports calls to Java and JavaScript, outside the Given-When-Then structure. | 🥇 | | ||
| _Ecosystem_ | The [VS Code extension](https://marketplace.visualstudio.com/items?itemName=kirkslota.karate-runner) didn't work at all (e.g. no autocomplete, no debugger, no run test button). In terms of community… there's not much since it's a recent tool. The author is an [enthusiastic](https://twitter.com/KarateDSL/status/1167533484560142336) salesperson which led to [some bad PR](https://twitter.com/jarbon/status/1136589061605416961), result of the "my tool is amazing, if you disagree you're against me" attitude. He's very active on Stack Overflow and GitHub though, replies within hours! | 🥉 | | ||
| _Readability_ | It's easier to read than to know what to write. Without autocomplete or good documentation it becomes hard to know how to use the Karate DSL to achieve what you want to do. Your tests use Gherkin's structure, but you have to mix programming syntax too (e.g. operators, selectors). This [sums the downsides](https://club.ministryoftesting.com/t/karate-for-test-automation-what-is-your-experience/39336/2) of natural (e.g. no refactoring) and programming (e.g. learning curve) languages. The CLI output is very verbose (without colours or whitespace) so it's hard. The HTML report doesn't clear results from previous test runs. Oh, and the DSL doesn't allow inline comments. | 😭 | | ||
| _Extensibility_ | You don't need plugins, since it follows the "batteries included" philosophy. Running tests in parallel is very easy. It includes Mocking, [code coverage](https://github.com/intuit/karate/tree/master/karate-demo#code-coverage-using-jacoco) and HTML reports (but it doesn't reset results between runs, even when using `--clean`, which makes the report useless). | 🥈 | | ||
| _Maintainability_ | The [*big difference*](https://intuit.github.io/karate/#cucumber-vs-karate) from Cucumber is that you *don't* need to write extra "step definitions" (but you end up mixing Gherkin with programming). You can't use PageObjects, but you can centralise selectors in a `locators.json` to achieve DRY. I could not debug at all, zero of features [advertised here](https://twitter.com/KarateDSL/status/1167533484560142336) worked for me (Cypress, even [Selenium](https://hackernoon.com/the-world-needs-an-alternative-to-selenium-so-we-built-one-zrk3j3nyr), does a better job). On top of that, I got [incoherent test results on UI automation](https://stackoverflow.com/questions/62308044/karate-ui-automation-test-results-are-not-coherent). | 😭 | | ||
| _Documentation_ | Documentation is a single README file. It's verbose, exhaustive for beginners, hard to navigate and find what you are looking for. It feels like the official docs were written by the author but never revised from the perspective of a beginner (e.g. the provided quick start example fails; it can't be copied because it's an image; it was faster to skim blogs for examples and reverse-engineer the bits that I needed). | 🥉 | | ||
| **VERDICT** | Useful for [API testing](https://docs.google.com/document/d/1ETTrdMVcBXaPjdKY-_67zCWBsi2Ctc5DIQUIfr02H7A/edit), because it uses a generic language and can be executed as a standalone. But don't be fooled, the target audience are developers and it's not an alternative for UI/E2E tests. | **3/5** | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,4 @@ | |
15: 535 | ||
7: 800+80 | ||
12: 1100 | ||
102: 1000 |