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>

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