Reputation: 1
I am testing android application
I am stuck here please help.
Upvotes: 0
Views: 8609
Reputation: 89
I wrote a code to swipe form with direction, it's working for me home this helps you.
The below is the code for swipe up and down
if (Direction.equalsIgnoreCase("Up")) {
startX = size.width / 2;
startY = ((int) (size.height * 0.80) - Offset);
endX = startX;
endY = (int) (size.height * 0.20);
}
//down
else if(Direction.equalsIgnoreCase("down")) {
startX = size.width / 2;
startY = ((int) (size.height * 0.20) + Offset);
endX = startX;
endY = (int) (size.height * 0.80);
}
pointOption = new PointOption();
new TouchAction<>(getDriver()).press(pointOption.point(startX, startY)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000)))
.moveTo(pointOption.point(endX, endY)).release().perform();
Upvotes: 0
Reputation: 505
// create a method name scrollTo or any name of your choice , with below mentioned code it will take parameter of text using which we want to scroll :
public void scrollTo(String text){
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+text+"\").instance(0))");
}
Upvotes: 1
Reputation: 2140
My example is from python but it will work for Java as well just use java syntax to find element like
driver.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains("**/Put some text of scroll screen/**").instance(0))')
Or using java syntax
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\"**/Put some text of scroll screen/**\").instance(0))")
Upvotes: 3
Reputation: 1135
driver.scrollTo("Tabs");
is no more
In java client 4.0 version, scrollTo and scrollToExact are deprecated.
You have to use driver.swipe()
Upvotes: 0
Reputation: 3004
while testing your app using appium, use the below code to swipe vertically:
Dimension size = driver.manage().window().getSize();
int starty = (int) (size.height * 0.80);
//Find endy point which is at top side of screen.
int endy = (int) (size.height * 0.20);
//int endy = (int) (size.height * 0.10);
//Find horizontal point where you wants to swipe. It is in middle of screen width.
int startx = size.width / 2;
//Swipe from Bottom to Top.
driver.swipe(startx, starty, startx, endy, 3000);
this will vertically swipe down your screen.
you can also try this line to scroll:
// Scroll till element which contains Tabs text.
driver.scrollTo("Tabs");
as you are facing with your android driver, declare it like below:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","fevicename");
capabilities.setCapability("platformName","Android");
//add more according to your requirement
public AppiumDriver<WebElement> driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Upvotes: 0
Reputation: 2533
Just wrap all that inside a ScrollView
:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Here you put the rest of your current view-->
</ScrollView>
ScrollView can contain just one item (only one layout as child)... so if you had something like this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- bla bla bla-->
</LinearLayout>
You must change it to:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- bla bla bla-->
</LinearLayout>
</ScrollView>
For reference you can raed..
https://developer.android.com/reference/android/widget/ScrollView.html
or Simple ScrollView example...
http://stacktips.com/tutorials/android/android-scrollview-example
Upvotes: 0