Add a custom keyword in the test case without automatically adding a parameter default value

I have customized a keyword, and give a default parameter value of 1, but when I add it at test case, the input column always sets to 0, how do I need to solve this problem?

You should show the codes here.

Hi, I have uploaded my code picture in the post, please help me answer, thank you.

This is my custom keyword:

This is what I added in my use of custom, IPUT is not I expected 1 but 0.

You showed your Test Case in “Manual” view … difficult for me to understand.

Could you show your Test Case in “Script” view?

I mean this, I first customize a sliding keyword, I hope the default value of the parameter “n” of the keyword is 1, so I wrote this:
** def swipe_right(int n=1){**
** int y = MobileBuiltInKeywords.getDeviceHeight()**
** int x = MobileBuiltInKeywords.getDeviceWidth()**
** for (i in 0…n-1) {**
** MobileBuiltInKeywords.swipe((x0.2).toInteger(), (y0.5).toInteger(), (x0.8).toInteger(), (y0.5).toInteger())**
** }**
** }**

Then I built a new use case, and I called my custom keyword in the newly built usage:
Script interface -

Manual interface -

This is my custom keyword:

In the test case, you have the following line:


Here you specified 0 as the argument to your keyword. Therefore the keyword received 0.

Yes, of course. The program is working just as you wrote.

But the default parameter value I gave “n” in custom keyword is 1, when I add this keyword, the program is automatically set to me 0, why not 1 but 0? I don’t understand this.

Default arguments

Default arguments make parameters optional. If the argument is not supplied, the method assumes a default value.

def foo(String par1, Integer par2 = 1) { [name: par1, age: par2] }
assert foo('Marie').age == 1

In other words, if the argument is supplied, the method takes the supplied value, not the default value.

def foo(String par1, Integer par2 = 1) { [name: par1, age: par2] }
assert foo('Marie', 0).age == 0

I seem to understand, that is, if I want to use the default value defined in the keyword, I can’t pass the “n” parameter, does that mean? But whenever I add a custom keyword in a test case, the program seems to pass a 0 to the parameter “n” by default. What do I need to do to make the program pass 1 by default or not pass any value to it every time What about the parameter “n”? Thank u.

you cannot achieve that in ‘manual’ view.
this is how the ui decide to pass somethin to your custom keyword.
simply stop using manual view and use only script view

In the Manual view, Why not you write “1” in the “Value” column of the row for “n” ?

I have the same opinion as @bionel

Manual view disturbs Groovy’ s “default parameter” syntax: def function(int n=1)

If you want the “default parameter” syntax to work, you should use Script mode. Shouldn’t go back to the Manual mode.