Saturday, 18 June 2016

Appium - Introduction




-> Appium is mobile application software testing tools.

-> we can automate native app, Web app and Hybrid app by using Appium.

-> Its open source software automation tool which is useful to automate android and IOS platform apps.

-> Appium is cross-platform automation tool so we can write automation tests and run against IOS and Android.


Multiple Platforms Support

Appium support bellow given different platforms.

Android
IOS
FirefoxOS



Multiple Languages Support

Appium supports bellow given languages with the Selenium WebDriver API and language-specific client libraries.

Java
Objective-C
JavaScript with Node.js
PHP
Python
Ruby
C#
Clojure
Perl



Limitations Of Appium

There are few limitation in appium right now.

For Android, No Support for Android API level < 17.
Script execution is very slow on IOS platform.
Gestures support is limited.
No support for Toast messages.


Appuium supports only Android 17+ API level version only.


****************************************

What is Android SDK


-> Androd SDK is software development kit which enables to create application for android platform.

For Example, If you want to create any android software games then we need Android SDK.

-> Also its provides ability to create emulators to test new created games or any other android apps.

-> By using appium we can create and run automation tests for native apps and web apps in android device or emulators. But we need Android SDK is pre-requisite to run tests on android platform using Appium.


*************************************************


Difference between simulator and emulator


The basic difference is Emulator runs for Android OS (Samsung galaxy,htc,motorola,etc,.) but simulator runs for Mac (iOS) iPhone 3g,4,4s,iPod.


Device is Emulator
Software is simulator

Saturday, 4 June 2016

How to create excel sheet using apache poi





By using below code we can create excel sheet using apache poi



code:


public static void main(String agrs[])
{

Workbook book2=verifyExcelVersion(ToFilePath);
Sheet sheet2=null;


createExcelSheet(wb,"Sheet2",Download_FilePath);

}



// create new Excel sheet in workbook

public static void createExcelSheet(Workbook wb, String SheetName, String ExcelPath) throws IOException
{
wb.createSheet(SheetName);
FileOutputStream output_file =new FileOutputStream(new File(ExcelPath));  
wb.write(output_file); 
output_file.flush();
output_file.close(); 

}


// verify Excel version

public static Workbook verifyExcelVersion(String FilePath) throws FileNotFoundException, IOException
{
Workbook book1=null;
String fileExtn=FilenameUtils.getExtension(FilePath);

if(fileExtn.equals("xls"))
book1=new HSSFWorkbook(new FileInputStream(FilePath));
else if(fileExtn.equals("xlsx"))
book1=new XSSFWorkbook(new FileInputStream(FilePath));
else if(fileExtn.equals("xlsm"))
book1=new XSSFWorkbook(new FileInputStream(FilePath));
return book1;
}


How to verify excel sheet present or not in apache poi



By using below code we can verify the perticular excel sheet present or not. If not available we can create by using apache POI command.



code:

public static void main(String agrs[])
{

Workbook book2=verifyExcelVersion(ToFilePath);
Sheet sheet2=null;


if(!isExcelSheetExist(wb,"Sheet2"))
createExcelSheet(wb,"Sheet2",Download_FilePath);

}


// verify Excel Sheet exist or not

public static boolean isExcelSheetExist(Workbook wb, String SheetName)
{
if(wb.getSheetIndex(SheetName)>=0)
return true;
else
return false;

}


// create new Excel sheet in workbook

public static void createExcelSheet(Workbook wb, String SheetName, String ExcelPath) throws IOException
{
wb.createSheet(SheetName);
FileOutputStream output_file =new FileOutputStream(new File(ExcelPath));  
wb.write(output_file); 
output_file.flush();
output_file.close(); 

}


// verify Excel version

public static Workbook verifyExcelVersion(String FilePath) throws FileNotFoundException, IOException
{
Workbook book1=null;
String fileExtn=FilenameUtils.getExtension(FilePath);

if(fileExtn.equals("xls"))
book1=new HSSFWorkbook(new FileInputStream(FilePath));
else if(fileExtn.equals("xlsx"))
book1=new XSSFWorkbook(new FileInputStream(FilePath));
else if(fileExtn.equals("xlsm"))
book1=new XSSFWorkbook(new FileInputStream(FilePath));
return book1;
}




How to create common functions for working with different format of Excel Sheet by using Apache POI



By using below verifyExcelVersion() we can create common function for handle with different Excel format by using Apache POI



code:

public static void main(String agrs[])
{

Workbook book2=verifyExcelVersion(ToFilePath);
Sheet sheet2=null;


if(!isExcelSheetExist(wb,"Sheet2"))
createExcelSheet(wb,"Sheet2",Download_FilePath);

}




// verify Excel version

public static Workbook verifyExcelVersion(String FilePath) throws FileNotFoundException, IOException
{
Workbook book1=null;
String fileExtn=FilenameUtils.getExtension(FilePath);

if(fileExtn.equals("xls"))
book1=new HSSFWorkbook(new FileInputStream(FilePath));
else if(fileExtn.equals("xlsx"))
book1=new XSSFWorkbook(new FileInputStream(FilePath));
else if(fileExtn.equals("xlsm"))
book1=new XSSFWorkbook(new FileInputStream(FilePath));
return book1;
}

how to break out of nested loops java



break;

By using break we can come out from single loop.

But if we want to come out from all nested loop then we shoule use lables for acheiving this concept.



Example:

int points = 0;
int goal = 100;
someLabel:
while (goal <= 100) {
   for (int i = 0; i < goal; i++) {
      if (points > 50) {
         break someLabel;
      }
   points += i;
   }
}
// you are going here after break someLabel;

How to set auto detect proxy settings by using selenium in browser



Normally selenium referred the system proxy settings. If we want to use auto detect proxy setting from selenium code then we have to use different code like below



       org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
       proxy.setAutodetect(true); 
       DesiredCapabilities cap = new DesiredCapabilities();
       cap.setCapability(CapabilityType.PROXY, proxy);
       WebDriver driver5 = new FirefoxDriver(cap);
       
       driver5.manage().window().maximize();

How to Generate XSLT reports by using Ant+TestNG



We have to follow below steps to generate XSLT reports

1) ANT Installation
2) Configure XSLT and build.xml
3) Genrate XSLT report by using ANT

1) ANT Installation

-> Download Latest Version of apache-ant zip
Download latest version of apache-ant from

http://ant.apache.org/bindownload.cgi.

Extract zip folder and save into our local path.

-> Set JAVA_HOME Environment variables

* Right click on My Computer -> Properties and go to -> Advanced tab.
* Clicking on Environment variables button will open Environment variable dialog.
* Click on New button from System Variables box and add Variable Name = JAVA_HOME and Variable Value = Path of your jdk folder.
* Here my JDK folder path is 'C:\Program Files\Java\jdk1.8.0'

-> Set ANT_HOME Environment Variables

* Right click on My Computer -> Properties and go to -> Advanced tab.
* Clicking on Environment variables button will open Environment variable dialog.
* Click on New button from System Variables box and add Variable Name = ANT_HOME and Variable Value = Path of your jdk folder.
* Here my ANT folder path is 'D:\Selenium\apache-ant-1.9.7'

-> Edit Path Variable

* Right click on My Computer -> Properties and go to -> Advanced tab.
* Clicking on Environment variables button will open Environment variable dialog.
* Edit existing Path variable by selecting Path variable from System variables list.
* And click Edit button and insert  %JAVA_HOME%\bin;%ANT_HOME%\bin  at the end of Path variable value string.
* Do not forget to put semicolon (;) before %JAVA_HOME%\bin

-> Copy tools.jar from jdk/lib and paste It In jre/lib
* There will be 2 folders In your C:Program Files\Java folder.
* In my system It Is jdk1.8.0 and jre8.
* Open C:\Program Files\Java\jdk1.8.0\lib folder and copy tools.jar file.
* Open C:\Program Files\Java\jre8\lib and paste tools.jar In to It.

Now restart your system to getting system variables changes effect.

Verify ant configured properly or not
To verify that ant Is configured properly or not, follow the bellow given steps after restarting system
* Open command prompt.
* Type command "ant" and press Enter button.
* It should show you message as bellow.


C:\Users\user>ant
Buildfile: build.xml does not exist!
Build failed





2) Configure XSLT and build.xml


-> The below jar files shoule be under lib folder

* saxon-8.7
* SaxonLiaison
* testng-xslt-maven-plugin-test-0.0
* Selenium-server-standalone 2.47

-> The below files should be under project path

* build.xml  -> Link to download
* testng-results.xsl -> Link to Download

-> Configure build.xml file

• Verify the Value for "project.jars" property at line no 10 of build.xml file. It should be the path of "lib" folder of project.
• Verify the path of testng-results.xsl file at line no 91 of build.xml file. It should be  path of testng-results.xsl.

Note : Don't change any thing else In build.xml file.




3) Genrate XSLT report by using ANT


Once your test execution get completed and testng results generated, We can go to generate XSLT report. You need to follow bellow given steps to generate XSLT report.


-> Open command prompt.

-> Goto your project

E:\Selenium_Project\Selenium_Testing>

-> Type "ant" to check we are in correct path to generate XSLT report.


E:\Selenium_Project\Selenium_Testing>ant
Buildfile: E:\Selenium_Project\Selenium_Testing\build.xml

usage:
     [echo]
     [echo]             ant run will execute the test
     [echo]

BUILD SUCCESSFUL
Total time: 0 seconds


-> Remove Previous Build : Type Command = "ant clear"

 It should give message "BUILD SUCCESSFUL"


E:\Selenium_Project\Selenium_Testing>ant clear
Buildfile: E:\Selenium_Project\Selenium_Testing\build.xml

clear:
   [delete] Deleting directory E:\Selenium_Project\Selenium_Testing\build

BUILD SUCCESSFUL
Total time: 0 seconds


-> Compile And Generate New Build Folder : Type Command = "ant compile".

 It should give message "BUILD SUCCESSFUL"

E:\Selenium_Project\Selenium_Testing>ant compile


-> Verify Build Folder Is Generated : Now Refresh your project In eclipse.
 ant compile command will created new folder with name of  build under your project

-> Execute Test Suites : Type Command = ant run In command prompt and press enter.
It will execute your all software automation test suites which are included In testng.xml file.

 So now you can execute your software test suites from command prompt Instead of testng.xml file.

-> Generate XSLT Reports : Type Command = ant reports In command prompt and press enter.
It should give message "BUILD SUCCESSFUL"

-> open XSLT Report : Once more refresh your project In eclipse.

 ant reports command will create new folder with name = XSLT_Reports under your project


->You will find index.html file In XSLT_Reports folder.
That Is XSLT Report of your webdriver test. Open that file In any web browser.
 It Is Interactive and easy to understand that how many test cases are Pass, Fail and Skip for specific test case.



Note : If pie chart is not available in your report then you will get error message in browser like below


Error Message : SVG Pie Charts are not available. Please install a SVG viewer for your browser


So please install SVG viewer in order to see pie chart in XSLT reports.