Thursday, 11 February 2016

Difference between testing tool and testing framework

Difference between testing tool and testing framework:
=========================================
Tool:
-------
A testing tool or software development tool is a computer program that  use to create, debug, maintain, or otherwise support other programs and applications.

A tool is used to test the applications.

Tool is dependent on the environment

Selenium is a tool  which works on browsers for web based applications

Framework:
-----------------

A framework is a semi completed application,based on our requirements we can customize it its called framework.
Using testing tools we build the testing frameworks





Difference between pom.xml(maven) and build.xml(ant)

Difference between pom.xml(maven) and build.xml(ant):
============================================
1.Maven doesn't have formal conventions like a common project directory structure, you have to tell Ant exactly where to find the source and where to put the output. Informal conventions have emerged over time, but they haven't been codified into the product.
                    Ant has conventions, it already knew where your source code was because you followed    the convention. It put the byte code in target/classes, and it produced a JAR file in target.

2.Maven has a convention to place source code, compiled code etc. So we don't need to provide information about the project structure in pom.xml file
         Ant doesn't has formal conventions, so we need to provide information of the project structure in build.xml file.

3.Ant is a tool box.
                      Maven is a framework.
4.Ant is mainly a build tool.
                      Maven is mainly a project management tool.
5.Ant scripts are not reusable.
                      Maven plugins are reusable. 
6.Ant is procedural, you need to provide information about what to do and when to do through code. You need to provide order.
                        Maven is declarative, everything you define in the pom.xml file.

Swapping of two numbers without using temporary variable

Swapping of two numbers without using temporary variable:
===============================================
1st way:
=======
package files;

public class SwapProgDemo {

public static void main(String[] args) {

int x = 10;

        int y = 20;
        
        System.out.println("Before swap:");
        System.out.println("x value: "+x);
        System.out.println("y value: "+y);
        
        x = x+y;
        y = x-y;
        x = x-y;
        
        System.out.println("After swap:");
        System.out.println("x value: "+x);
        System.out.println("y value: "+y);

}

}

OUTPUT:
--------------
Before swap:
x value: 10
y value: 20
After swap:
x value: 20
y value: 10


2nd way:
========

package files;

public class SwappROGdEMO {
public static void main(String[] args) {
int x = 10;
        int y = 20;
        
        System.out.println("Before swap:");
        System.out.println("x value: "+x);
        System.out.println("y value: "+y);
        
        x = x*y;
        y = x/y;
        x = x/y;
        
        
        System.out.println("After swap:");
        System.out.println("x value: "+x);
        System.out.println("y value: "+y);
}
}

OUTPUT:
--------------
Before swap:
x value: 10
y value: 20
After swap:
x value: 20
y value: 10



Swamping of two numbers using temporary variable

Swamping of two numbers using temporary variable:
=======================================
package files;

public class SwapDemo {

public static void main(String[] args) {

int x = 20, y = 30,temp;

System.out.println("Before Swapping\nx = " + x + "\ny = " + y);

temp = x;
x  =  y;
y  =  temp;

System.out.println("After Swapping\nx = " + x + "\ny = " + y);
}

}

OUTPUT:
=========
Before Swapping
x = 20
y = 30
After Swapping
x = 30

y = 20

Wednesday, 10 February 2016

File uploading in selenium @ 3 ways

File uploading in selenium @ 3 ways:
=============================
We can upload a file using 3 ways

1.Using WebDriver sendKeys() method
2.Using Autoit tool
3.Using Robot class and StringSelection java class

1.Using WebDriver sendKeys() method:
===============================
If we want to upload a file we can upload by using webdriver sendKeys() method.
//example:
-----------
package blog;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class FileUploadSendKeys {

WebDriver webDriver;

@BeforeSuite
public void launchingIEBrowser() {

System.setProperty("webdriver.chrome.driver",
"D:\\Ramesh\\ChromeDriver.exe");
webDriver = new ChromeDriver();

// webDriver = new FirefoxDriver();
webDriver.manage().window().maximize();
webDriver.manage().deleteAllCookies();
webDriver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);

}

@Test
public void testScript() throws InterruptedException, AWTException {

webDriver.get("https://www.sendspace.com/");

webDriver.findElement(By.id("upload_file")).sendKeys(
"C:\\Users\\aramesh\\Desktop\\abc.txt");
;
Thread.sleep(2000);

}

@AfterSuite
public void closeBrowser() {
webDriver.quit();

}

}

2.Using Robot class:
================

Robot class is used to (generate native system input events) take the control of mouse and keyboard. Once you get the control, you can do any type of operation related to mouse and keyboard through with java code.

There are different methods which robot class uses. Here in the below example we have used 'keyPress' and 'keyRelease' methods.

keyPress:
-------------
This method with press down arrow key of Keyboard.
Example: robot.keyPress(KeyEvent.VK_DOWN).

keyrelease:
--------------
This method with release down arrow key of Keyboard
Example: robot.keyRelease(KeyEvent.VK_DOWN) 

mousePress():
-----------------
This method will press the right click of your mouse.
mouseMove() :  This will move mouse pointer to the specified X and Y coordinates.
Example: robot.mouseMove(point.getX(), point.getY()):


mouseRelease():
--------------------
This method will release the right click of your mouse.

robot.keyPress(KeyEvent.VK_DOWN):
---------------------------------------------------
To press down arrow key of Keyboard.

robot.keyPress(KeyEvent.VK_TAB):
------------------------------------------------
To press TAB key of keyboard


robot.keyPress(KeyEvent.VK_ENTER):
---------------------------------------------------
To press copy key from the keyboard

robot.keyRelease(KeyEvent.VK_ENTER):
------------------------------------------------------
To press release copy key from the keyboard

robot.keyPress(KeyEvent.VK_ENTER):
----------------------------------------------------
To press Enter key from the keyboard

//example:
--------------
package blog;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class RobotFileUpload {

WebDriver webDriver;

@BeforeSuite
public void launchingIEBrowser() {

System.setProperty("webdriver.chrome.driver",
"D:\\Ramesh\\ChromeDriver.exe");
webDriver = new ChromeDriver();

// webDriver = new FirefoxDriver();
webDriver.manage().window().maximize();
webDriver.manage().deleteAllCookies();
webDriver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);

}

@Test
public void testScript() throws InterruptedException, AWTException {

webDriver.get("https://www.sendspace.com/");

webDriver.findElement(By.id("upload_file")).click();
Thread.sleep(2000);
// StringSelection is a class that can be used for copy and paste
// operations.
StringSelection stringSelection = new StringSelection(
"C:\\Users\\aramesh\\Desktop\\abc.txt");
Toolkit.getDefaultToolkit().getSystemClipboard()
.setContents(stringSelection, null);
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
// press enter key of keyboard to perform above selected action
robot.keyRelease(KeyEvent.VK_ENTER);
// release the neter key

Thread.sleep(4000);

webDriver.findElement(By.name("recpemail_fcbkinput")).sendKeys(
"rameshat914@gmail.com");

webDriver.findElement(By.id("ownemail")).sendKeys(
"rameshat914@gmail.com");

Thread.sleep(8000);

}

@AfterSuite
public void closeBrowser() {
webDriver.quit();

}

}

3.Using autoit:
============
Please refer the post autoit in our blog@rameshselenium.blogspot.in

Tuesday, 9 February 2016

Java source file structure

Java source file structure:
====================
1. A java program can contain any number of classes.
2. Compulsory one class should be declared as public
3. If there is a public class then name of the program and name of the public class must be matched or same,otherwise we will get compile time error.
4. The class which you declared as public,write main() method in that class.

SampleDemo.java:
------------------
              class First
              {
                   ;;;
                   ;;;
                   ;;;
               }

              class Second
              {
                 ;;;;;
                 ;;;;;
                 ;;;;;
               }

              public class SampleDemo
              {
                 ;;;;;
                 ;;;;;
                 ;;;;;
              }


Naming conventions:
================
1.Every class should start with capital letter and if it is having multiple words,every word start with capital letter.

ex:
      class Sample
      {
                 ;;;
       }

      class SampleDemo
      {
              ;;;
       }

2.Every variable name should start with small letter and if it is having multiple words first word start with small letter,next words start with capital letter.

ex:
           int number=10;
           int firstNumber=30;

3.Every method name should start with small letter.

               public void display()
              {
                      ;;;;
                      ;;;;

              }

Types of variables in JAVA

Types of variables in JAVA:
======================
There are 2 types of variables 
1.Primitive variables
2.Reference variables

Primitive variables:
--------------------------
Primitive variables are used to represent primitive values like 

integer etc...
ex:int a=10;


Primitive variables are divided in to 3 types.
      1.Instance variables
      2.Static variables
      3.Local variables

1.Instance variables:
---------------------------
If the value of a variable keep on changes or its varies from 

object to object then that type of variables are called Instance 

variables.

syntax:
----------
  datatype variablename = variablevalue;
----------------------------------------------------

Instance variables should be declared within the class directly.

For every object a separate copy of instance will be created.

Instance variables will be stored in the heap memory.

Instance variables will be created at the time of object 

creation and destroyed at the time object destruction.

Instance variables are also called as object level variables.


Default values:
--------------------
If we dont perform initialization For instance variables JVM 

provide values.
(integer====0)
(float====0.0)
(String ===null) etc...
ex:
package blog;

public class DefaultDemo {

int a,b;
String name;

public static void main(String[] args) {

DefaultDemo defaultDemo = new DefaultDemo();

System.out.println(defaultDemo.a);//0
System.out.println(defaultDemo.name);//null

}

}

In order to access instance variables compulsory we need to create the object.

static variables:
---------------------
If the value of a variable is not varied from object to object 

then declare such type of variables as static variables.

If we want to convey a variable as static declare that variable with static modifier.

syntax:
--------

 static datatype variable name = variable value;
--------------------------------------------------------------
For static variables a single copy will be created at class 

level.

static variables will be created at the time of class loading 

and will be destroyed at the time of class unloading.


Default values:
--------------------
If we dont perform initialization For instance variables JVM 

provide values.
(integer====0)
(float====0.0)
(String ===null) etc...
ex:
package blog;

public class DefaultDemo {

static int a,b;
static String name;

public static void main(String[] args) {

DefaultDemo defaultDemo = new DefaultDemo();

System.out.println(defaultDemo.a);//0
System.out.println(defaultDemo.name);//null

}

}


We can access static variables in 3 ways
1.By using classname
2.Direclty by calling their names
3.By using object

Local variables:
---------------------
Based on requirements some times we need to use some variables at certain extent level only.
When ever we declare a variable inside the method or constructor such type of variables we can call it as local variables

Local variables will be stored in stack memory.
For local variables compulsory we need to perform initialization

The scope of local variable is within that particular method only and when you try to access outside of that we will get compile time error.

package blog;

public class DefaultDemo {

public static void main(String[] args) {

int a;
System.out.println(a);//compile time error...a is local variable should perform      initialisation

}

}


Reference variables:
---------------------------
Reference variables are used to represent or to refer objects.

Ex:Employee emp = new Employee();