Karate: JS function doesn't work when test runs in docker container

Viewed 188

I'm having some problems with running tests in docker. I'm not sure if this is Karate thing or docker configuration.

Background looks like this:

  Background:
    * configure report = { showLog: true, showAllSteps: false }
    * def ts = call read('classpath:utilities/helper-random-data-js.feature@timestamp')
    * def timestamp = ts.timestamp
    * print "Current timestamp " + timestamp

JS located in helper-random-data-js.feature@timestamp

  @timestamp
  Scenario: Generate timestamp
    * def getDate =
    """
    function() {
    var unix = Math.round(new Date().getTime()/1000)
    return unix;
    }
    """
    * def timestamp = getDate()
    * print timestamp

Everything works as expected when I'm running tests on local env via command line

xx - scenario called at line: 4 by tag: @timestamp
xx - [print] 1614103214
xx - [print] Current timestamp 1614103214

Problem starts when I'm running docker container with this test:

docker run karate_docker mvn test -DargLine="-Dkarate.env=stage" -Dtest=E2eRunner -Dkarate.options="--tags @test1"

xx - scenario called at line: 4 by tag: @timestamp
xx - [print] 1.614103807E9
xx - [print] Current timestamp 1614103807

As a result, the test fails because incorrect timestamp

  @test1
  Scenario: xxx
    Given url my_url
    And path 'billing/history/' + user_id
    And param startDate = timestamp
    When method get
    Then status 200

Result: https://xx/billing/history/0000?startDate=1.614103807E9

Docker file looks like this:

FROM maven:3-jdk-8-alpine

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY settings.xml /usr/share/maven/ref/
COPY pom.xml /usr/src/app
COPY ./src/test/java /usr/src/app/src/test/java


RUN mvn -B -f /usr/src/app/pom.xml -s /usr/share/maven/ref/settings-docker.xml prepare-package -DskipTests

Any help appreciated.

1 Answers
Related