Karate and Github Copilot - NextensArelB/SwaggerGenerationTool GitHub Wiki

[[TOC]]

Github Copilot and Karate: how to use:

When you have installed Github Copilot as a extension to visual studio code, you can use this tool to help generate tests or get advice as well as autocomplete.

Examples of how to use Copilot

Below, you can find examples of how to use Copilot

###Example 1 "Can you create a Karate test for calculating the amount of days from 1 january 1970 till today" Navigate to the Github Copilot button at the bottom bar of VS code and select: "Github copilot chat":

image.png

On the left panel a chat window will open so you are able to ask questions. Put in the question and this is the result:

# Can you create a Karate test for calculating the amount of days from 1 january 1970 till today

Feature: Calculate number of days since January 1, 1970

Scenario: Calculate number of days
  Given def epochStart = 0
  And def millisecondsPerDay = 86400000
  And def today = new Date()
  And def todayMilliseconds = new Date().getTime()
  When def daysSinceEpoch = (todayMilliseconds - epochStart) / millisecondsPerDay
  Then print 'Days since January 1, 1970: ' + daysSinceEpoch

###Example 2 "Can you create a Karate script that calls Google with a get call and validate the response code is 200?"

Here is the result of this question:

# Can you create a Karate script that calls Google with a get call and validate the response code is 200?
Feature: Send a GET request to Google

Scenario: Send GET request
  Given url 'https://www.google.com'
  When method get
  Then status 200

##Conclusion The karate scripts generated by Copilot, came very close to working out of the box. Minor modifications are needed to get it to work but with the help of Copilot it is possible to make those changes. This shows that Copilot can definitely be used for generating tests with some minor fixes needed.

Additionally, Copilot is helpful for working to solve issues when making your own Karate tests. Giving the returned error to Copilot often times will have it respond with how to fix it and tips on how to avoid it. Overall, Copilot is a very helpful tool when working with Karate. However some Karate knowledge and skills are recommended as Copilot will not do everything for you. It is most helpful when it comes to fixing tests and trying out new techniques or when feeling stuck. Last but not least, the autocomplete functionality is incredibly helpful. When filling in an JSON object that has repetitive naming structures such as test1, test2 etc. Copilot can quickly pick up on this and complete your object saving time and tedium.

Copilot is a useful tool that will defintiely help and benefit testers when working with karate.

⚠️ **GitHub.com Fallback** ⚠️