3

I have a util file that I need to access called util.js from karate-config.js and would like it available for both modules to use.

util.js
module1
-- src
--- test 
--- java 
---- karate-config.js
module2
-- src
--- test 
--- java 
---- karate-config.js

I have tried karate.call('classpath:util.js') which results in a FileNotFoundException. I have tried an absolute path and it does not work.

Any other suggested approaches I could try ?

1 Answers1

0

You may have to use something like karate.call('file:./test.js') or something similar. This is not really recommended, because the chances of test.js being available when you check-out from version-control are low.

I strongly recommend moving test.js to lie side-by-side with karate-config.js and then things will work using classpath:test.js as you expect.

Refer the docs for more: https://github.com/karatelabs/karate#naming-conventions

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • I have added some details to the original description. What I need is a shared util file across 2 modules. Is that possible ? – Karen D'souza Mar 09 '22 at 17:57
  • @KarenD'souza yes, if you know what you are doing, use the `file:` prefix as I already said (relative paths like `../../foo` should also work) or see this answer for a more advanced approach: https://stackoverflow.com/a/58339662/143475 – Peter Thomas Mar 09 '22 at 20:12