Thursday, January 10, 2013

The Difference Between Cookies and Sessions.

The main difference between cookies and sessions is that cookies are stored in the user's browser, and sessions are not. This difference determines what each is best used for.

A cookie can keep information in the user's browser until deleted. If a person has a login and password, this can be set as a cookie in their browser so they do not have to re-login to your website every time they visit. You can store almost anything in a browser cookie. The trouble is that a user can block cookies or delete them at any time. If, for example, your website's shopping cart utilized cookies, and a person had their browser set to block them, then they could not shop at your website.

Sessions are not reliant on the user allowing a cookie. They work instead like a token allowing access and passing information while the user has their browser open. The problem with sessions is that when you close your browser you also lose the session. So, if you had a site requiring a login, this couldn't be saved as a session like it could as a cookie, and the user would be forced to re-login every time they visit.

You can of course get the best of both worlds! Once you know what each does, you can use a combination of cookies and sessions to make your site work exactly the way you want it to.

Wednesday, November 28, 2012

Networking Definition

  1. SMTP: SMTP (Simple Mail Transfer Protocol) is a set of standard Internet procedures by which two email providers (ex. Gmail, Yahoo Mail), transfer email messages to one another’s mail servers.
  2. domain: A domain is a name for an IP address and is more commonly recognized as a website or web address. For example, Google.com is a domain.
  3. SSL: SSL (secure socket layer) is a way of changing data such as your username and password into code as it travels across the Internet, so that the data will be secure and private.
  4. ISP: An ISP (Internet Service Provider) is a company (ex. AOL, AT&T, and Comcast) that gives your computer Internet access. ISPs are usually the companies that come to your house and set up all the wires.
  5. TLS: TLS (Transport Layer Security) is a way of changing data such as your username and password into code as it travels across the Internet, so that the data will be secure and private. With mail delivery, TLS begins with an unsecured connection to the mail servers, and then upgrades to a secure connection once information is sent.
  6. POP: POP (Post office protocol) is a one-way download of your messages that allows you to access your mail with a mail program like Outlook Express or Apple Mail. POP only offers one-way communication, which means that actions you take in the mail program (like marking a message as read) won’t be synced to Gmail.
  7. IMAP: IMAP (Internet message access protocol) lets you download messages from Gmail so you can access your mail with a program like Outlook Express or Apple Mail. IMAP syncs the actions you take in Outlook Express or Apple Mail with Gmail so if you read a message in your mail client, it'll be marked as read in Gmail.

Friday, November 2, 2012

Switching Frame and Windows in WebDriver sample code


1> Switch to different Frames:
 List<WebElement> frameset = driver.findElements(By.tagName("frame"));  
 if(frameset.size()>0) {  
 for (WebElement framename : frameset){  
 System.out.println("frameid: " + framename.getAttribute("name"));  
 }  
 }  
 else System.out.println("can not find any frame in HTML");  

Notice when you set the frame index, it starts with 0 for the first frame:
 driver.switchTo().frame(0);  


2> Switch to different Windows:
 Set<string> handlers = driver.getWindowHandles();  
 if (driver.getWindowHandles().size()>= 1){  
 for(String handler : handlers){  
 driver.switchTo().window(handler);  
 if (driver.getCurrentUrl().contains("Popup")){  
 System.out.println("Get focus on Popup window");  
 break;  
 }  
 }  
 }  
 else System.out.println("No windows founded!");  


Writing a common function based you own app for switching will be more helpful for your Code Clean!

Saturday, September 8, 2012

AutoIt Tools Related Concept !!!


AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys). AutoIt is also very small, self-contained and will run on all versions of Windows out-of-the-box with no annoying “runtimes” required!
AutoIt was initially designed for PC “roll out” situations to reliably automate and configure thousands of PCs. Over time it has become a powerful language that supports complex expressions, user functions, loops and everything else that veteran scripters would expect.
Features:
  • Easy to learn BASIC-like syntax
  • Simulate keystrokes and mouse movements
  • Manipulate windows and processes
  • Interact with all standard windows controls
  • Scripts can be compiled into standalone executables
  • Create Graphical User Interfaces (GUIs)
  • COM support
  • Regular expressions
  • Directly call external DLL and Windows API functions
  • Scriptable RunAs functions
  • Detailed helpfile and large community-based support forums
  • Compatible with Windows 2000 / XP / 2003 / Vista / 2008 / Windows 7 / 2008 R2
  • Unicode and x64 support
  • Digitally signed for peace of mind
  • Works with Windows Vista’s User Account Control (UAC)
AutoIt has been designed to be as small as possible and stand-alone with no external .dll files or registry entries required making it safe to use on Servers. Scripts can be compiled into stand-alone executables withAut2Exe.
Also supplied is a combined COM and DLL version of AutoIt called AutoItX that allows you to add the unique features of AutoIt to your own favourite scripting or programming languages!
Best of all, AutoIt continues to be FREE – but if you want to support the time, money and effort spent on the project and web hosting then you may donate.
Take me to the downloads page!
download autoit AutoIt

Features

Basic-like Syntax and Rich Function Set
AutoIt has a BASIC-like syntax which means that most people who have ever written a script or used a high-level language should be able to pick it up easily.
Although it started life as a simple automation tool, AutoIt now has functions and features that allow it to be used as a general purpose scripting language (with awesome automation as well of course!). Language features include:
  • The usual high-level elements for functions, loops and expression parsing
  • A staggering amount of string handling functions and a Perl compatible regular expression engine (using the PCRE library).
  • COM support
  • Call Win32 and third-party DLL APIs
Built-in Editor with Syntax Highlighting
AutoIt comes with a customised “lite” version of SciTe that makes editing scripts easy. Users can alsodownload a complete version of SciTe that includes additional tools to make things even easier.
Standalone and Small
AutoIt is a very small and standalone application with no reliance on massive runtimes like .NET or VB. All you need to run AutoIt scripts are the main AutoIt executable (AutoIt3.exe) and the script. Scripts can also be encoded into standalone executables with the built-in script compiler Aut2Exe.
International and 64-bit Support
AutoIt is fully Unicode aware and also includes x64 versions of all the main components! How many other free scripting languages can you say that about?
Key and Mouse Simulation
Much time has been spent optimizing the keystroke and mouse simulation functions to be as accurate as possible on all versions of Windows. All the mouse and keyboard routines are highly configurable both in terms of simulation “speed” and functionality.
Window Management
You can expect to move, hide, show, resize, activate, close and pretty much do what you want with windows. Windows can be referenced by title, text on the window, size, position, class and even internal Win32 API handles.
Controls
Directly get information on and interact with edit boxes, check boxes, list boxes, combos, buttons, status bars without the risk of keystrokes getting lost.  Even work with controls in windows that aren’t active!
Graphical User Interfaces (GUIs)
AutoIt v3 will also allow you to create some complex GUIs – just like those below!
gui eg1 AutoIt gui eg2 AutoIt
And much, much more.
You’ll probably want to go to the downloads page right now…

How to handle popup window and run test suite in Selenium webdriver.

Hi There are three .java files and one build.xml file.

package com.org;

import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

import junit.framework.TestCase;

public class TypeGoogle extends TestCase{
    
    private WebDriver driver;
    private String baseUrl;
    private StringBuffer verificationErrors = new StringBuffer();
    
    @Before
    public void setUp() throws Exception {
        driver = new FirefoxDriver();
        baseUrl = "http://www.google.co.in";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Test
    public void testFileTypeGoogle() throws Exception {
        
        driver.get(baseUrl + "/");
        driver.findElement(By.xpath("//div[@id='gs_lc0']/input")).clear();
        driver.findElement(By.xpath("//div[@id='gs_lc0']/input")).sendKeys("google");
         
            WebElement google = driver.findElement(By.className("gssb_m"));
            List<WebElement> googleBox = google.findElements(By.tagName("span"));
            Iterator<WebElement> i = googleBox.iterator();
            while(i.hasNext()) {
                    WebElement sel = i.next();
                    System.out.println(sel.getText());
            }
      }

    @After
    public void tearDown() throws Exception {
        driver.quit();
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
            fail(verificationErrorString);
        }
      }
    }

=====================================================================


package com.org;

import java.util.concurrent.TimeUnit;

import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import junit.framework.TestCase;

public class AddGadget extends TestCase{
    
    private WebDriver driver;
    private String baseUrl;
    private StringBuffer verificationErrors = new StringBuffer();
    @Before
    public void setUp() throws Exception {
        driver = new FirefoxDriver();
        baseUrl = "http://www.google.com/";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

        @Test
        public void testFileAddGadget() throws Exception {
            driver.get(baseUrl + "ig");
            
            driver.findElement(By.xpath("//div[@class='popupContent']/div/a[@id='popup_dialog_close']")).click();
            driver.findElement(By.cssSelector("img.G-BJ.G-AJ")).click();
            driver.findElement(By.id("search_module_query_box")).clear();
            driver.findElement(By.id("search_module_query_box")).sendKeys("news");
            driver.findElement(By.id("search_module_submit_button")).click();
            driver.findElement(By.id("featured_gadget_link")).click();
            driver.findElement(By.cssSelector("#addbtn > input.kd-button")).click();
            driver.findElement(By.id("back_to_gallery_link")).click();
            driver.findElement(By.cssSelector("input.kd-button")).click();
            driver.findElement(By.cssSelector("span.G-PI")).click();
            driver.findElement(By.id("tdd_edit")).click();
            driver.findElement(By.linkText("Delete")).click();
            driver.switchTo().alert().accept();
            Thread.sleep(5000);
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        }

        @After
        public void tearDown() throws Exception {
            driver.quit();
            String verificationErrorString = verificationErrors.toString();
            if (!"".equals(verificationErrorString)) {
                fail(verificationErrorString);
            }
        }
    }

=====================================================================

package com.org;

    import junit.framework.Test;
    import junit.framework.TestSuite;
    import org.junit.runner.RunWith;
    import org.junit.runners.Suite;
    import org.junit.runners.Suite.SuiteClasses;

    @RunWith(Suite.class)
    @SuiteClasses(value = {AddGadget.class, TypeGoogle.class})

    public class IGTestSuite {

        public static Test suite() {
            
            TestSuite suite = new TestSuite();
            suite.addTestSuite(AddGadget.class);
            suite.addTestSuite(TypeGoogle.class);
           
            return suite;
        }

        public static void main(String[] args) {
            junit.textui.TestRunner.run(suite());
        }
    }

=====================================================================

<?xml version="1.0" encoding="UTF-8"?>

<project name="IGoogle" default="all" basedir=".">
    <description>
        Demo UI testing, using Selenium and JUnit
    </description>
  <!-- set global properties for this build -->
  <property name="project_name" value="Results"/>
  <property name="src" location="src"/>
  <property name="build" location="bin"/>
  <property name="dist"  location="dist"/>
  <property name="lib"  location="lib"/>
  <property name="res"  location="res"/>
  <property name="output" location="out"/>
  
    <!-- Set the Classpath -->
    <path id="classpath">
        <fileset dir="./lib/">
            <include name="*.jar"/>
        </fileset> 
        <pathelement path="${build}"/>
    </path>
    
    <!-- top level targets -->
      <target name="compile" depends="init" description="compile the source code " >
        <javac srcdir="${src}" destdir="${build}" includeantruntime="false">  
        <classpath refid="classpath"></classpath>
        </javac>
      </target>

      <target name="clean"
            description="clean up" >
        <!-- Delete the ${build} and ${dist} directory trees -->
        <delete dir="${build}"/>
        <delete dir="${output}"/>
      </target>

        <!-- Selenium Test Case Start -->
        <target name="Start_Selenium_Server">
            <echo message="Start Selenium Server. Please wait.."/>
            <java jar="./lib/selenium-server.jar"
                    fork="true" spawn="true" >
                <classpath refid="classpath"></classpath>
                <!--  Set the proxy
                <arg value="-Dhttp.proxyHost=172.16.18.3"/>
                <arg value="-Dhttp.proxyPort=8080"/
                <arg line="-singleWindow"  />-->
                <arg line="-log ${output}/selenium.log"/>
            </java>
            <echo message="Started Selenium Server. "/>
        </target>    
    
        <target name="Stop-Selenium-Server">
                <echo message="Stop Selenium Server. Please wait.."/>
                <get taskname="selenium-shutdown"
                     src="http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer
                     dest="${output}/server.stop.status.txt" 
                     ignoreerrors="true"/>
        </target>
    
        <target name="run-alltests" depends="compile" description="run all test suite" >
              <echo message="Test Run. Please wait.."/>
              <antcall target="Start_Selenium_Server"/>
            <junit printsummary="yes" haltonfailure="no" showoutput="yes" >
                <classpath refid="classpath"/>
               <batchtest fork="yes" todir="${output}/raw/">
                  <formatter type="xml"/>
                <fileset dir="${build}">
                 <filename name="com/org/IGTestSuite.class"/>
                </fileset>
              </batchtest>
            </junit>    
              <antcall target="Stop-Selenium-Server"/>
        </target>
    
    
      <target name ="test" depends="run-alltests">
            <java classname="com/org/IGTestSuite.class"
                  fork="true">
                    <arg line="${output}/raw/ ${output}/SeleniumReport.xml"/>
                <classpath refid="classpath"/>
            </java>
              <junitreport todir="${output}">
              <fileset dir="${output}/raw/">
                <include name="TEST-*.xml"/>
              </fileset>
              <report format="frames" todir="${output}/html/"/>
            </junitreport>
      </target>

    <!-- supporting targets -->
    
     <target name="init" description="initialize the build environment" >
        <!-- Create the time stamp -->
        <tstamp/>
        <!-- Create directory structures -->
        <mkdir dir="${build}"/>
        <mkdir dir="${output}"/>
        <mkdir dir="${output}/raw/"/>
        <mkdir dir="${output}/html/"/>
      </target>
  
      <target name="all" depends="clean, test">
      </target>
  
</project>

=====================================================================