Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config object data unavailable within features called from karate-config.js #1838

Closed
kirksl opened this issue Nov 15, 2021 · 5 comments
Closed
Assignees
Labels

Comments

@kirksl
Copy link
Contributor

kirksl commented Nov 15, 2021

This issue started occurring after Karate 1.0.1

myproject.zip

  1. Download attached project
  2. Run /src/test/java/com/repro/tests/test.feature@test=test1
  3. Open build/karate.log
  4. Search for "someConfigVar" which was set on the config object in karate-config.js
  5. Witness that it exists (example karate.log output below)
  6. Update build.gradle to a build greater than 1.0.1
  7. Rerun steps 1-4
  8. Witness now that "someConfigVar" no longer exists

What we are expecting (eg "testData", "someConfigVar", "someConfigVal")

14:12:51.221 [Test worker] INFO  com.intuit.karate - [print] {
  "testData": {
    "someConfigVar": "someConfigVal"
  },
  "create_account": true,
  "params": [
    {
      "param1": "abc",
      "param2": "def",
      "param3": "ghi"
    }
  ],
  "param3": "ghi",
  "responseStatus": 200,
  "param1": "abc",
  "param2": "def",
  "password": "Customertesting123!",
  "responseHeaders": {
    "Date": [
      "Mon, 15 Nov 2021 22:12:51 GMT"
    ],
    "Content-Type": [
      "application/json"
    ],
    "Content-Length": [
      "299"
    ],
    "Connection": [
      "keep-alive"
    ],
    "Server": [
      "gunicorn/19.9.0"
    ],
    "Access-Control-Allow-Origin": [
      "*"
    ],
    "Access-Control-Allow-Credentials": [
      "true"
    ]
  },
  "somevar": "someval",
  "response": {
    "args": {
    },
    "headers": {
      "User-Agent": "Apache-HttpClient/4.5.13 (Java/11.0.8)",
      "Host": "httpbin.org",
      "Accept-Encoding": "gzip,deflate",
      "X-Amzn-Trace-Id": "Root=1-6192db63-1cd8aa8e45e9f7f85f8bf4a0"
    },
    "origin": "136.27.62.13",
    "url": "https://httpbin.org/get"
  },
  "name": "Customer Testing1",
  "entity": [
    {
      "name": "Customer Testing1",
      "email": "customertesting+1@gmail.com",
      "password": "Customertesting123!",
      "create_account": true
    }
  ],
  "email": "customertesting+1@gmail.com"
}
 
14:12:51.224 [Test worker] INFO  com.intuit.karate - [print] {
  "someConfigVar": "someConfigVal"
}
@ptrthomas
Copy link
Member

@kirksl I haven't looked at this - but the "config" variables are injected only when the karate-config.js exits. which is why any call you do has to manually collect / pass arguments taken out of the code, for e.g. see #1837

@kirksl
Copy link
Contributor Author

kirksl commented Nov 16, 2021

@ptrthomas I should clarify. I meant passing any object reference to another feature file within karate-config. I just happened to be using config in this case. Eg "config.testData" here...
image

@ptrthomas
Copy link
Member

@kirksl ok. will look into this later. can you try a quick experiment. and karate.toJava() also in case toJson() doesn't work

var temp = karate.toJson({ testData: config.testData, entity: data });
karate.call(callee, temp);

@ptrthomas ptrthomas self-assigned this Nov 16, 2021
@ptrthomas ptrthomas added the bug label Nov 16, 2021
@ptrthomas ptrthomas added this to the 1.2.0 milestone Nov 16, 2021
@kirksl
Copy link
Contributor Author

kirksl commented Nov 16, 2021

@ptrthomas done. toJava() and toJson() did not change the behavior.

@ptrthomas
Copy link
Member

@kirksl just took a look at this and the project is a bit too complicated to navigate. I'd like it to be more minimal, because from what little I could understand, this is not valid use of call etc.

anyway, it is most likely fixed in the latest changes to develop. so please re-open as a fresh issue if applicable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants