Thursday, 30 October 2014

How to close all browsers other than ALM in UFT using Descriptive Programming.

Requirement:- Close all browsers other than Application life cycle (ALM/QC) 

Kill browser other than ALM 

Solution:- We followed the concept of Descriptive Programming in UFT to achieve the result.

Approach:- Very simple and straight flow,look for all the opened browsers (Creating DP object ). Incase browser is not ALM close it.


'Function Name:-        fn_CloseBrowser
'Function Description:- Function to close browser other than ALM instance using DP approach 
'Input Parameters:-     None
'Output Parameters:-    None
'function call 
Sub fn_CloseBrowser ()
    Dim iCnt :iCnt = 0
 'Incase Occur occurs move to next step
 On Error Resume Next
 'Using Descriptive Programming in UFT to create the browser object
 Set objBrowser = Description.Create
 objBrowser("micclass").Value = "Browser"
 'Creating the Page Desription
 Set objPage = Description.Create
 objPage("micclass").Value = "Page"
 'Get all browsers which are opened
 Set allBrowser = Desktop.ChildObjects(objBrowser)
 'Taking the count of browsers
 iCntBrowser = allBrowser.Count - 1
 'if no browsers were found, exit
 If iCntBrowser < 0 Then
  Msgbox "No opened Browser found!!!"
  Exit Sub       
 End If
 'Looping untiL the last opened browser
 For iCnt = 0 To iCntBrowser
  'Get the page object from the browser
  Set objPg = allBrowser(iCnt).ChildObjects(objPage)(0)
  'exit if the last open browser is ALM  (as we don't want to close this)
  If iCntBrowser=0 AND InStr(objPg.GetROProperty("title"), "HP Application Lifecycle Management") > 0 Then
   On Error GoTo 0
   Msgbox "Only ALM browser is opened!!!"
   Exit Sub
  End If
  'Close the browser
  If InStr(objPg.GetROProperty("title"), "HP Application Lifecycle Management") = 0 Then
  End If
 'Destroying the objects
 Set objBrowser = Nothing
 Set objPg = Nothing 
 Set objPage = Nothing  
End Sub

Tuesday, 28 October 2014

How to Downgrade the existing Sass Version ?

Issue :- We installed the newest version of compass but it is giving unpleasant error. How we can downgrade to an older version to make things working.

When installing compass (v1.0.1), it will download the latest sass v3.4.6 (because it's a dependency), but compass won't work with the latest sass. You have to downgrade sass to 3.4.5 or earlier version
Compass Command
Install Compass

Approach 1:-
Specify version number
Uninstall Sass
Using Version Number
Approach 2:-
Without version number

Uninstall Sass without any version
Without Version Number

Note :- If we select 4 to uninstall all versions, it will further prompt to remove its dependencies.
Uninstall Sass with all dependencies
Select 4 from above options

Now we can downgrade using  gem install –version versionnumber

Install downgraded version of Sass
Installing Sass downgraded version
To downgrade Compass, we can simply use the following commands:
gem uninstall compass
gem install compass –version versionnumber

Understanding Selenium WebDriver Navigation Commands?

After our successful run of our first test case on Firefox and Chrome. We are stepping towards grasping the essential navigation commands in Selenium. Thus we are going to discuss about multifarious browser commands that we would be using in our day to day life in testing.

Requirement :- 
How to navigate in Browser using Selenium Webdriver?

Solution :-
We are focusing on Get and Navigate Commands.
MindMap for Selenium Navigation commands
Browser Navigation Commands

To Command:-
This command is use to navigate to specific page or URL

Forward Command:-
This command is similar to browser forward button, Takes you forward by one page on the browser's history.

Back Command:-
Used to go back to previous page like browser’s back button.

Refresh Command:-
Refresh the current page.

Get Command:-
Opens  a new browser window and navigate to given URL.

Get v/s Navigate :-
"navigate().to()" and "get()" do exactly the same thing. One's just a lot easier to type than the other!
But "navigate" interface also exposes the ability to move backwards and forwards in your browser's history.

Let us test the above commands by completing the following Test Scenario:-

  1. Launch Home page using Get Method
  2. Open Contact Us page
  3. Navigate Back to Home Page
  4. Navigate Forward to Contact Us Page 
  5. Refresh the Contact Us Page 
  6. Navigate To Selenium Page
  7. Close the Browser


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
public class Navigation {

 public static void main(String[] args) {
   //Creating WebDriver Object
    System.out.println("Launch Home page using Get Method");
    System.setProperty("", "C:\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
   //Opens the given URL using Get Method
   //Click on Contact Us Link
    System.out.println("Open Contact Us page");
   //Using Back Command, go back to "Home" page
    System.out.println("Navigate Back to Home Page");
   // Using Forward Command, go to "Contact Us" link
    System.out.println("Navigate Forward to Contact Us Page ");
    //Refresh the page
    System.out.println("Refresh the Contact Us Page ");
   //Using To command, open the Selenium Page
    System.out.println("Navigate To Selenium Page");
    System.out.println("Close the Browser");
   //Closing the Browser



Monday, 27 October 2014

Getting started with Sass (Installation)


Installing Sass on Windows/Linux/Mac platform.

What is Sass?

Sass(Syntactically Awesome StyleSheets) is an extension of CSS that adds power and elegance to the basic language. It allows you to use variables, nested rules, mixins, inline imports, and more, all with fully CSS-compatible syntax and adds features to combat shortcomings. Sass helps keep large stylesheets well-organized, and get small stylesheets up and running quickly; particularly with the help of the Compass style library. It is a preprocessor like CoffeeScript & Haml
Sass Compiler
Flow of Sass

Installing Sass

Sass has a Ruby dependency and we need to install Ruby first before starting with Saas installation.

Linux Platform

We can install Ruby through the apt package manager, rbenv, or rvm.

Windows Platform

The promptest method to get Ruby on our Windows computer is to use Ruby Installer. It's a single-click installer and will create the full package .The installer will also install a Ruby command line powershell application that will let us use the Ruby libraries.

Mac Platform

Ruby is pre-installed on Mac.

Steps to follow:-

Open your Terminal or Command Prompt. On Windows, Start -> Run, then type “cmd” in Run to launch it.

On the Mac the comes installed by default. It's located in the "Utilities" folder.

Install Sass. Ruby uses Gems to manage its various packages of code like Sass. Open terminal or command prompt window and type:
Sass installation on windows
Installation on Windows
         For Linux/Mac, you will need to use the sudo command to install the Sass gem. It would look     like:

Installation on Linux/Mac
Installation on Linux/Mac

This will install Sass and any of its dependencies.After successful installation we can cross-check it:

Verify Sass
Verify installation of Sass
It should return Sass 3.4.6 (Selective Steve).

In next post, we are going to discuss about how to write styles using Sass.

Running Selenium test case in Google Chrome?

We have already learned to execute selenium test case in Firefox browser . Now we thought of running the same test on "Google Chrome".

Requirement:- Executing selenium webdriver test case in Google chrome for the first time.

We simply tried to change the previous code and passed the reference of "chromedriver".

Before :-
  WebDriver driver = new FirefoxDriver();
  WebDriver driver = new ChromeDriver();

But !!!
On our execution of the test case we encountered a below error message:-

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the system property; for more information, see The latest version can be downloaded from at at org.openqa.selenium.remote.service.DriverService.findExecutable( at at at LearnSelenium.main(

This error message was a hint for our solution. We followed this to solve the puzzle of running our test on chrome.

Step1:- We need to download the "ChromeDriver"(Given in the above error message)
Link :
Chromedriver download
Download the latest version 

ChromeDriver for selenium
Check the OS
 We can check the latest bug fixes from notes.txt
 For other Drivers download 

Step2:- Extract the file (chromedriver.exe)

Step3:-We need to use the "System Property" to create a bridge between the selenium webdriver and google chrome.

 Key = ""
 Value = "chromedriver.exe", Absolute path of chromedriver , (Refer Step-2 above)


import org.openqa.selenium.WebDriver;
import java.lang.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LearnSelenium {

public static void main(String[] args) {
  //Creating WebDriver Object
  System.out.println("Launching the Browser");
  //WebDriver driver = new FirefoxDriver();
  System.setProperty("", "D:\\Automation\\Selenium\\MyCode\\chromedriver_win32\\chromedriver.exe");
  WebDriver driver = new ChromeDriver();
  //Opens the given URL
    System.out.println("Fetching the Title");
    System.out.println("Please Wait!!");
  //Returns the Title of Current Page
    String sTitle = driver.getTitle();
    System.out.println("My First Selenium Program");
    System.out.println("Title is = '"+sTitle+"'" );
   //Closing the Browser