1

I have been trying to automate a test scenario wherein I need to fetch a JSON file from S3 bucket, read it and then apply my logic. Please note I am using JavaScript with Karate.

Since I am fairly new to test automation I have been doing some research online about this. So far I have got the Maven Artifact aws-java-sdk-s3 that I am trying to use.

I put this dependency in the pom.xml file.

        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-s3</artifactId>
            <version>1.11.953</version>
        </dependency>

How do I use this artifact to fetch a file from the S3?

Meanwhile, I am trying to fetch a particular file using the S3 URL as follows:

@sampleTest
Scenario: Get Call Test
    Given url 'http://test-bucket.s3.amazonaws.com/'
    When method Get
    Then status 200

This is currently giving me 403 status because the bucket is not public.

How do I add the S3key and S3secret to the URL? Also, how to fetch the particular file given I know the location (JSONPathURL)? Can someone who is familiar with this tool help me?

Shambhavi
  • 305
  • 1
  • 14

1 Answers1

1

It should be possible to mimic the HTTP request using Karate and pass the magic headers. Here is an example: https://stackoverflow.com/a/62085130/143475 - and if all you need is a GET it should be even simpler.

That said the other option is via Java inter-op. Start by writing a static helper method with everything hard-coded and calling that from Karate will be straightforward: https://github.com/intuit/karate#calling-java

Something like this:

* def data = MyUtils.getJsonFromS3()

Once you get that working, you can think of passing parameters to the getJsonFromS3() method etc.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Yea I had checked that particular question, but it does not help me with how to fetch a file. Unfortunately I did not find any examples on GET. I will keep searching to see if I find how to do what I want to do. Thanks – Shambhavi Feb 13 '21 at 10:51
  • @Shambhavi just find any existing Java code example using the SDK there's no need to search so much ! – Peter Thomas Feb 13 '21 at 11:23