Showing posts with label Core Java. Show all posts
Showing posts with label Core Java. Show all posts

Saturday, November 25, 2017

Android : How to get the package name of Android application

How to get the package name of Android application


There are multiple ways in which we can obtain the package name of Android .apk file. 
Here are the some quick ways to get the package name.


Step 1 : If its public app and available in https://play.google.com/store/apps , then search the app name and click on that particular app. you will get the package name as shown in below screenshot.



















Demo of Step 1 :






Step 2 : Install the app on your device and run the below command to get the list of packages and search for your app. 
 *(Make sure ADB configured in your path variable, click here to know how to configure adb on Windows , For Mac - you can click here )

-> adb shell pm list packages 












Demo of Step 2 :




Step 3 : Again using the Android command , you can get the details of app , package name

-> aapt dump badging <path of apk> | grep <any_relevant_search_text>

for example :
-> aapt dump badging D:\facebook.app | grep package









   ** aapt stands for Android Asset Packaging Tool .


Demo of Step 3 :




Step 4 : [This step is now obsolete, as Appium UI has changed , if you have OLD Appium setup , you can still use it ] If you have Appium installed and locate the .apk file and it will list the package name as shown in below screenshot.
























You can choose any above mentioned steps to get the package name of your app. Some other ways are also present to get the app name.But here i listed few easy way to get the package name. 

If you like this, please subscribe my Youtube channel,like ,comments & share.

Sunday, September 17, 2017

Java : How to read data from properties file

How to read data from properties file


The Properties class represents a persistent or defined set of properties. The Properties can be saved to a stream or loaded from a stream. Each key and its corresponding value in the property list is a string.
Because Properties inherits from Hashtable, the put and putAll methods can be applied to a Properties object.

The Properties file is highly used in automation. Let see with an example.

package com.qahumor;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Properties;

public class Reading_PropertyFile {

 /*
  * @author : Qahumor Reading Properties file in Java
  */

public static void main(String[] args) {

// Create an Object of Properties class.
Properties prop = new Properties();

// Get the path of properties file which you have created in your project.
// System.getProperty("user.dir") - help to read the root directory of your project.
// Change the below path accordingly.
String path = System.getProperty("user.dir") + "/src/config/test.properties";

// Print the path of file for Debug purpose
System.out.println("Debug : Properties file path :" + path);

try {

// Reading the File input stream
 FileInputStream fs = new FileInputStream(path);

// Load the file into memory
 prop.load(fs);
   
} catch (Exception e) {
 e.printStackTrace();
}

// Read the value from Property file - test.properties
System.out.println("\nVersion of the Property file is : " 
    + prop.getProperty("version"));

}

}

Output:

Version of the Property file is : 3.1.4




@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

To create a property file:
1. You can open a notepad
2. Type below content in it.
    version=3.1.4
    login=admin
    pswd=xxxx
3. Save it name "test.properties" in double quotes.
4. You can download the sample property file from Link


Thank you!!





Sunday, December 27, 2015

Appium : Step by step Native IOS App Automation - Part 3(iOS Simulator)

In this Part 3 , we are talking about iOS Simulator command line commands.

How this will be helpful in automation:
This will helpful in checking/verifying your iOS app whether it’s working fine without Appium or any other automation tool in picture. Once you find your app works well then you can go for automation with Appium, this is just to save your time from unnecessary troubleshooting.

Here we start with some useful and important commands

1. To get the list of Simulators available in your system , you can type below command
-> Open Terminal and type below command
                        xcrun instruments -s

2. To launch Simulator using command line , you can type below command and provide same of simulator as you got from step 1 above
-> Open Terminal and type below command
$ xcrun instruments -w "iPhone 6 (9.2)”   // replace with your Simulator name

3. To install app on Simulator using command line once Simulator is up and running, you can type below command
-> Open Terminal and type below command
                        xcrun simctl install booted <app path>
                  e.g xcrun simctl install booted /Users/macuser/Desktop/UIKitCatalog.app

4. To launch an installed app on your simulator , type below command(you can also click/tap the app and launch in simulator using mouse )
-> Open Terminal and type below command
                        xcrun simctl launch booted <app identifier>  

// To get an app identifier or Bundle Identifier you can get it from info.plist file
     e.g xcrun simctl launch booted com.example.apple-samplecode.UIKitCatalog


if you are interested to learn more about all available subcommands you can get by running
          $ xcrun simctl

Hope this helps to get acquainted yourself with basic as well as important iOS simulator commands.click here for Part 2

In Part 4 , we will see the sample demo program of iOS Native App automation using Appium. Stay tuned.


Appium : Step by step Native IOS App Automation - Part 2 (Xcode)



In this Part 2, we are learning about Xcode usage like - building a project, running an application on iOS Simulator.

As you know Xcode is IDE provided for Apple software development. Once you build your project, you can deploy your app on Simulator. 

Now we start with creating a project in Xcode. Since we will be working with Sample IOS Application (UICatalog) which can be downloaded from link provided in Part 1


1. Once you download UICatalog Sample Code, go to the folder and click on UIKitCatalog.xcodeproj





2. It will open in Xcode and looks like this


3.Now on Xcode click on: Product -> Build for -> Testing and you will observe build Succeeded message

4. Again go to Product menu and click on Run, you will see iOS Simulator booting up.
 (Make sure to choose installed simulator on your Mac OS using - Product->Destination->IOS Simulator on Xcode)

5. You can see UIKitCatalog app installed on your iOS Simulator 

If you want to add more devices (iOS simulators), you can go to 

  On Xcode :  Window ->Devices , it will open a Devices Windows



You can go to bottom-left and click on + sign and add your simulator.

Hope this helps, click here for Part 1


Please stay tuned for Part 3, where you will learn running iOS simulator using command line etc.

Appium : Step by step Native IOS App Automation - Part 1 (pre-requisites)

Appium is an open-source mobile automation framework which supports automation on both iOS and Android platforms. It has become one of the most popular choice among mobile app automators.

In this post, I will walk you through the step-by-step setup guideline which are necessary before starting iOS automation. 

To setup iOS automation below are the pre-requisites:

1. Mac OSx machine 
    - supports OS X 10.7+ onwards

2. Xcode - (for supported version, visit http://appium.io)

   You have to download Xcode + Command Line Tools.
   - download Xcode from Apple App Store.

  - download Command Line tools follow the steps mentioned below
        -> Open Terminal and type below command  
                    $ xcode-select --install 
-> You will get software update pop-up, click on Install button.

3. Appium

 - download Appium app from http://appium.io


4. JAVA
   - download and install JAVA.
   - Once installed, configure environment variable in Mac OS as mentioned in steps below.
Step-1 Open Terminal and type below commands
                        $ open -e .bash_profile

Step-2 Save the below line
                         $ export JAVA_HOME=$(/usr/libexec/java_home)

Step-3 Refresh the file using below command
                         $ source .bash_profile

Step-4 Check if the JAVA_HOME is set properly
                         $ echo $JAVA_HOME


5. Eclipse / or any other IDE of your choice
 - download IDE of your choice, I will be showing demo using Eclipse IDE.

6. Install Homebrew (http://brew.sh)
   This is required to install software on Mac machine
          -> Open Terminal and type below command
                      $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

7. Install idevicceinstaller
         -> Open Terminal and type below command
                     $ brew install --HEAD ideviceinstaller

8. Download Sample iOS App project ( UICatalog) from below link:


Please stay tuned for Part-2which continues with some basic knowledge and troubleshooting steps required for iOS automation like building a project in Xcode, installing .app on iOS simulator etc.

Sunday, November 29, 2015

Selenium WebDriver : How to handle frame in webpage using selenium automation.

/*
 * @author : P programs
 * Selenium WebDriver : How to handle frame in webpage using selenium automation. 
 *
 */

An iframe is nothing but a webpage within a webpage.
Multiple iframe can be present in a webpage . To work or extract data from frame is not straight forward.We can't directly access iframe using code i.e we need to switch to frame before extracting any data or perform any operation.
We can use driver.switchTo().frame("pass_frame_index or frame_name") function to jump to particular frame in webpage.
Here is a self explanatory example in Selenium web driver.



import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class FrameHandlingInSelenium {

 public static void main(String[] args) {

  
  WebDriver driver = new FirefoxDriver();
  driver.get("http://www.w3schools.com/html/tryit.asp?filename=tryhtml_iframe_height_width");
  
// First of all we need to get the list of frames present in page. we can use iframe tagname as a locator. 
  List<WebElement> pageframeList =driver.findElements(By.tagName("iframe"));

// For debugging purpose , print the size of available frames.  
  System.out.println("Total list of frames ina page. size = " + pageframeList.size()); 

// Once you identified the desired frame where you want to retrieve data, switch to that frame   
  driver.switchTo().frame("iframeResult");

// In this example, we are again going to inner frame to retrieve data.
// Get the list of all frames inside the outer frame.  
  List<WebElement> frameIn =driver.findElements(By.tagName("iframe"));
  System.out.println("Inner frame size :-" +frameIn.size());

// Either you can switch to frame using frame name or frame index.Since in this example only one frame is present
// inside.so we are directly switching using index 0.   
  driver.switchTo().frame(0);

// Now print the text inside the frame 0 using valid xpath.  
  System.out.println(driver.findElement(By.xpath("html/body/h1")).getText());
  
  driver.quit();  
 }

}

How to install Robot Framework on your Windows OS?

Robot Framework is an   open-source automation framework   mainly used for: Test automation  (acceptance testing, regression testing, system...