Thursday, February 2, 2017

Appium Test for Android App

About Appium:
Appium is open source automation tool for iOS and android application supported by Sauce Lab. It is cross platform, supported Native, Hybrid iOS and android application. At backend it uses webdriver JSON wire protocol to communicate with iOS and android applications.
Appium supported many languages like Webdriver. You can write your test scripts any language that has selenium client library.
Appium support UIAutomator framework for ios and android library (For newer Api) and use selendroid for older android platform.
In this post I will show you how to setup and create Appium android script in java language.

Prerequisite: 
1. JDK should be installed and java home path setup in your machine.
2. Android SDK should be installed on your machine and android path should be setup in your machine
3. Appium for window download from: 
download
4. Selenium jar file from: 
download
5. Eclipse.

Your First APPIUM Test Case for Native Android App

Step 1) Download ADT eclipse plugin or download ADT bundled separately here
Step 2) Open Eclipse and Create a new Project >> Package >> Class
Step 3) Import Selenium library and TestNG inside that new project.
Step 4) Now Create a small test Program for 'Calculator.app' to sum two numbers.
APPIUM Design Concepts
·         Appium is an 'HTTP Server' written using Node.js platform and drives iOS and Android session using Webdriver JSON wire protocol. Hence, before initializing the Appium Server, Node.js must be pre-installed on the system.
·         When Appium is downloaded and installed, then a server is setup on our machine that exposes a REST API.
·         It receives connection and command request from the client and execute that command on mobile devices (Android / iOS).
·         It responds back with HTTP responses. Again, to execute this request, it uses the mobile test automation frameworks to drive the user interface of the apps. Framework like:-
o    Apple Instruments for iOS (Instruments are available only in Xcode 3.0 or later with OS X v10.5 and later)
o    Google UIAutomator for Android API level 16 or higher

o    Selendroid for Android API level 15 or less

Accept Certificate code:

Accept Certificate code:
To accept certificate warning from Java Selenium code.


 driver.navigate().to("javascript:document.getElementById('overridelink').click()");

PDF Document Reading in Java Selenium


Below code is used to read PDF documents from JAVA code.

import org.pdfbox.cos.COSDocument;
import org.pdfbox.pdfparser.PDFParser;
import org.pdfbox.pdmodel.PDDocument;
import org.pdfbox.pdmodel.PDDocumentInformation;
import org.pdfbox.util.PDFTextStripper;

import java.io.File;
import java.io.FileInputStream;
import java.io.PrintWriter;

public class PDFTextParser {
   
    PDFParser parser;
    String parsedText;
    PDFTextStripper pdfStripper;
    PDDocument pdDoc;
    COSDocument cosDoc;
    PDDocumentInformation pdDocInfo;
   
    // PDFTextParser Constructor
    public PDFTextParser() {
    }
   
    // Extract text from PDF Document
    String pdftoText(String fileName) {
       
        System.out.println("Parsing text from PDF file " + fileName + "....");
        File f = new File(fileName);
       
        if (!f.isFile()) {
            System.out.println("File " + fileName + " does not exist.");
            return null;
        }
       
        try {
            parser = new PDFParser(new FileInputStream(f));
        } catch (Exception e) {
            System.out.println("Unable to open PDF Parser.");
            return null;
        }
       
        try {
            parser.parse();
            cosDoc = parser.getDocument();
            pdfStripper = new PDFTextStripper();
            pdDoc = new PDDocument(cosDoc);
            parsedText = pdfStripper.getText(pdDoc);
        } catch (Exception e) {
            System.out.println("An exception occured in parsing the PDF Document.");
            e.printStackTrace();
            try {
                   if (cosDoc != null) cosDoc.close();
                   if (pdDoc != null) pdDoc.close();
               } catch (Exception e1) {
               e.printStackTrace();
            }
            return null;
        }     
        System.out.println("Done.");
        return parsedText;
    }
   
    // Write the parsed text from PDF to a file
    void writeTexttoFile(String pdfText, String fileName) {
               
                System.out.println("\nWriting PDF text to output text file " + fileName + "....");
                try {
                                PrintWriter pw = new PrintWriter(fileName);
                                pw.print(pdfText);
                                pw.close();        
 \             } catch (Exception e) {
                                System.out.println("An exception occured in writing the pdf text to file.");
                                e.printStackTrace();
                }
                System.out.println("Done.");
    }
   
    //Extracts text from a PDF Document and writes it to a text file
    public static void main(String args[]) {
               
                if (args.length != 2) {
                System.out.println("Usage: java PDFTextParser <InputPDFFilename> <OutputTextFile>");
                System.exit(1);
        }
       
        PDFTextParser pdfTextParserObj = new PDFTextParser();
        String pdfToText = pdfTextParserObj.pdftoText(args[0]);
       
        if (pdfToText == null) {
                System.out.println("PDF to Text Conversion failed.");
        }
        else {
                System.out.println("\nThe text parsed from the PDF Document....\n" + pdfToText);
                pdfTextParserObj.writeTexttoFile(pdfToText, args[1]);
        }
    } 
}



Sunday, May 17, 2015

Selenium Webddriver - Scripts

Some of useful script for Java Selenium Automation Tester:

1)
JavaScript:

JavascriptExecutor javascript = (JavascriptExecutor) driver;
javascript.executeScript("alert('Test Case Execution Is started Now..');");

 2)
Navigation:

driver.navigate().to("http://google.com");
driver.navigate().back();
driver.navigate().forward();

Saturday, May 9, 2015

Selenium - Framework

For Java Selenium training and placement, contact eastbaytrng@gmail.com or (925) 322 3131

Selenium - Framework

Selenium will allow you to automate all your web (browsers) actions automation.
  • •Junit/TestNG as the testing framework, including their default reports system
  • •Maven for the project management and lifecycle 
  • •Jenkins is a good integration tool that will easily run the setup above
Different Selenium FrameWork :
1.Page Object Model
2.Data Driven
3.TestNG Reporting
4.Hybrid Framework
5.User-Defined Functions

Framework Advantages:
1.    Less Technical Expertise: Once Framework is set up, manual testers or non technical testers can easily write test scripts for automation.
2.    Easy To Understand: As it is maintained in Excel sheet and no coding is exposed, the test scripts are easy to read and understand. Keywords & actions resemble so closely manual test cases, which become easier to write and maintain.
3.    Early Start: You can start building Keyword Driven test cases before the application is delivered, as Object Repository can be easily set up at the later stage. Using information gathered from Requirements or other documentation, keyword data tables can be created that mirror corresponding manual test procedures.
4.    Re-usability of component: With implementing modularization in Keyword Driven, Re-usability can be further increased.
5.    Re-usability of code: As there is just one Execution Engine in Keyword Driven Framework, it encourage extreme code re-usability.

Data Set:
Data set stores the data files, Script reads test data from external data sources and executes test based on it.
Test Script:
A test is considered as a single action or a sequence of actions, that defines whether a specific feature meets functional requirements. It has multiple test files / packages / class files 
Test Report:
Test report/results is a document which contains summary of test activities.


For Java Selenium training and placement for further details related to framework and Selenium concepts, contact eastbaytrng@gmail.com or (925) 322 3131


Sunday, December 7, 2014

Difference Between Selenium 1.0 and Selenium 2.0

Selenium 2.0 Advantages:
  • No need of starting server
  • Object-oriented API
  • It is more faster than Selenium RC / 1.0
  • There are more ways to identify objects
  • Can Handle Onload Alerts
Below picture shows the architecture difference between Selenium 1.0 and 2.0



Wednesday, November 19, 2014

Manual Testing Vs. Automation Testing

Manual Testing:  This is traditional method of testing manually to test the software against requirements. Testers simulates the end-user testing.

Automation Testing: This is run through scripts and can be repeated over and over again. It reduces the testing effort and cost The script simulates the end-user testing.


Automation Testing tools:

  • QTP - HP
  • Java-Selenium - Open Source
  • IBM Rational - IBM
  • Visual Studio Test Professional by MicroSoft
  • TestComplete
  • TestPartner
  • SOA Test
  • WinRunner
  • LoadRunner
  • SilkTest
While QTP and other tools involved license cost, Java Selenium is Open-Source which is widely used.

Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language. It includes features like record and playback, intelligent field selection, Xpath as needed, auto complete for all common selenium commands, walk through tests, debug and set breakpoints, Java Support, or other formats, support for selenium user-extensions file, option to automatically assert the title of every page etc. 

Please contact eastbaytrng@gmail.com or (925) 322 3131 if interested in our QA online or in-person Training in bay area.