Setup Android and Genymotion into Eclips and Automation Testing with Appium

Good Artical to step by step setup – http://www.software-testing-tutorials-automation.com/2015/09/steps-to-download-and-install-android.html

Download Appium

Before download and install appium in windows, Please make sure bellow given prerequisites are fulfilled.

  1. JDK Installed. View
  2. Android SDK Installed.
  3. Set ANDROID_HOME and Path Environment Variables.
  4. Eclipse ADT Plugin Installed.
  5. Microsoft .Net Framework, Node JS and PDANet+ for Android Installed.

1.Install the Java JDK and set JAVA_HOME to your JDK folder

  • Download from http://www.oracle.com/technetwork/java/javase/downloads/index.html
  • It opens Java SE Development Kit 8 Downloads page. Download jdk-8u31-window-i58.exe and install it
  • Set JAVA_HOME Variable in your windows system environment variable ex. Select advanced tab -> Click on Environment Variables button. It will open Environment Variables dialog.
  • Set Path Variable For Java

2. Install the Android SDK

  1. Download SDK from http://developer.android.com/sdk/installing/installing-adt.html
  2. Set ANDROID_HOME to be your Android SDK path and add the tools and platform-tools folders to your PATH variable.

androidsdk_path

  1. Need to run the ‘android’ tool (included in the SDK) and make sure you have an API Level 17 or greater API installed. Run “ddms” batch file

androidsdk_tools

Download Genymotion

  • Open https://www.genymotion.com
  • Login in
  • Go to Download page and download Genymotion latest version (i.e. 2.8.0) with VirtualBox. It will download the exe (i.e. genymotion-2.8.0.exe)
  • Now run the setup. It will install to default location (C:\Program Files\Genymobile\Genymotion)

Setup plugin in Eclipse

  • Start Eclipse, then select Help > Install New Software.
  • Click Add, in the top-right corner.
  • In the Add Repository dialog that appears, enter “ADT Plugin” for the Name and the following URL for the Location: https://dl-ssl.google.com/android/eclipse/

Install Genymotion plugin into Eclipse

  • Open Eclipse > Help > Install New Software
  • Add Location URL

For Genymotion – http://plugins.genymotion.com/eclipse/

Eclips_ADT_Plugin

  • Click OK.
  • In the Available Software dialog, select the checkbox next to Developer Tools and click Next.
  • In the next window, you’ll see a list of the tools to be downloaded. Click Next.
  • Read and accept the license agreements, then click Finish.
  • If you get a security warning saying that the authenticity or validity of the software can’t be established, click OK.

For Genymotion setup the Preferences in Eclips Window > Preference

Preference_Genymotion

Install Node JS

Download Windows Installer (.msi) file as per your system(32 bit or 64 bit)

https://nodejs.org/en/download/

Capture the Logcat

Option 1 : From Eclipse once you open the emulator we can see the Logs in Logcat Go to Eclipse > Window > Show View > Other and select “LogCat” Eclipse_Logcat Eclipse_Logcat1

Option 2 : Generate the LogCat file From Command prompt (Once set path ..android-sdk-windows\platform-tools

Windows: adb logcat –d > %UserProfile%\Desktop\ellowoyld.txt

Windows: set timestamp=%date:~-4,4%%date:~-7,2%%date:~-10,2%%time:~0,2%%time:~3,2%%time:~6,2%adb logcat –d > “%UserProfile%\Desktop\%timestamp%-logcat.txt” Or

Create .bat file

1) Open notepad, or whatever your preferred text editor is (just not word or an rtf text editor)

2) Paste in your commands: set timestamp=%date:~-4,4%%date:~-7,2%%date:~-10,2%%time:~0,2%%time:~3,2%%time:~6,2% adb logcat –d >”%UserProfile%\Desktop\%timestamp%-logcat.txt” adb logcat –c 3) And save it to your desktop as a “.bat” file with a catchy name

Appium Architecture

Appium

In above figure mention that Client is any IDE (ex. Eclipse) where we write the code to automate an application So client would communicate to Server and Server understand what client will request and communicate with Mobile devices.

Appium is web-server. It follows the client- server architecture. Client would be communicating to server and server would be perform the necessary actions.

Client is initiates the Session. So client would be sending something calls as Desired Capabilities to the server so that server will understand what kind of session does it needs to create. This particular Server would responds back on same Session ID. This session id would be use for all further communication going to made between the client and server.

Appium is returns in Node.js. Appium understand each and every request that is coming form the client so communication is done over the http protocol it uses something call as communication between client and server is done by JSON Wire Protocol. Which means client written in any programming language like JAVA, Ruby, Python etc. and server understand what to do with client request and communicate with mobile devices and response back to client.

Appium communicate with iOS called as UIAutomation. if Android version less than 17, Appium communicate with Android called as Instrumentation and if Android version grater than 17, Appium communicate with Android by UiAutomator.

Appium is an open source, cross-platform test automation tool for native, hybrid and mobile web apps, tested on simulators (iOS, FirefoxOS), emulators (Android), and real devices (iOS, Android, FirefoxOS).https://university.utest.com/how-to-set-up-your-first-android-automation-project-with-appium/

Note – Appium Support from Android API 17 means Support from Android 4.2.2

Setup Appium

https://www.youtube.com/watch?v=WgnusVu9Icg download the JDK, Android SDK, Eclips setup Java and JDK path in environment (Verify in cmd Java -version) setup Android Path Download Appium exe, nodejs Start Appium server – Option 1 – Open appium.exe Option 2 – cmd > go to C:\Program Files (x86)\Appium\node_modules\appium\bin > node appium

  • Download SDK and set-up environment variable

http://developer.android.com/sdk/index.html#Other

Download android-sdk zip file for window or Mac OS

SDK

Extract zip file and Click on SDK Manager.exe

Set up the Environment Variables and path

ANDROID_HOME D:\android-sdk-windows

Add D:\android-sdk-windows\platform-tools and D:\android-sdk-windows\tools under  path after semicolon(;)

Open cmd and type ‘adb’ to test it

  • Download and Setup Nodejs

https://nodejs.org/en/download/

run .msi only it will automatically detect and set the path

  • Download Appium

http://appium.io/downloads.html

Just run the appium-installer setup or run appium server it will automatically download latest version

  • Download Java Client

http://appium.io/downloads.html

Click on Java link under Appium Client Libraries

Download jar ex. 3.4.1

  • PDANet(optional)

http://pdanet.co/

User-full to identify the missing driver to connect your mobile device with PC via USB

  • Download Genymotion

https://www.genymotion.com

Appium_Start

Install APK in mobile device

Run your virtual device or connect mobile device with USB

Open cmd and type adb devices to see connected device

cmd

now type commend ‘adb install <apkpath> <Filename.apk>’ to install apk in connected device

InstallApk

Setup the test apk path in appium before start it

appium

Once Start appium server package and launch activity value set and disable

appiumstart

click on start button on right top corner Find the webelement and xpath from uiautomatorview open the cmd > uiautomatorviewer

How to find the Webelement or xpath of application using uiautomatorview 

Open application in emulator or in real device and start uiautomatorviewer

Press the Device Screen shot button on top2

uiautomateview

driver.findElement(By.id(“io.selendroid.testapp:id/my_text_field”)).sendKeys(“Test”);

Create Appium First Test project in Eclips (https://www.youtube.com/watch?v=Jgqd7oYWx-Y)

 

uiautomatorview

 

 

public class desiredcapb

{

public AndroidDriver driver;

@Before

public void setUp() throws MalformedURLException

{

File appDir = new Faile(“src”); File app = new File(appDir, “app.apk”); DesiredCapabilities cap = new DesiredCapabilities(); cap.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID); cap.setCapability(MobileCapabilityType.DEVICE_NAME, MobileDevices.find(“emulator-5554”)); cap.setCapability(MobileCapabilityType.APP_PACKAGE, “com.sportlobster.android.debug”); cap.setCapability(MobileCapabilityType.APP_ACTIVITY,”com.sportlobster.android.main.MainActivity”); driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub&#8221;), cap);

}

@Test

public void test() throws Exception { WebElement btn_me = driver.findElement(By.id(“bottomBarMeButton”)); btn_me.click();

}

}

How to find APP_PACKAGE and APP_ACTIVITY for apk file

  1. Download and install SDK.
  2. Inside SDK Manager download Tools (Android SDK build-tools) and APIs for recent versions of Android.
  3. Open SDK folder and go to build-tools folder.
  4. Open any folder (example: 21.1.2).
  5. Open a command prompt window in this folder ( Shift+ right click – Open command window here).
  6. Run command “aapt list -a <path_to_apk_we_need_to_test> >manifest.txt” ( this command will write the app manifest in manifest.txt file inside the same folder).
  7. Open the manifest.txt txt file.
  8. At the beginning of the file there should be details about the package including name ( example: com.example.android.contactmanager).
  9. At the end of the file there should be details about activity including name ( example: ContactManager).

appium3 appium4

OR

Install and Run the application in emulator

Open hierarchyviewer.bat from android-sdk\tools

You can see application APK package and main activity to use in script

Find_APK_Pkg_Activity

OR

from Command prompt – Open your application in Device or in Emulator – type command > adb shell >  dumpsys window windows | grep -E ‘mCurrentFocus|mFocused App’ It will give you your application package and main activity of current applicaton e.x   mCurrentFocus=Window{11266800 u0 com.cns.rd/com.realtydaddy.ui.user.AuthenticationActivity}

So APP_PACKAGE = com.cns.rd and APP_ACTIVITY = com.realtydaddy.ui.user.AuthenticationActivity

@Test
public void ValidLoginTest() throws Exception {
WebElement Login = driver.findElement(By.id(“authActivity_btn_SignIn”));
Login.click();
WebElement LoginUserName = driver.findElement(By.id(“fragSignIn_et_emailOrUserName”));
LoginUserName.sendKeys(“buyer”);
WebElement LoginPassword = driver.findElement(By.id(“fragSignIn_et_password”));
LoginPassword.sendKeys(“admin123”);
WebElement SignIn = driver.findElement(By.id(“fragSignIn_btn_SignIn”));
SignIn.click();

}

Issue : Using uiautomatorviewer to quickly get resource-ids as mention in above code but noticed that sometime resource-id field is no longer present in uiautomatorviewer

Solutions : Visibility of the resource id is dependent on Adnroid version. Its supported from Android version 4.3 or later/ from API level 18.

Reference Tutorial

http://www.guru99.com/introduction-to-appium.html

Advertisements

About samp79

Professional Automation Tester
This entry was posted in Android, Appium. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s