Sunday 26 June 2016

Python Environment Setup

Binaries of the latest version of python 3  are available on its official site.


For Windows:

You need to download the .zip file and extract it locally, It can be x86 or x64 depending on your operating system.

Following options available for that.

Windows x86-64 embeddable zip file
Windows x86 executable installer
Windows x86 web-based installer
Windows x86-64 executable installer
Windows x86-64 web-based installer
Windows x86 embeddable zip file


Double-click on the installer file and follow simple instructions.


Setting up PATH :

Executable files can be in many directories, so OS provides search path that lists the directories that OS looks for it.

You can set PATH from command line also, like go to command line and 
type path %path%;C:\[Python folder name] and press Enter.


The other way of doing this is to go to environment variable setup page and add the location of python dir to PATH variable.



Now go to command prompt and type python --version, you should get a version of python as the result.




For Linux:

For Linux, there are different types of that, and each flavor uses different package managers.

On ubuntu, python 3 can be downloaded using the following command.

$sudo apt-get install python3-minimal


Setting path Linux:


For csh shell: type setenv PATH "$PATH:/usr/local/bin/python3"

For bash shell (Linux): type export PYTHONPATH=/usr/local/bin/python3










Friday 17 June 2016

Java Environment Setup

The reason behind adding the path to environment variable is that you need not go to java executables path again n again while compiling and running java files.  

Download Java.

Setting environment variable is not compulsory, but it is recommended.

If you do not set the PATH variable, you need to give full path of executables everytime you run it. such as:


C:\Java\jdk1.7.0\bin\javac ClassName.java


How to setup:

Right click on my computer.

Select Property option.

Now from property select Advance system Setting option.

click on new button and variable name.



Now go to path variable under system variable menu.

and add JAVA_HOME variable to path like as follows.

%JAVA_HOME%\bin



Click ok and close all windows.

To test the settings open command prompt and type 
java -version and hit enter.










Serializing and Deserializing in java

Serializing: Serialization is the mechanism to write the object into byte Stream, this mechanism used while dealing with object sending on remote clients using such client/server Java technologies as RMI or socket programming.

Basically, it converts all data into the byte stream, it contains data of the object as well as information about the object like type, metadata etc.


All the wrapper classes implement java.io.Serializable interface by default.


java.io.Serializable interface :

Serializable is interface has no body, it is basically used to mark java classes which support certain capabilities.

One advantage of serialization is that it compresses the data of the object to make travel of object across the network easy.

It has Following Methods:

1) public final void writeObject(Object obj) throws IOException {}writes the object to the ObjectOutputStream.
2) public void flush() throws IOException {}flushes the existing output stream.
3) public void close() throws IOException {}closes the output stream.

Here is the Example:

We are going to Serialize object of Schools in NACC class.

import java.io.Serializable
public class Schools implements Serializable{
       int s_Id;
       String s_Name;
       
       public Schools(int s_Id, String s_Name){      //We are creating constructor 
               this.s_Id = s_Id;
               this.s_Name=s_Name;
       }
}


NACC Class:


import java.io.*;  

class NACC{  

  public static void main(String args[])throws Exception{  

  Schools    s =new Schools(211,"MIT");  

  
  FileOutputStream fout=new FileOutputStream("SchoolsObject.txt");  
  ObjectOutputStream out=new ObjectOutputStream(fout);  
  
  out.writeObject(s);  
  out.flush();  
  System.out.println("Object Serialized.");  
 }  
}  

Here what is did here!

1) It creates one text file using FileOutputStream.

2) It Converts Object of Schools class into byte Stream using class

    ObjectoutputStream.
    If you open that text file, it will not be in human readable format.



3) We wrote data of the Object using out.writeObject() method.






Deserializing:
Deserializing means re-creating serialized object from serialized state.

It is the reverse process of serializing, here we convert byte stream data into the object again to make it operational.

We do this by using ObjectinputStream class.

Important Method :

1) public final Object readObject() throws IOException, ClassNotFoundException{}reads an object from the input stream.
2) public void close() throws IOException {}closes ObjectInputStream.


Example of Deserialization:

import java.io.*;
class Depersist{
 public static void main(String args[])throws Exception{
   
    ObjectInputStream in=new ObjectInputStream(new                    FileInputStream("SchoolObject.txt"));
    Schools s=(Schools)in.readObject();
    System.out.println(s.s_Id+" "+s.s_Name);
 
     in.close();
 }
}  


ObjectInputStream  gets the bytes converted in object from given file and then
It casts converted Object into Schools type.

readObject() function then reads the object and print function simply prints it.

   



Happy Learning.........

   


Saturday 2 January 2016

Installing Robot Framework with Python(an interpreter) using 'Selenium2Library' as library

What is Robot Framework: It is  Python based, extensible keyword-driven test automation framework for end to end acceptance testing.

It also known for acceptance-test-driven development(ATDD).

Though apart from Python we can use other interpreter also like Jython(JVM) , IronPython(.Net).

As Python 3.x is not yet supported with Robot Framework, we must use Python version 2.7.X or 2.5.X base version. click here to download python.

After downloading python install it by following simple wizard.

Now, set environment variable(PATH) (1) add location of installation directory of interpreter(e.g. C:\Python27)  
(2) add location of scripts are installed(e.g. C:\Pyhton27\Scripts).


Edit path variable and add above mentioned value.


To validate installation go to Command Prompt and type python and hit enter. It should enter in to Python mode with some info.

Now install the 'pip' which is standard Python package manager which makes the installation easy.

Note: We must install 'pip'  to execute below mentioned command click here to see installation steps.

Once we have 'pip' installed, open command prompt and run following command.

pip install robotframework

It will install all required files and can be see in Scripts directory of Pyhton.

Now we will install Selenium2Libraryopen command prompt and run following command.

pip install robotframework-selenium2library


Once it completes installation we are ready to go with Robot Framework.

Refer my post Integrate Robot Framework with Eclipse to start writing and executing your scripts on eclipse.

Friday 1 January 2016

How to install RIDE Editor for Robot Framework on windows


RIDE  editor is used to write and execute test suite for Robot Framework.

It is GUI tool which allows user to write test cases using template base and script. User can choose either ways to write cases.

RIDE only runs on regular Python. It does not run on Jython or IronPython

Precondition

Note: We must use wxPython2.8-win64-unicode-2.8.12.1-py27 if using win64 bit otherwise it will throw an error.

You can Refer my post to know more about Python and Robot Framework installation.

RIDE is distributed as separate installation packages for windows.

Click here to download RIDE packages. 

OR

You can also install RIDE using pip. Click here to know about installation of pip in python.

Open command prompt and navigate to bin directory and run command:

 pip install robotframework-ride


After successful installation of RIDE, it can be started from command like by running ride.py .


                                         OR
Extract zip file of RIDE which you downloaded, go to src/bin and copy ride.py to src
Go to command prompt and go to directory of RIDE editor/src and run python ride.py

In both way It should launch RIDE editor.









Installing pip(Python package manager)

'pip'  is consider best package manager for python. It makes the installation easy for user.

Here are the steps to install pip. Before we install pip Python must be installed in system.

Note: PATH variable must be set for python. 

Refer my post  Installing Robot Framework with Python(an interpreter) using 'Selenium2Library' as library for more information on setting PATH variable and more information.

Go to https://bootstrap.pypa.io/get-pip.py and copy all content of this page to one file in local system and name it as 'get-pip.py'.
.py is python extension.

Now open command prompt and navigate to the folder where get-pip.py file is located.

e.g. d:\pip\

Run following command: python get-pip.py

It will install all required file for pip and we are ready to go with smooth installation.

Wednesday 25 November 2015

Integrate Robot Framework with Eclipse



Robot Framework generally use RIDE tool for automating cases, but it happens that many users of Eclipse tool does not like other tool to use.

Here are the few simple steps to integrate Robot Framework with Eclipse:

In order to use Robot Framework we need to install python in system and then have Robot Framework installed.

Refer my post Installing Robot Framework with Python(an interpreter) using 'Selenium2Library' as library to know about Python installation.

Note: Though we can use many scripting language with Robot Framework  like Jython(Java) IronPython(.net platform) etc. but we are considering python in this article.

Get the Eclipse and start it, It should be compatible with Operating system.

Now go to Eclipse  Run menu and select External Tool option and select sub menu named "External Tool Configurations".





Clicking on External Tools Configuration will open one window. Select Program option.


Now It will open new program configuration form. Give any name to this configuration.

Under location field we will give path of pybot.bat file(You can find pybot file in script folder in python directory).

For "Working directory field" select you working directory.

For "Arguments" field give ${selected_resource_loc} as argument.



Now click on apply button and we are ready to run Robot file in eclipse.

To verify go to run configuration menu and click on it.


You will see pybot option added to the list. Now select any test suit and click on pybot option.

It will start executing the suit you are running.


-- Please drop your comments below if you have any query regarding information I have mentioned here.