TESTEVERYTHING

Showing posts with label Appium. Show all posts
Showing posts with label Appium. Show all posts

Tuesday, 4 August 2015

How to use ADB (Android Debug Bridge) over WiFi | Android automation

Whenever we work with Android mobile app automation we have to connect the device using USB cable. We can connect the device over Wi-Fi. To get rid of from the USB there is a super simple way! All you need is a USB cable (for the initial setup) and have both devices in the same network. This will work for non-rooted devices also.

Precondition: 
  • Your system and device must be in the same network.
  • Android mobile must have developer option set to true.
  • ADB (Android debug bridge) must be configure
  • Android SDK installed.
Step 1. Attach mobile via USB

Step 2. Open then command terminal type adb devices and press enter

It will confirm that your device is connected and able to recognize by android sdk.




Step 3:   type:
adb tcpip 5555
Step 4:To find the mobile ip type:
adb shell ip -f inet addr show wlan0
Step 5: The ip address will be shown in second line like this:
inet 192.168.1.233/24 brd 192.168.1.255 scope global wlan0
where 192.168.1.233 is the ip address of your mobile.
Step 6:Remove USB cable and type:
   adb connect <mobile-ip>:5555

 like:
adb connect <192.168.1.233>:5555 

Note: 
  1. Make sure: that you do not have Android studio running before executing the - 'restart adb in tcpip mode' command
  2. If you have IDE running then adb may have been already started and you may need to restart it in some cases: adb kill-server; adb start-server

Saturday, 25 July 2015

How to know app package and activities information without having apk | android app | Appium

How to know app package and activities information without having apk | android app | Appium

In Android app mobile automation,we need apk file of app but sometimes we have to perform action on inbuild app(pre installed) which come with device like call,sms etc.. for this we do not have apk file. Basically in android app automation we need app package information  and app activities. In case of apk it is easy to get above information with appium. But if we do not have apk and need the app package/activities information, we can use following command:

Precondition: 
1. Android mobile must have developer option set to true.
2. ADB (Android debug bridge) must be configure
3. Android SDK installed.

Step1. Open then command terminal type adb devices and press enter

It will confirm that your device is connected and able to recognize by android sdk.






Step2: Now in mobile, open the app of which you want to get app pkg info/activities. In your mobile, it should be current activated app with focus. Means current window of your mobile should be app like calling/msg/your app window. 

Step3: Now type adb shell and press enter to open the adb shell

Step4: type dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'  and press enter







Above command will show the current activated app info of  your mobile. Now check the value of mCurrentFocus.

First highlighted text is pkg info



Second highlighted text is app activities info


Here you can see that we can use this:





 Thanks



Wednesday, 17 December 2014

Automation Testing of Android app on device using Appium


1)      Run the setup using the below provided location using the URL as :
and click on installer_r24.0.1-windows.exe for windows.

2)      Agree to the terms of service and licence from google and download the installer.
3)      Download the Appium for windows latest version from http://appium.io/ .
4)      Download java-client version for the same latest from location http://appium.io/downloads.html
5)      Set ANDROID_HOME as environment variable providing the path for the SDK till the SDK path
6)      Set the path for platform tools and tools folder specifically like below :
D:\Mobiletesting\MobileSDK\sdk\platform-tools;D:\Mobiletesting\MobileSDK\sdk\tools;




7)      Once the path for tools and platform-tools is set check if the configurations are correct by opening the command prompt and entering the command as
adb devices
If the configurations are correct then the device will be listed as a result of the response for command as above in the screen.
List of devices attached
ZX1B32DBJ3      device
Here ZX1B32DBJ3       is the device connected to the 32 bit machine having SDK setup.
8)      Have an apk file of the application to be tested ready and open appium.exe by running the utility for launching the appium window.
9)      Configure Appium like in the below screenshot :
Application path: Path for the apk file to be tested.
Other fields such as package,launch activity platform version ,automation name,device name all fields will be populated by default.
 
Click on start the appium node server button at the right corner of the window and we can see the below mentioned activity listed when the server is launched.
 
Create a java project using the Android eclipse toolkit and set the properties such as below.

package com.testng;

import io.appium.java_client.AppiumDriver;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.junit.AfterClass;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;

public class  WhatsApp {


WebDriver dr;
   
@Test
public void testApp() throws Exception
{
    //WebDriver dr;
    String contact ="shreekantpandey@gmail.com";
    File app = new File("D:\\Mobiletesting\\WhatsApp.apk");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("browserName","Chrome");
    capabilities.setCapability("deviceName","ZX1B32DBJ3");
    capabilities.setCapability("platformVersion","4.4");
    capabilities.setCapability("platformName", "Android");
    //capabilities.setCapability("app",app.getAbsolutePath());
    //capabilities.setCapability("appPackage","com.testng");
    //capabilities.setCapability("appActivity","com.testng.WhatsApp");
   
    dr= new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    dr.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
   
    dr.get("http://www.apple.com");
   
    dr.quit();

   
}
@AfterClass
public void teardown(){
    //close the app
    dr.quit();
}
}



Where details specific to device and platform are :

DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("browserName","Chrome");
    capabilities.setCapability("deviceName","ZX1B32DBJ3");
    capabilities.setCapability("platformVersion","4.4");
    capabilities.setCapability("platformName", "Android");


and driver are :

dr= new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    dr.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);


Once we have the browser handle we can navigate to any page of our choice like the content here being navigated to
dr.get("http://www.apple.com");

___________________________________________________


2. For Android application related project creation having a launching activity are:
package com.testng;

import io.appium.java_client.AppiumDriver;
import java.io.File;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.junit.AfterClass;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class  NewClass {


WebDriver dr =null;
   
@BeforeMethod
public void setup() throws Exception

{
     File appDir = new File("D://Mobiletesting");
     File app = new File(appDir, "MakeMyTrip_Flights_Hotels_Bus.apk");
     
     
     DesiredCapabilities capabilities = new DesiredCapabilities();
     capabilities.setCapability("app-package", "com.makemytrip");
     capabilities.setCapability("app-wait-activity", "com.mmt.ui.activity.Splashactivity");
     capabilities.setCapability("app-activity", "com.mmt.ui.activity.Splashactivity");
  
    capabilities.setCapability("deviceName","ZX1B32DBJ3");
    capabilities.setCapability("platformVersion","4.4");
    capabilities.setCapability("platformName", "Android");
  
   
    //capabilities.setCapability("browserName","Chrome");

    //capabilities.setCapability("app-activity","com.mmt.ui.activity.Splashactivity");
//    capabilities.setCapability("app",app.getAbsolutePath());
//    capabilities.setCapability("appPackage","com.makemytrip");

   
    dr= new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    dr.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
   
}
@Test
public void loginTest() throws Exception {
    String text;   
    Thread.sleep(5000);

       
     
      dr.findElement(By.className("android.widget.Button")).click();
     
      dr.findElement(By.id("com.makemytrip:id/login_activity_emailId_edt")).sendKeys("shreekant1282@gmail.com");
      dr.findElement(By.id("com.makemytrip:id/login_activity_password_edt")).sendKeys("3093005");
      //dr.findElement(By.id("id/login_activity_password_edt")).sendKeys("3093005");
      dr.findElement(By.id("com.makemytrip:id/login_activity_login_btn")).click();
      WebDriverWait wait = new WebDriverWait(dr,80);
      text = dr.findElement(By.className("android.widget.TextView")).getText();
      if (text.equals("User not valid!"))
      {
          System.out.println("test passed");
      }
      else
      {
          System.out.println("test failed");
      }
      //dr.quit();

      }
@AfterTest
public void teardown(){
    //close the app
    dr.quit();
    //dr.close();
}
}

Where details are for same device but with different .apk file having different launching activity as in the screenshot below.




Sample makemytrip.apk file can be downloaded from anywhere over the internet.


    

Which one is right ?

Translate







Tweet