Tuesday, November 7, 2017

Enabling Keyboard input in Android Emulator

Open Android Studio.
Open AVD Manager.
Click on Edit for the device which you want to have keyboard input.
Click on Show Advanced Settings. 
At last there is a option called "Enable Keyboard Input"



Enable that.. Save and start the emulator. Now you can use your keyboard with emulator.


Monday, November 6, 2017

Emulator Proxy Settings - Android Studio

With the emulator open, click More , and then click Settings and Proxy. From here, you can define your own HTTP proxy settings.

Refer to the below Image.




Give the proxy URl and port number and also if authorization required give those details. apply.

now open browser in emulator and check.

It worked for me. Hope it will help others too :)

Thursday, November 2, 2017

Steps to Automate LinkedIn Android app[Package+activity+capabilities]

1) install Appium + Node

2) Install Android Studio as well and create a virtual device on that i have created with name : Nexus_5X_API_25_1

3) Download LinkedIn.apk file from below link.

4) Now For automating any android app we need to know the package and activity names.
So Lets find them.

For this set your PATH variable to point to below directories.

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/build-tools/26.0.2

above version can be anything in my case it is 26.0.2

after setting the above path variables run the below command.

aapt dump badging “<Path to LinkedIn.apk>” 

Output of above command will contain below 2 values.

package: name='com.linkedin.android'
launchable-activity: name=‘com.linkedin.android.authenticator.LaunchActivity'

5) So we got the package name and activity name too. Now we should frame the desired capabilities section. Like this(In my machine)

{
  "platformName": "Android",
  "deviceName": "Android Emulator",
  "app": "/Users/sriramkukkadapu/Downloads/LinkedIn.apk",
  "automationName": "Appium",
  "platformVersion": "7.1.1",
  "appPackage": "com.linkedin.android",
  "appActivity": "com.linkedin.android.authenticator.LaunchActivity",
  "avd": "Nexus_5X_API_25_1”
}


6) Now start appium with above capabilities and you can see it will open the app :)

Assuming my appium/node server is running on url : http://127.0.0.1:4723/wd/hub
You can check the status of the server with this url http://127.0.0.1:4723/wd/hub/status

Note: IP and the port number values would be the one which we give, when we start the node/appium server

Code:


public class AndroidDriverEx {
public static void main(String args[]) throws IOException, InterruptedException
{
    WebDriver driver=null;
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName","Android Emulator");
    capabilities.setCapability("platformName","Android");
    capabilities.setCapability("app", "/Users/sriramkukkadapu/Downloads/LinkedIn.apk");
    capabilities.setCapability("automationName","Appium");
    capabilities.setCapability("platformVersion","7.1.1");
    capabilities.setCapability("appPackage","com.linkedin.android");
    capabilities.setCapability("appActivity","com.linkedin.android.authenticator.LaunchActivity");
    capabilities.setCapability("avd","Nexus_5X_API_25_1");
    driver=new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    Thread.sleep(3000);
    driver.quit();
}

Now we are good to go and automate all the actions which you wanted to automate.


Sunday, October 22, 2017

Installing Appium + Node - Mac


Following steps worked for me[On Mac OS]. 

Mac OS : 10.11.6 OS X EI Capitan
Xcode : 8.1
Appium : 1.6.0
Appium GUI : 1.2.3 dmg
npm : 5.4.2(after upgrade)
node: 6.3.0

Prior to this you need to have XCode[for iOS] and Android Studio[for Android] installed in your machine.

For Appium we need to install Node JS and also carthage.



1)  Install Node and set proxy for node.

Download and install this node pkg. It will install npm too.


If your machine is behind a proxy then Set Proxy using below commands

npm set proxy http://<proxy url>:<port>
npm set https.proxy https://<proxy url>:<port>


Set No proxy variable.
export no_proxy=localhost,127.0.0.1
export http_proxy=http://<proxy url>:<port>


2)  Install carthage


3) we need to upgrade the node version and the install appium.

Upgrading npm
sudo npm install npm@latest -g

Set All Proxy and then install appium because it downloads chromedriver.zip using curl
export ALL_PROXY=<proxy url without http>:<port>
export no_proxy=localhost,127.0.0.1
export http_proxy=http://<proxy url>:<port>

npm set proxy http://<proxy url>:<port>
npm set https.proxy https://<proxy url>:<port>

Run 
npm install appium@1.6.0


It will take some 10 min time for installing.

Once the installation is successful. verify appium directory inside node.

cd~ 
/Users/sriramkukkadapu/node_modules/appium

4)
Install appium-doctor
npm install appium-doctor

npm install appium-doctor –g


after it is done type this command. it will show us if anything is wrong.
appium-doctor


If it shows JAVA_HOME bin is not set properly then run this commands or set JAVA bin path.

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
export PATH=$PATH:$JAVA_HOME/bin


5) To authorize npm for iOS

npm install -g authorize-ios appium-doctor appium-gulp-plugins authorize-ios



6)  Install appium 1.2.4 dmg file. This is for appium GUI
https://github.com/appium/appium-desktop/releases/

Before starting Appium server make sure Xcode is pointed to right path.
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

If Xcode is not set properly errors might come.

In the appium you need to specify the capabilities for appium server to start. I am listing the capabilities which i have used, for iOS and Android apps. modify them accordingly and point appium to your mobile app with "app" : <path> parameter

Once the capabilities are defined(for any deivce ex: iOS or Android)

Open appium(GUI). Click on Start Inspector Session.
Select the configuration(any of the capabilities below) and
Click on Start Session.

Capabilities are below for iOS

{
  "platformName": "iOS",
  "deviceName": "iPhone 7",
  "app": "/Users/sriramkukkadapu/TestApp.app",
  "automationName": “XCUITest”
}


Capabilities for Android

{
  "platformName": "Android",
  "deviceName": "Android Emulator",
  "app": "/Users/sriramkukkadapu/TestAPP.apk",
  "automationName": "Appium",
  "platformVersion": "7.1.1",
  "appPackage": "<app package>",
  "appActivity": “<app activity>”
 "avd": "Nexus_5X_API_25_1"
}

If we dont specify avd prameter
For Android devices(if it says cannot recognize any devices)
then open android studio start any device
and run this command to check the device status. Android_HOME/platform-tools has this command

adb devices

once device is listed and active it will be recognized by appium.


7) To see the list of Android virtual devices.
emulator -list-avds

my mac has below devices

Nexus_5X_API_25_1
Nexus_5X_API_26_-_Android_8.0


use the same name in capabilities as avd name


Note: 

For Android we all know that .apk is the setup file(which will be used to run the application)
For iOS .ipa is the file which user will be able to install the application but to generate a .ipa file apple license is required so there is a separate .app file which XCode tool generates for us to install it on the virtual device and run the application.

So to run the .apk file we need android studio [Emulator]
to run the .app file we need xcode [Simulator]


Tuesday, October 10, 2017

Setting up Android studio and running a apk file in Emulator in Mac

These steps are for Mac machine.

Installing Android Studio

Setting JAVA_HOME
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/
export PATH=$PATH:$JAVA_HOME/bin/
Verify like this : $JAVA_HOME/bin/java -version

Setting GRADLE_USER_HOME
export GRADLE_USER_HOME=/scratch/skukkada/OMC_Softwares/gradle-2.14.1/
export PATH=$PATH:/scratch/skukkada/OMC_Softwares/gradle-2.14.1/bin

For Mac, download android-studio(which is a dmg file supported for mac)
open the dmg file and drag dmg into applications. it will show Android-Studio in “Finder” or "Launchpad"
open android studio, click next, select default sdk path click on next..
it would ask for proxy give the proxy details(if you are behind a proxy)

Proxy:
http, host='<proxy url>' port=<port> --proxy=http "platforms;android-25”
enable https also

Click next.. Downloading of the components will start.
It will take lot of time even after connecting to lan.

once the android studio opens, go to SDK manager and in Platform, select version from 7,6,5(all) and update. in SDK tools we need emulator. download these packages.


(Not Required) Setting path for Android home
   export ANDROID_HOME=/Applications/ADT/sdk
   export PATH=$PATH:$ANDROID_HOME/bin

For Mac
Android studio automatically sets Android_Home to : /Users/sriramkukkadapu/Library/Android/sdk

if it is not set you can run: export ANDROID_HOME=$HOME/Library/Android/sdk

Installation is done. Now we need to create a AVD(Android Virtual Device or Emulator)

AVD Manager (Or) Emulator

First set these env variables. In Terminal

export ANDROID_TOOLS=$ANDROID_HOME/tools
export ANDROID_PLATFORM_TOOLS=$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_TOOLS:$ANDROID_PLATFORM_TOOLS

Go to Android Studio-> AVD Manager -> create virtual device.
Click Next(device selection)
In the System image. install all the android version images(click download link in each of them and download the packages)
Install 8,7 versions

Once the device is ready, 
Open Emulator


we need to install the apk file of the application which you want to run in Emulator
In the mac terminal go to the path where .apk file is present and run this command.

adb install <testapp.apk>

This command will install the application in the emulator(which is currently running).



Sunday, October 8, 2017

Windows - Schedule Testng.xml to run automatically without Jenkins

1st create a batch file to run Testng.xml automatically.
For Maven project the batch file looks similar to below. If your project is not a maven project(you need to specify the path of the libs explicitly)

set projectLocation=<C:\SVN-IndirectWorkspace\...>
cd %projectLocation%
mvn clean test -DsuiteXmlFile=<Path of testng.xml>
pause

Ex(Maven Project):

set projectLocation=C:\SVN-IndirectWorkspace\TestProj\
cd %projectLocation%
mvn clean test -DsuiteXmlFile=testng.xml
pause

Ex(Normal Project):

set projectLocation=C:\GitRapo\MyProject
cd C:\GitRapo\MyProject
set classpath=C:\GitRapo\MyProject\bin;C:\GitRapo\MyProject\lib\*
java org.testng.TestNG C:\GitRapo\MyProject\testng.xml

Test the bat file once by executing it.

Now we can create a Windows Task to run this batch file on the desired time(Daily/weekly etc).

Follow the steps in this blog post:

http://sriramkukkadapu.blogspot.in/2017/08/how-to-schedule-batch-file-to-run.html




Monday, September 18, 2017

Installing Maven in Mac

1. Download apache-maven-3.5.0-bin.tar.gz from Apache maven website.
https://maven.apache.org/download.cgi

2. extract the above file in any directory in your machine(lets refer as: <directory_maven>)

$ cd <directory_maven>
$ ls
(should list all contents)
$ export M2_HOME=/Users/<your username>/<directory_name>/apache-maven-3.5.0

Ex(in my machine): /Users/sriramkukkadapu/Downloads/apache-maven-3.5.0

Note : above path can also be something like /usr/local. provide accordingly.

$ export M2=$M2_HOME/bin

3. This is a important step. JAVA_HOME should be configured properly.
To check the current JDK home. go to the root folder in ur user(just do cd.. multiple times). 
Then go to /Library/Frameworks/JavaVM.framework/Versions/
here you will find current JDK version. Ex jdk1.8.0_144.jdk (in my machine)

Now form the below path with your JDK Version Replaced.

/System/Library/Frameworks/JavaVM.framework/Versions/<Your JDK Version>/home

Ex(My machine) : /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/home

Now Set JAVA_HOME Variable.

$ export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/home

4. Setting Path Variable to Java_Home/bin.

$ export PATH=$M2:$JAVA_HOME/bin:$PATH

5. Done, Now check maven version

$ mvn –version


Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T01:09:06+05:30)
Maven home: /Users/sriramkukkadapu/Downloads/apache-maven-3.5.0
Java version: 1.8.0_144, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8

OS name: "mac os x", version: "10.11.6", arch: "x86_64", family: "mac"

Hope it is useful :)