Andoid Appium coding examples

Hi Friends,

I set up the environment, Appium for Android and done some positive flows for apps.

Now i want to learn framework so i need your help friends kindly help me and suggest any websites/tutorials for learning process.

Thanks in Advance

1 Like

You can check Toolsqa.com for frameworks.

Appium is independent of frameworks

Hi @amitjaincoer191 in toolsqa NO frameworks for Appium.

I already said Frameworks are independent of Appium / Selenium.

Hi @amitjaincoer191 thank you and sry am not noticed tat

@amitjaincoer191 hi how to handle listview/dropdown in app ?? kindly hlp me

from above screenshot i want to click and select the India (+91).


After click on Country(id: text_country_name) pop up open with the list of Country now i want to select Country India from this list (id:rl_row_countryname)

Kindly help me out

how to write code or take xpath for this ??

can you post ui automator screenshot of this view ?

Hi @amitjaincoer191 Ya sure kindly find the below screenshot from UI Automator

Screenshot 2: Country list view. Here i have to select country from Netherland to India.

And also please tell how to take XPATH in appium @amitjaincoer191

Thanks and am awaiting for your reply.

1 Like

Hi,

Here you can select country using following xpath :

//android.widget.TextView[@text=‘India’]

Above is xpath to select country India , you can replace country name as per your need.

So it will be driver.findElement(By.xpath("//android.widget.TextView[@text=‘India’]"));

Hope this help you…

Hi @iRANG_QA Thanks for ur reply but its not working yar :worried:

Shows below error:

org.openqa.selenium.UnsupportedCommandException: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource. (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 31 milliseconds

UI Automator won’t find elements that are not displayed on screen. You have to scroll to it.

Tried this is working for me. So here It will start scrolling until given country “Malta” is not found and once found it will be clicked and scrolling loop will be closed. This is tested code, it should work.

  @Test
public void HandlingScrollonList() throws InterruptedException{

	Thread.sleep(3000);
	
	_driver.findElement(By.id("chillitalk.mundio.com:id/btn_signup")).click();
	Thread.sleep(3000);
	System.out.println("Clicking " + _driver.findElement(By.xpath("(//android.widget.TextView)[2]")).getAttribute("name"));
	_driver.findElement(By.xpath("(//android.widget.TextView)[2]")).click();
	
	List <WebElement> elem = _driver.findElements(By.xpath("(//android.widget.TextView)"));
	
	System.out.println("elem.size()  " + elem.size());
	System.out.println("elem.get(1).getLocation().getX()  " + elem.get(1).getLocation().getX() + 
					   "  elem.get(1).getLocation().getY()  " + elem.get(1).getLocation().getY());	
	System.out.println("elem.get(elem.size()-1).getLocation().getX()  " + elem.get(elem.size()-2).getLocation().getX() +
					   "  elem.get(elem.size()-1).getLocation().getY()  " + elem.get(elem.size()-2).getLocation().getY());
	
	int x1 = elem.get(1).getLocation().getX();
	int y1 = elem.get(1).getLocation().getY();
	int x2 = elem.get(elem.size()-1).getLocation().getX();
	int y2 = elem.get(elem.size()-1).getLocation().getY();
	TouchAction tAction=new TouchAction(_driver);
	
	do  {
	
		tAction
		.press(x1,y1)
		.moveTo(x2,y2)
		.release()
		.perform();

		Thread.sleep(1000);
		
	if (_driver.findElements(By.name("Malta (+356)")).size()>0)
		_driver.findElement(By.name("Malta (+356)")).click();
	} while (_driver.findElements(By.name("Malta (+356)")).size()==0);
	
}

Hi @amitjaincoer191 : :worried: not working am getting below error amit. how it is working for u ??

FAILED CONFIGURATION: @AfterMethod afterMethod
org.openqa.selenium.UnsupportedCommandException: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 29 milliseconds

can u pls share source code. find the below scrnshot, asks drivr to mobile driver suggestion box.

ok @Alexis can u suggest how to do

Java client 3.1 if u r using it will work…
With 3.1 android/appium driver classes are changed …
So change java client do driver declaration in right way it will work …

As I said it is working on my machine that’s why I passed code to u …

so now what can i do ?? kindly explain what i have to install/import

Just download java_client3-1.jar from maven repository… Remove older version of jar from ecllipse build path … and add new one … It will ask to change declaration of

driver=new AndroidDriver();
Then that touch actions error will go…

Hi @amitjaincoer191 Find the below source code and say what issue is there

configured build path with java client 3.1 as u said refer below scrnshot

package Amzn;

import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;

import java.io.File;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;

public class Chillitalk {
static AndroidDriver driver;

@BeforeMethod
public void beforeMethod() throws Exception {

	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability("automationName", "Selendroid");
	capabilities.setCapability("deviceName", "HT42FWE01991"); /*HTC Mobile*/
	capabilities.setCapability("platformVersion", "5.0.1");
	capabilities.setCapability("platformName", "Android");
	capabilities.setCapability("app", app.getAbsolutePath());
	capabilities.setCapability("appPackage", "chillitalk.mundio.com");

	driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
	driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

@Test
public void login() throws Exception 
{
	driver.findElement(By.id("btn_login")).click();
	Thread.sleep(2000);

//Here i pasted your given code

	driver.findElement(By.id("text_phno")).sendKeys("9876543210");
	driver.findElement(By.id("btn_continue")).click();
	driver.findElement(By.id("text_pin")).sendKeys("1234");
	Thread.sleep(2000);
	driver.findElement(By.id("btn_continue")).click();
	Thread.sleep(5000);

}

kindly help me and sorry to disturb u @amitjaincoer191 . am getting below error.

If you have declared Android Driver correctly then it should work.
Also I suggest you to use selendroid server stand alone 2.46 as newer version like 2.47.1 may have some issues.
Can you join me at “amitjics” on skype. As I had written code base on u r app, so it should work.

k ll cme on Skype. Inbx me whn u free