0

How to overwrite a karate-config.js variable thru a Scenario. I tried using Set, but did not work. My karate-config.js and feature files are as below: Though not getting any error but cpNumber value did not change, printing 234455 not 123. Can some-one pls help me over-writing a karate-config.js variable.

function fn(){
     var config = {
        cpNumber : "234455"
        }
        return config
    }

    Scenario: Update  scenario
        * karate.set(cpNumber, "123")
        * print cpNumber 
karusai
  • 126
  • 1
  • 1
  • 9
  • as far as I know this should work. you never know, maybe karate has a bug. please follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue - and note that a simple `* def cpNumber = '100'` should work – Peter Thomas Apr 04 '23 at 15:01
  • * def cpNumber = '100', creating local variable and assigning value to it. But what i'm trying to achieve is to overwrite a config variable that is written in karate-config.js file. – karusai Apr 04 '23 at 15:14
  • I still don't understand your question - but let me just say that once `karate-config.js` runs you cannot over-write variables for *other* scenarios. please read this: https://stackoverflow.com/a/46080568/143475 - and if you still have a question, follow the process I linked above please – Peter Thomas Apr 04 '23 at 15:17
  • Thanks for quick response on this question. I have gone thru above post and agree. But instead restricting to over-write config variables, if we allow user to update, he may use these updated variables in other scenarios. It could be feature at the same time. – karusai Apr 04 '23 at 15:43
  • I have nothing more to add about the design of karate and why every `Scenario` **has** to start from a "clean slate". you are welcome to contribute code via a PR so that others understand what you want. once reviewed, if everyone agrees we can certainly add that code to karate – Peter Thomas Apr 04 '23 at 16:07
  • 1
    Thanks for invitation to contribute code, but I'm not that much expert. I'm a normal qa automation lead and thought to share my views. Any ways its very useful and saving lot of our time in testing api, you really awesome, seeing you/your team developing such a marvel, kudos, keep up good work, thanks a lot again for great support. – karusai Apr 05 '23 at 10:25

0 Answers0