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

Saturday, 19 September 2015

Java required by Selenium Automation

#Java #TheBuddhaTree #SeleniumWebDriver

After many of requests/questions from our readers that how much Java is needed for working on Selenium WebDriverHere we are listing all the Java topics, which you should know before start working on Selenium WebDriver.

Introduction to Computers and Java
•       Introduction
•       Computers: Hardware and Software
•       Machine Languages, Assembly Languages and High-  Level Languages
•       Introduction to Object Technology
•       Operating Systems
•       Programming Languages
•       Java Development Environment
•       Test-Driving Java Application

Introduction to Java Applications
•       Introduction
•       Write Your First Program in Java
•       Modifying Your First Java Program
•       Displaying Text
•       Adding Integers
•       Memory Concepts
•       Arithmetic
•       Decision Making: Equality and Relational
•       Conditional Operators

Introduction to Classes, Objects, Methods and Strings
•       Introduction
•       Declaring Class with Method and Instantiating Object of a Class
•       Declaring a Method with Parameter
•       Instance Variables, set getter Methods
•       Primitive vs. Reference Types
•       Initializing Objects with Constructors
•       Floating-Point Numbers and double

Control Statements:  Part  1
•       Introduction
•       Algorithms
•       Control Structures
•       if Statement
•       if...else Statement
•       while Statement
•       Compound Assignment Operators
•       Increment and Decrement Operators
•       Primitive Types

Control Statements: Part 2
• Introduction
• Essentials of Counter-Controlled Repetition
• for Repetition Statement
• Examples Using the for Statement
• do...while Repetition Statement
• switch Multiple-Selection Statement
• break and continue Statements
• Logical Operators
• Structured Programming Summary

  Methods
• Introduction
• Program Modules in Java
• static Methods  and static Fields
• Methods with Multiple Parameters
• Method-Call Stack and Activation Records
• Argument Promotion and Casting
• Java API Packages
• Scope of Declarations
• Method Overloading

Array
• Introduction
• Arrays
• Declaring and Creating Arrays
• Arrays Examples
• Enhanced for Statement
• Passing Arrays to Methods
• Multidimensional Arrays
• Limitation of Array

Classes and Objects: In Detail
• Introduction
• Controlling Access to Members
• Referring to the Current Object’s Members with this  Reference
• Overloaded Constructors
• Default and No-Argument Constructors
• Setter and Getter Methods
• Composition &  Enumerations
• Garbage Collection and Method finalize
• static Class Members
• static Import
• final Instance Variables
• Creating & Accessing package

Inheritance
• Introduction
• Superclass and Subclass
• protected Members
• Relationship between Superclass and Subclass
• Constructors in Subclasses
• Class Object

Polymorphism
• Introduction
• Polymorphism Examples
• Polymorphic Behavior
• Abstract Class and Method
• final Method and Class
• Using Interfaces

Exception Handling
• Introduction
• Example: Divide by Zero
• When to Use Exception Handling
• Java Exception Hierarchy
• finally Block
• Obtaining Information from an Exception Object
• Chained Exceptions
• Declaring New Exception Types
• Preconditions and Post-conditions
• Assertions

Strings, Characters and Regular Expressions
• Introduction
• Fundamentals of Characters and Strings
• Class String
• String operation
• Class Character
• Tokenizing Strings
• Regular Expressions, Class Pattern and Class Matcher
  
Files, Streams and Object Serialization
• Introduction
• Files and Streams
• Class File
• Sequential-Access Text Files
• Object Serialization
• Additional java.io Classes

Generic Collections Classes & Methods
• Introduction
• Collections Overview
• Type-Wrapper Classes for Primitive Types
• Autoboxing and Auto-Unboxing
• Interface Collection and Class Collections
• Lists
• Collections Methods
• Sets
• Maps
• Properties Class
• Synchronized Collections
• Un-modifiable Collections


• Abstract Implementations

Saturday, 12 September 2015

SeleniumFramework - A simple web testing framework based on open source technology Selenium WebDriver, TestNG, Java, Apache POI

#Selenium #WebDriver #Maven #TestNG #Framework #POI #Jenkins

This framework is designed to help you get started with Web testing quickly, to grow as needed, and to avoid common pitfalls. it just allows you to manipulate browser.
Who Will Cry When You Die?

Main features:
  • Provides browser automation using Selenium WebDriver
  • Page Object Model is used to design pattern to create Object Repository for web UI elements.
  •  Running test case against multiple set of test data
  • Automation Suite Configuration using Java properties file
  • TestNG.xml file which provides feature to run selective test suite
  • Screenshot capturing capability for failed test scenario (Take screenshots on demand and save on disk.)
  • Uses Apache logger for generating test execution logs
  • Build Tool : Maven
  • Programming language: Java
  • Test Data Management: data stored in Excel worksheet : Apache POI
  • Parallel Execution : Using Selenium Grid to run simultaneous test execution
  • CI Integration : Integrated with Jenkins
  • Exceptions handling : Using Java try/Catch exception handling feature
  • Reports : Custom html reports are generated and available in test-output folder

To download Framework, visit link - Download Here

Note - If any doubt/query/suggestion, pls post in forum - Testing Forum

Sunday, 6 September 2015

How to Verify the limit of characters of a textbox

If you already know the char limit, then input the text which is more than the permissible limit. For example if max char limit is 30 then send a text with 31 char length and then fetch the text and count the number of character. It should be 30.

Code example is here which is written considering the limit is 30 char :- 

//Data input should be more than 30 chars
driver.findElement(By.id("textfield1")).sendKeys("Testexample1Testexample2Testexa");

//get count of string length
int actualLimit =driver.findElement(By.id("textfield1")).getText().length();

//Assertion
assertEquals(actualLimit, 30);

Sunday, 16 August 2015

Java : Reverse a String

Wings of Fire: An Autobiography

Code to reverse string is as follows -

public class StringReverse {

  public static void main(String[] args) {

      String original, reverse =""; // declare two string variable

      original = "Sample String"; //String to be reversed

      int length = original.length(); //find length of string

      for ( int i = length - 1 ; i >= 0 ; i-- )

         reverse = reverse + original.charAt(i); //charAt returns one char at a time & assign to reverse 

      System.out.println("Reverse is :- "+reverse); //print reverse of string

  }
}

Monday, 10 February 2014

How to Verify Broken Links using Selenium WebDriver

This program reads all link from a web page, sends open connection request to URL, checks for response code. Based on response code, broken link is identified & get printed on console.

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class Links_Broken {

    @Test
      public void saveAllLinks(){
          FirefoxDriver firefoxDriver = new FirefoxDriver(); //Starts Firefox browser
                  
          firefoxDriver.navigate().to("
http://google.co.in"); //opens Web Page
               
           List <WebElement>linksList = firefoxDriver.findElements(By.tagName("a")); // finds link  elements & stores in a list

//traverse each link from collection
          for(WebElement linkElement: linksList){
              String link =linkElement.getAttribute("href");
              if(link!=null){
                verifyLinkActive(link);
              }
          }
          firefoxDriver.quit(); // close Firefox browser
      }
          
      /**
       * This method verifies that link is active
       * @param link - link(URL)
       * @return - true/false
       */
       public void verifyLinkActive(String linkUrl){
          try {
             URL url = new URL(linkUrl);
             HttpURLConnection httpURLConnect=(HttpURLConnection)url.openConnection();
             httpURLConnect.setConnectTimeout(3000);
             httpURLConnect.connect();

             if(httpURLConnect.getResponseCode()==200){
                 System.out.println(linkUrl+" - "+httpURLConnect.getResponseMessage());
              }
            if(httpURLConnect.getResponseCode()==HttpURLConnection.HTTP_NOT_FOUND)  

             {
                 System.out.println(linkUrl+" - "+httpURLConnect.getResponseMessage() + " - "+                  HttpURLConnection.HTTP_NOT_FOUND);
              }
          } catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
}

Tuesday, 21 January 2014

Java convert string to int value

Java provides two method parseInt() and valueOf() method to convert string into integer. Below example shows the usage of two methods to convert string to integer.

public class StringtoNumber {

public static void main(String[] args) {
String String1 = "000456";
  try{
  // using Integer.parseInt method
       int intvalue = Integer.parseInt(String1);
       System.out.println("With parseInt method, intvalue = " + intvalue );
        } catch(NumberFormatException e) {
        System.err.println("NumberFormatException in parseInt, "+ e.getMessage());
        }
         
        try{
        // using Integer.valueOf method
             int intvalue = Integer.valueOf(String1);
             System.out.println("With valueOf method, intvalue = " + intvalue );
             
          } catch(NumberFormatException e) {
              System.err.println("NumberFormatException in valueOf, "+ e.getMessage());
        }
     }
}

Output -
      With parseInt method, intvalue = 456

      With valueOf method, intvalue = 456

Note - Catch section gets executed in case, Java fails to convert string to integer.

Friday, 3 January 2014

How to create runnable jar file for your Selenium project

   1.   Right click on your project in eclipse
   2.   Select Export
   3.   Select [Java -> Runnable Jar file]
   4.   Provide Export Location
   5.   Click finish

 Run generated .jar file from command prompt


Script will run on machine having Browser & Java.

Tuesday, 10 December 2013

Java - How to check Palindrome

public class palindrome {
public static void main(String[] args) {
String original, reverse="";
        original = "jaj";
        int length = original.length();
        for ( int i = length - 1 ; i >= 0 ; i-- )
           reverse = reverse + original.charAt(i);
        if (original.equals(reverse))
           System.out.println("Palindrome, Original - "+ original+ " Reversed - " + reverse);
        else
          System.out.println("Not a Palindrome, Original - "+ original+ " Reversed - " + reverse);
}

}