Thursday

QTP and Windows OS


Thanks and taken from:
http://www.joecolantonio.com/2012/10/02/qtp-operating-systems-supported-by-qtp-11-qtp-10-qtp-9-5-and-qtp-9-2/


Table of Supported OS's for QTP
OS
QTP 11
QTP 10
QTP 9.5
QTP 9.2
Microsoft Windows 2000 Service Pack 4
No
Yes
Yes
Yes
Microsoft Windows 2000 Update Rollup 1 For Service Pack 4
No
Yes
Yes
Yes
Microsoft Windows XP Service Pack 2 (32-Bits)
Yes
Yes
Yes
Yes
Microsoft Windows XP Service Pack 3 (32-Bits)
Yes
Yes
Yes
No
Microsoft Windows XP Service Pack 1 (64-Bits)
No
No
No
Yes
Microsoft Windows XP Service Pack 2 (64-Bits)
Yes
Yes
Yes
No
Microsoft Windows XP Service Pack 3 (64-Bits)
Yes
No
No
No
Microsoft Windows Server 2003 (32-Bits)
No
No
No
No
Microsoft Windows Server 2003 (64-Bits)
No
No
No
Yes
Microsoft Windows Server 2003 Service Pack 1 (32-Bits)
No
No
No
No
Microsoft Windows Server 2003 Service Pack 2 (32-Bits)
Yes
Yes
Yes
Yes
Microsoft Windows Server 2003 Service Pack 2 (64-Bits)
Yes
Yes
Yes
No
Microsoft Windows Server 2003 R2 (32-Bits)
Yes
Yes
Yes
No
Microsoft Windows Server 2003 R2 (64-Bits)
Yes
Yes
No
No
Microsoft Windows Vista Beta 2-build 5384
No
No
No
No
Microsoft Windows Vista (32-Bits)
No
No
Yes
Yes
Microsoft Windows Vista (64-Bits)
No
No
Yes
No
Microsoft Windows Vista Service Pack 1 (32-Bits)
No
No
Yes
No
Microsoft Windows Vista Service Pack 1 (64-Bits)
No
No
Yes
No
Microsoft Windows Vista Service Pack 2 (32-Bits)
Yes
Yes
No
No
Microsoft Windows Vista Service Pack 2 (64-Bits)
Yes
Yes
No
No
Microsoft Windows Server 2008 (32-Bits)
No
No
Yes
No
Microsoft Windows Server 2008 (64-Bits)
No
No
Yes
No
Microsoft Windows Server 2008 Service Pack 2 (32-Bits)
Yes
Yes
No
No
Microsoft Windows Server 2008 Service Pack 2 (64-Bits)
Yes
No
No
No
Microsoft Windows Server 2008 R2 (64-bit)
Yes
No
No
Microsoft Windows Server 2008 R2 Service Pack 1 (64-bit)
Yes
No
No
No
Microsoft Windows 7 (32-Bits)
Yes
No
No
Microsoft Windows 7 (64-Bits)
Yes
No
No
Microsoft Windows 7 Service Pack 1 (32-Bits)
Yes
No
No
No
Microsoft Windows 7 Service Pack 1 (64-bits)
Yes
No
No
No

QTP 11 version


  • Support for new Operating Systems
  • Enhanced Data Management Facility
  • New Object Spy Functionality
    • Add an object to a repository
    • Highlight an object in our application
    • Copy/paste object properties
  • New Smart Regular Expression list
  • New QTP-Service Test integration facility
  • New Run Results Viewer
  • New facility to hide the Keyword View
  • Facility to add Images to Our Run Results
  • New Log Tracking Functionality
  • Automatic Parameterization of Steps
  • New Visual relation identifiers
  • Visual indication of Version Control Status of Tests
  • Web 2.0 add-ins support
  • New capabilities for working with Web-Based objects
    • Firefox Testing
    • XPath, CSS, Identifiers
    • Event Identifiers
    • Embed or Run JavaScripts in our Web Pages
  • New methods for testing Web-based Operations
  • New methods for testing Web-based Operations
  • New LoadFunctionLibrary statement
  • Improved checkpoints and output value objects management
  • Dual Monitor Support
  • New QTP Asset Upgrade Tool for HP ALM and Quality Center
  • Test execution in minimized remote desktop protocol session
  • Improved Web Add-in Extensibility
  • Improved Business Process Testing
  • New Extensibility Accelerator for Functional Testing

QTP - Register .Net DLL and use in QTP


1. Build a class in c# (get C# express)
2. Class Library
3. Create a  class MyQTP.cs  with small code in Myfunction(a,b)
4. go in properties
5. Click on Assembly information button
6. Make Assembly com visible
7. Go to Build
8. Register com interop

9. Open QTP



Set oDLLCom = CreateObject("QTP.UI.Automation.MyQTP")
msgbox oDLLCom.Myfunction(a,b)
Note:
When we build the DLL in Visual Studio then it automatically enters all the Method in registry.To use the DLL on another machine we need to use RegAsm.exe to register it. 

Create a jar file




The basic format of the command for creating a JAR file is:
jar cf jar-file input-file(s)

  • The c option indicates that you want to create a JAR file.
  • The f option indicates that you want the output to go to a file rather than to stdout.
  • jar-file is the name that you want the resulting JAR file to have. You can use any filename for a JAR file. By convention, JAR filenames are given a.jar extension, though this is not required.
  • The input-file(s) argument is a space-separated list of one or more files that you want to include in your JAR file. The input-file(s) argument can contain the wildcard * symbol. If any of the "input-files" are directories, the contents of those directories are added to the JAR archive recursively.
jar cvf my.jar mytest.class

http://docs.oracle.com/javase/tutorial/deployment/jar/build.html

Basic Assert in Junit - Beginner


  • Assertions

assertEquals()
assertEquals("something", result);

assertTrue()/ assertFalse()
assertTrue (oMyClass.myMethod());
assertFalse(oMyClass.myMethod());


assertNull() / assertNotNull()
assertNull(oMyClass.myMethod());
assertNotNull(oMyClass.myMethod());

assertSame()/assertNotSame()
assertNotSame(oMyClass1.myMethod(),
oMyClass2.myMethod());


assertArrayEquals()

String[] expectedArray = {"one", "two", "three"};
String[] actualArray =  oMyClass.myMethod();
assertArrayEquals(expectedArray,actualArray );


Junit and Ant for Beginner - jump start



1. Install ant  {something like C:\Junit\Ant\apache-ant-1.8.4-bin\apache-ant-1.8.4 say it ANT_HOME}
2, Install Junit {remember to set classpath example C:\Junit\junit4.8.1\junit4.8.1 in classpath}
3. copy junit.x.x.jar in ANT_HOME/lib
4.  Now you working folder ex C:\Junit\Ant_project
5. Create test and src folder in it and put .java file in src folder

6.  example file 1:

public class Subscription {

   private int price ; // subscription total price in euro-cent
   private int length ; // length of subscription in months

   // constructor :
   public Subscription(int p, int n) {
     price = p ;
     length = n ;
   }

  /**
   * Calculate the monthly subscription price in euro,
   * rounded up to the nearest cent.
   */
   public double pricePerMonth() {
     double r = (double) price / (double) length ;
      return r ;
   }

  /**
   * Call this to cancel/nulify this subscription.
   */
   public void cancel() { length = 0 ; }

}


File 2:


import org.junit.* ;
import static org.junit.Assert.* ;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.io.File;
import java.io.FileWriter;
 import java.io.IOException;
 import java.util.logging.Level;
 import java.util.logging.Logger;
public class SubscriptionTest {

   @Test
   public void test_returnEuro() {
      System.out.println("Test if pricePerMonth returns Euro...") ;
  Write_To_File(12,"hi","bye");
      Subscription S = new Subscription(200,2) ;
      assertTrue(S.pricePerMonth() == 1.0) ;


  Write_To_File(11,"hi","bye");
   }

   @Test
   public void test_roundUp() {
      System.out.println("Test if pricePerMonth rounds up correctly...") ;
  Write_To_File(10,"hi","bye");
      Subscription S = new Subscription(200,3) ;
      assertTrue(S.pricePerMonth() == 0.67) ;

   }


   @Test
   public void test_absolute() {
      System.out.println("shyam") ;
  Write_To_File(10,"hi","bye");
      Subscription S = new Subscription(200,4) ;
      assertTrue(S.pricePerMonth() == 50.0) ;
   }


   public void Write_To_File(int var, String str, String str1) {
   try {
FileWriter fstream = new FileWriter("C:\\Junit\\Result\\out.txt",true);

System.out.println("jhansi");
            BufferedWriter fbw = new BufferedWriter(fstream);
            fbw.write("Our append txt...");
            fbw.newLine();
            fbw.close();
}
catch (Exception ex) {
System.out.println("Exception Occured:: ");
ex.printStackTrace();
}
}
 
 
   }



7. Now craete Build.xml in C:\Junit\Ant_project

8. copy paste following xml in build.xml  (Please replace <   and  >  sing in the following xml)




lessthanSign ?xml version="1.0"?>

lessthanSign project name="tutorial" default="build" basedir=".">
  lessthanSign property name="srcdir" value="./src" />
   lessthanSign property name="testdir" value="./test" />
lessthanSign property name="lib" value="./lib" />
lessthanSign property name="classes" value="./classes" />


 lessthanSign target name="build">
        lessthanSign javac srcdir="." includeantruntime="false" includes="**/*.java"/>
    lessthanSign /target>

lessthanSign target name="ensure-test-name" unless="test">
    lessthanSign fail message="You must run this target with -Dtest=TestName"/>
lessthanSign /target>


 lessthanSign path id="classpath.base"/>
 
  lessthanSign path id="classpath.test">
  lessthanSign pathelement location="C:\Junit\junit4.8.1\junit4.8.1\junit-4.8.1.jar" />
    lessthanSign pathelement location="${testdir}" />
  lessthanSign pathelement location="${srcdir}" />
  lessthanSign path refid="classpath.base" />
  lessthanSign /path>
 
    lessthanSign target name="clean" >
  lessthanSign delete verbose="${full-compile}">
  lessthanSign fileset dir="${testdir}" includes="**/*.class" />
  lessthanSign /delete>
  lessthanSign /target>
 
    lessthanSign target name="compile" depends="clean">
  lessthanSign javac srcdir="${testdir}" destdir="${testdir}" verbose="${full-compile}" >
  lessthanSign classpath refid="classpath.test"/>
 
  lessthanSign /javac>
  lessthanSign /target>
 
  lessthanSign target name="test" depends="compile">
  lessthanSign junit>
  lessthanSign classpath refid="classpath.test" />
  lessthanSign formatter type="brief" usefile="false" />
  lessthanSign test name="test.SubscriptionTest" haltonfailure="no" outfile="result1"/>
  lessthanSign /junit>
  lessthanSign /target>



9. open command prompt and do the following

C:\Junit\Ant_project>ant test

10. you should get the test running

Wednesday

Loadrunner -- provide wait with waste time and timer

Action()

{

lr_start_transaction("Wait");

Wait(130000);

//lr_think_time(130);

lr_end_transaction("Wait", LR_AUTO);

return 0;

}

Create new action with name Wait

Wait(int time)

{

double timeElapsed;

merc_timer_handle_t timer;

if(time!=NULL)

{

timer = lr_start_timer();

sleep(time);

timeElapsed= lr_end_timer(timer);

lr_wasted_time(timeElapsed*1000);

}


return 0;

}