Showing posts with label appium. Show all posts
Showing posts with label appium. Show all posts

How to install appium

How to install appium through npm

Appium Server
Appium is a server written in Node.js

Warning: Appium Desktop is Not Appium

Appium Desktop is a graphical frontend to Appium with additional tools. Appium Desktop is released on its own cadence and has its own versioning system. If you are reporting an issue with Appium Desktop, always be sure to include both the version of Appium Desktop and the version of the Appium Server which is in use

  1. Install JAVA 8 and set JAVA_HOME variable and Path variable for java. 
  2. Install android sdk and set ANDROID_HOME variable and also set the adb path
In this article, I will show you how to install appium server and run the server through the command line. 


Download node.js from node.js website.  I will download the LTS version. 

Ensure you select to install the npm tools and the system paths:

Step 2:

Now I am going to install appium using npm command. 

If you want to install appium latest version then you need to use below command 

npm install -g appium

If you want to install appium specific version then you need to use below command 

npm install -g [email protected]

If you want to uninstall appium , you need to execute below command 

npm uninstall -g appium

In this blog, I am going to install appium version 1.7.2 

You will find appium installed under below path in your system

After installation appium we need to start appium server. 

appium -a -p 4723

where -a is the IP address (here localhost) and -p is the port

After the server run successfully you will see something like this 

How to do scroll action till the particular element is present in appium

How to do scroll action till the particular element is present in appium ?

How to do scroll action till the particular element is present or not
I am currently working on appium for automating WhatsApp mobile application. I needed one method which would perform the ‘scroll’ action to a particular name or number and choose to click on a particular name or number. So I googled for that method and I found out that there are two methods, scrollTo(), scrollToExact(), which was supposed to solve my problem. But when  I started writing the code and again I faced another problem.  I am using appium java client 5.0.0-BETA9 (updated version )and on this version, there are no such methods like scrollTo() or scrollToExact().  Previously I had worked on the seetest tool and it is a mobile automation tool, there was a method called ‘swipewhileNotFound’ which would scroll the app view until the desired object was visible.  SeeTest is a licensed tool. Hence there are several readymade methods available for automating mobile application.  So I started writing this method for appium because I needed this method for appium to work.

I have used TestNG to write the test, but you can use any testing framework or simple Java class with the method mentioned above. I have posted my code here so that you can have a look at it. Also, you can download the complete java file from the below link

How to do scroll action till the particular element is present or not

 package appium;  
 import java.util.concurrent.TimeUnit;  
 import org.openqa.selenium.By;  
 import org.openqa.selenium.Dimension;  
 import org.openqa.selenium.WebElement;  
 import org.openqa.selenium.remote.DesiredCapabilities;  
 import org.testng.annotations.*;  
 public class WhatsAppAutomate {  
 // WebDriver driver;  
 protected AndroidDriver driver;  
  public void setUp() throws MalformedURLException {  
  DesiredCapabilities capabilities = new DesiredCapabilities();  
  capabilities.setCapability("deviceName", "8fe5de4a");  
  capabilities.setCapability("platformName", "Android");  
  capabilities.setCapability("appPackage", "com.whatsapp");  
  // This package name of your app (you can get it from apk info app)  
  capabilities.setCapability("appActivity", "com.whatsapp.Main");   
  driver = new AndroidDriver(new URL(""), capabilities);  
  public void testCal() throws Exception {  
  swipeWhileNotFound("down","//*[@text='Anjan Mondal']",1000,3000,3000,17,true);  
  public void swipeWhileNotFound(String direction, String xpath,int offset,int waitTime,int duration,int round, boolean click) throws InterruptedException {  
   Dimension size = driver.manage().window().getSize();  
  int startx = size.width/2;  
  int starty=0;  
  int endy=0;  
  try {  
  driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);  
  boolean loop = true;  
  int count = 0;  
  while (loop) {  
  if (count == round) {  
  System.out.println("round over");  
  if (driver.findElements(By.xpath(xpath)).size() > 0) {  
  loop = false;  
  System.out.println("element found");  
  WebElement elm = driver.findElement(By.xpath(xpath));  
  if (click);  
  } else {  
  endy = (int) (size.height * 0.60);  
  driver.swipe(startx, starty, startx, endy, duration);  
  }else if(direction.toUpperCase().equals("DOWN")){  
  starty = (int) (size.height * 0.80);   
  endy= offset;  
  driver.swipe(startx, endy, startx, starty, duration);  
  } catch (Exception e) {  
  } finally {  
  driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);  
  public void teardown() {  
  // close the app  

your ad