Custom Keywords are not working for Android Native applications


#1

I was trying to create custom keywords for Android Native application.

I have added mobile custom keyword under Keywords folder, ie I want add a sample custom keyword just perform tap action.

Snippet here :

class PlayerActions {

@Keyword

def tapOnPlayerLayer_Mobile(TestObject to, int timeout){

KeywordUtil.logInfo(“Tap on Player layer”+ to.getObjectId())

MobileElement mobileElement = MobileElementCommonHelper.findElement(to, timeout)

mobileElement.click()

}

}

Later I have called same from my test scrip

image.png

(4th Step)

in script mode :

CustomKeywords.‘PlayerActions.tapOnPlayerLayer_Mobile’(findTestObject(‘Android_POM/Layout_test’), 0)

While executing the test I get below error:

PlayerActions.tapOnPlayerLayer_Mobile(findTestObject(“Android_POM/Layout_test”), 0)

Elapsed time: 0.096s

Cannot invoke method click() on null object

But if we perform the same using

Mobile.tap(findTestObject(‘Android_POM/Layout’), 0)

test script executes properly.

Is there any bugs in Android Native app custom keywords ? I am able to perform custom keywords calls on Web application.

or is there any problem in custom keyword script ?


#2

Hi @kiran.sk.sdet,

Appium doesn’t support Selenium default click() method for Android app, please use Katalon BuiltinKeyword instead.

Thanks


#3

Thanks @duyluong for reply.

Appium doesn’t support mobileElement.click() ? Then we cannot perform these actions in android custom keywords.

In my use case, I want to add more than one action in a custom keyword, (my use cases are very customized) built in keys will not satisfy my use cases.

Is there any work around?

ie , I planned to write a custom key word for login - this would have 3 actions ( set username, set password, click login button ) and this task will be accomplished simply calling - login custom keyword. This is just a sample, i have hundreds of similar use cases and I dont want to use this as built in key words as I am planning to export these custom keywords to other testers.

Thanks