'Karate testing UI : what is syntax entering random value in text field

I am trying to enter a random string in text box using the input(“X-path”,’#(name)’). Script is failing with invalid syntax . Can anyone help me with the correct syntax



Solution 1:[1]

Here is the working sample script created for POC

  • Feature: create order

    Background

    • def now=function(){return java.lang.System.currentTimeMills()} *def ordername='order'+now()

    Scenario: Create random order

  • Given call read('login.feature')

  • Given driver 'url to navigate to another page'

  • And click('#selector')

  • And input("x-path",ordername)

Solution 2:[2]

I think you missed the fact that variables can be used "as is" in JS functions.

* def name = 'foo'
* input('/some/path', name)

The '#(name)' syntax is only for JSON: https://github.com/karatelabs/karate#rules-for-embedded-expressions

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Peter Thomas