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




Prerequisite:
  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. 

Step1: 


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
C:\Users\<username>\AppData\Roaming\npm


After installation appium we need to start appium server. 

appium -a 127.0.0.1 -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.net.MalformedURLException;  
 import java.net.URL;  
 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.*;  
 import io.appium.java_client.android.AndroidDriver;  
 public class WhatsAppAutomate {  
 // WebDriver driver;  
 protected AndroidDriver driver;  
 @BeforeClass  
  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("http://192.168.0.102:5036/wd/hub"), capabilities);  
 }  
  @Test  
  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");  
  break;  
  }  
  if (driver.findElements(By.xpath(xpath)).size() > 0) {  
  loop = false;  
  System.out.println("element found");  
  WebElement elm = driver.findElement(By.xpath(xpath));  
  if (click)  
  elm.click();  
  } else {  
  if(direction.toUpperCase().equals("UP")){   
  starty=size.height-offset;  
  endy = (int) (size.height * 0.60);  
  driver.swipe(startx, starty, startx, endy, duration);  
  Thread.sleep(waitTime);  
  }else if(direction.toUpperCase().equals("DOWN")){  
  starty = (int) (size.height * 0.80);   
  endy= offset;  
  driver.swipe(startx, endy, startx, starty, duration);  
  Thread.sleep(waitTime);  
  }   
  count++;  
  }  
  }  
  } catch (Exception e) {  
  System.out.print(e);  
  } finally {  
  driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);  
  }  
  }  
  @AfterClass  
  public void teardown() {  
  // close the app  
  driver.quit();  
  }  
 }