1

I am trying to add a conditional logic for karate UI feature that I am trying to build. The requirement is this: There are 5 fields;

  1. select(‘select[id=currency]’, ‘EUR’) // has a random logic to select between USA and EUR in the drop down
  2. Select(‘select[id=bankcountry]’, ‘{^}France’) // this can be either France or USA
  3. Input(‘input[id=iban]’, ‘Fr1234567’) // input field appears when the bank country is France
  4. Input(‘input[id=accnumber]’, ‘1234567’)// the account number and routing number fields are visible only if the bank country is selected as USA
  5. Input(‘#routingnumber’, ‘6765757’)

My requirement is; I want to use if then else such that if the currency is EUR then the bank country should get selected as France and input Iban else if the currency is USD then bank country should get selected as USA and input values account number and routing number. I am at a loss on how to achieve this. Could someone please help?

Eleza
  • 53
  • 5
  • please read this: https://stackoverflow.com/help/someone-answers - until now you have never up-voted or accepted an answer on stack overflow – Peter Thomas Jul 17 '23 at 03:05

1 Answers1

1

My immediate reaction is don't do this and have tests that do random things. Write two different Scenarios for France and USA. Or you can easily do data-driven testing.

Good tests are predictable, and a simple sequence of steps and assertions. Also refer: https://martinfowler.com/articles/nonDeterminism.html

Anyway, here is how you can pick a random value out of a list:

* def pickRandom = function(list){ var index = Math.floor(Math.random() * list.length); return list[index]; }

So you can do this to randomly select a currency:

* def currencies = ['EUR', 'USA']
* def currency = pickRandom(currencies)
* select('select[id=currency]', currency)

Now please refer this answer for tips: https://stackoverflow.com/a/50350442/143475

You can do things like this:

* select('select[id=bankcountry]', ‘{^}' + country)
* if (country == 'France') input('input[id=iban]’, 'Fr1234567')

The rest is up to you.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248