Hi,
Can anybody please explain how to create custom keyword for mobile action then how to call the same in Test Case?
I am trying to create custom keywords for swipe and scroll but it is not working, please have look at the code below:
***********************************************************************
public void swipeuntil(String widgetText) {
AndroidDriver driver;
boolean found=false;
while(!found) {
try {
driver.findElement(By.xpath(“//android.widget.TextView[@text='”+ widgetText +“']”));
found=true;
}
catch(Exception e) {
Dimension size = driver.manage().window().getSize();
int startx=size.width/2;
int starty=(int)(size.height*0.5);
int endx=size.width/2;
int endy=(int)(size.height*0.2);
driver.swipe(startx, starty, startx, endy, 1000);
}
}
}
***********************************************************************
Already tried the method:
Mobile.scrollToText(‘Testtext’, FailureHandling.STOP_ON_FAILURE)
but it is not working for me, it is throwing error as:
07-26-2018 04:19:20 PM - [ERROR] - Cannot invoke method manage() on null object
07-26-2018 04:19:20 PM - [END] - End action : commonLibrary.commonLibrary.swipeuntil
07-26-2018 04:19:20 PM - [ERROR] - Test Cases/Test/SwipeTest FAILED because (of) java.lang.NullPointerException: Cannot invoke method manage() on null object
looks like driver is null, not sure how to resolve it
also tried with updated method:
@Keyword
public void swipeuntil1(String widgetText) {
AndroidDriver driver;
boolean found=false;
while(!found) {
try {
//Mobile.findElement(By.xpath(“//android.widget.TextView[@text='”+ widgetText +“']”));
Mobile.findElement(By.xpath(“//hierarchy/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.RelativeLayout[1]/android.support.v4.view.ViewPager[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.ListView[1]/android.widget.LinearLayout[2]/android.widget.TextView[1]”));
found=true;
}
catch(Exception e) {
//Dimension size = Mobile.getDeviceWidth()
int startx=Mobile.getDeviceWidth()/2;
int starty=(int)(Mobile.getDeviceHeight()*0.5);
int endx=Mobile.getDeviceWidth()/2;
int endy=(int)(Mobile.getDeviceHeight()*0.2);
Mobile.swipe(startx, starty, startx, endy, 8000);
}
}
driver.findElement(By.xpath(“//android.widget.TextView[@text='”+ widgetText +“']”)).click();
}
still not working, it is giving issue as
**************************************************
ovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords.swipe() is applicable for argument types: (java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Integer) values: [540, 888, 540, 355, 8000]
Possible solutions: swipe(int, int, int, int), swipe(int, int, int, int, com.kms.katalon.core.model.FailureHandling), grep(), wait(), dump(), find()
*******************************************************
Please suggest?
Regards