Last active
May 13, 2019 05:19
-
-
Save murat3/6e694d8485275e9f3326d18c0700f170 to your computer and use it in GitHub Desktop.
Katalon Studio custom Keyword for filling out numbers via Android Virtual Keyboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package nl.zarif | |
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject | |
import com.kms.katalon.core.annotation.Keyword | |
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile | |
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory | |
import com.kms.katalon.core.model.FailureHandling | |
import com.kms.katalon.core.util.KeywordUtil | |
import io.appium.java_client.AppiumDriver as AppiumDriver | |
import io.appium.java_client.android.AndroidDriver as AndroidDriver | |
import io.appium.java_client.android.AndroidKeyCode as AndroidKeyCode | |
/** | |
* Used to fill numbers via the Android virtual keyboard. | |
* | |
* @author Murat Dönmez | |
* | |
*/ | |
class Keyboard { | |
/** Offset for the int value of numbers. Number 1 equals: offset + 1 and so on */ | |
static int KEYCODE_NUMBER_OFFSET = AndroidKeyCode.KEYCODE_0 | |
/** | |
* Fills numbers ( one by one) via the Android virtual keyboard. | |
* | |
* @param numberArray array of int's | |
* @return void | |
*/ | |
@Keyword | |
def static fill(int[] numberArray) { | |
if (numberArray == null) { | |
KeywordUtil.markFailed('input cannot be null') | |
} | |
AppiumDriver<?> driver = MobileDriverFactory.getDriver() | |
println('Driver type: ' + driver.getClass().getCanonicalName()) | |
if (driver instanceof AndroidDriver) { | |
AndroidDriver androidDriver = ((driver) as AndroidDriver) | |
for (int oneNumber : numberArray) { | |
androidDriver.pressKeyCode(oneNumber + KEYCODE_NUMBER_OFFSET) | |
} | |
androidDriver.pressKeyCode(AndroidKeyCode.ENTER) | |
KeywordUtil.markPassed('Numbers filled out successfully: ' + numberArray) | |
} else { | |
String msg = 'Currently only AndroidDriver is supported' | |
KeywordUtil.markFailed(msg) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment