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.

How to Kill Process from Task Manager 

Code:-


'*******************************************Function************************************************
'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
fn_CloseBrowser
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
allBrowser(iCnt).Close
End If
Next
'Destroying the objects
Set objBrowser = Nothing
Set objPg = Nothing
Set objPage = Nothing
End Sub

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.

Solution:-
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

Summary:- 
To downgrade Compass, we can simply use the following commands:
gem uninstall compass
gem install compass –version versionnumber

Understanding Selenium WebDriver Navigation Commands?

After successfully running 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 automation 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
driver.navigate().to(“http://www.uftHelp.com”);

Forward Command:-
This command is similar to browser forward button, Takes you forward by one page on the browser’s history.
driver.navigate().forward();

Back Command:-
Used to go back to previous page like browser’s back button.
driver.navigate().back();

Refresh Command:-
Refresh the current page.

driver.navigate().refresh();

Note:- Same can be achieved using "sendkeys"

driver.findElement(By.id(locator)).sendKeys(Keys.F5);

Get Command:-
Opens  a new browser window and navigate to given URL.
driver.get(“http://www.uftHelp.com”);

Get v/s Navigate :-
“navigate().to()” and “get()” do exactly the same thing. Only thing is that incase of “get” selenium would wait for the page to fully load before executing the next line of code.

Also “navigate” interface further 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

Code:-

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
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("webdriver.chrome.driver", "C:\chromedriver.exe");
WebDriver driver = new ChromeDriver();
//Opens the given URL using Get Method
driver.get("http://www.uftHelp.com");
//Click on Contact Us Link
System.out.println("Open Contact Us page");
driver.findElement(By.id("contact-Us")).click();
//Using Back Command, go back to "Home" page
System.out.println("Navigate Back to Home Page");
driver.navigate().back();
// Using Forward Command, go to "Contact Us" link
System.out.println("Navigate Forward to Contact Us Page ");
driver.navigate().forward();
//Refresh the page
System.out.println("Refresh the Contact Us Page ");
driver.navigate().refresh();
//Using To command, open the Selenium Page
System.out.println("Navigate To Selenium Page");
driver.navigate().to("http://www.ufthelp.com/p/selenium.html");
System.out.println("Close the Browser");
//Closing the Browser
driver.close();

}

}

Getting started with Sass (Installation)

Requirement:-

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.

    sudo apt-get update
    sudo apt-get install ruby-full rubygems


    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.

    Check Ruby Version to verify installation

    ruby –version

    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 Terminal.app 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:

             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 windows
    Install sass on ubuntu
    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).

    If you face the following error while installing Sass,

    error-image

    It means, your HOMEDRIVE is set to P.Execute the following command in command prompt or power-shell to set it to C or where you have installed ruby.


     SET HOMEDRIVE=C:

    You can check the HOMEDRIVE by running SET HOMEDRIVE

    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.

    Solution:-
    We simply tried to change the previous code and passed the reference of “chromedriver”.

    Before :-
      WebDriver driver = new FirefoxDriver();
    After:-
      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 webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html at com.google.common.base.Preconditions.checkState(Preconditions.java:177) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:89) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:117) at LearnSelenium.main(LearnSelenium.java:10)



    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 :– http://chromedriver.storage.googleapis.com/index.html

    Chromedriver download
    Download the latest version 


    ChromeDriver for selenium
    Check the OS

     Note:-
     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.

    Syntax:-System.setproperty(key,value);
     Key = “webdriver.chrome.driver”
     Value = “chromedriver.exe”, Absolute path of chromedriver , (Refer Step-2 above)

    Code:-

    import org.openqa.selenium.WebDriver;
    import java.lang.*;
    import org.openqa.selenium.chrome.ChromeDriver;
    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("webdriver.chrome.driver", "D:\Automation\Selenium\MyCode\chromedriver_win32\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    //Opens the given URL
    driver.get("http://www.uftHelp.com");
    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
    driver.close();
    }

    }

    Some crucial tips for selenium automation testing

    How to Dismiss angular modal on URL change ?

    Requirement :-
    We have a Angular bootstrap Modal to show a popup window. On clicking backspace / browser back button, we want to cancel the popup and continue with the url change. The default behaviour is that page behind the modal changes, but the modal remains on top.
    Plunker link for issue 
    GitHub issue

    Solution :- 


    We have seen lot of people facing this challenging scenario . To overcome this issue is to write a directive in Angular JS.

    Code:-


    app.directive('discardModal', ['$rootScope', '$modalStack',
    function($rootScope, $modalStack) {
    return {
    restrict: 'A',
    link: function() {
    /**
    * If you are using ui-router, use $stateChangeStart method otherwise use $locationChangeStart
    * StateChangeStart will trigger as soon as the user clicks browser back button or keyboard backspace and modal will be removed from modal stack
    */
    $rootScope.$on('$stateChangeStart', function (event) {
    var top = $modalStack.getTop();
    if (top) {
    $modalStack.dismiss(top.key);
    }
    });
    }
    };
    }
    ]);



    How to write my first Test Case using Selenium in Eclipse?

    We are already finished with the prerequisite for starting with “Selenium”.Now we are taking a step further towards learning “Selenium”.
    You can also check how to write first program in Eclipse.

    Requirement:-Configuring Selenium Webdriver Jar files in Eclipse to write our first Selenium Program.

    Solution:-
    Step1:-Adding Jar files to Eclipse

    Right Click “Java Project” in Package Explorer ->Build Path ->Configure Build Path

    Opening add JAR dialog
    Configure Build Path

    Select Libraries Tab ->Click Add External JAR’s

    Window to Add JAR files
    Add External JAR’s

    Browse to Selenium JAR files (For DownloadProcess) ->Add the Selenium JAR (We can add source JAR also) , Open the Lib folder to add all the JAR files.

    Selenium JAR selection
    Browse the Selenium JAR location

    Click OK button to Add all the selected JAR files

    Add JAR from Libraries
    Adding JAR to Project


    Note :- One’s JAR files are added, we can confirm it, under Reference in Project Explorer


    Step2:- Writing and Running our first line of Selenium Code.(For running the First Java Program)

    Flow :- Launching the firefox browser -> open the URL -> fetch the Title details.

    import org.openqa.selenium.WebDriver;
    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();
    //Opens the given URL
    driver.get("http://www.uftHelp.com");
    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
    driver.close();
    }

    }

    Add the above lines of code and Run it to success (CTRL + F11)

    Result in Console 

    Console in eclipse
    Console Results

    How to run the above code in Google Chrome?

    “Hello World!”- My First Java Program in Eclipse.

    Understanding IDE of Eclipse is the core for starting with Selenium. Today we are trying our age long program “Hello World!” in Eclipse using Java.Hope it would motivate our automation lovers in the journey towards Java and Selenium using Eclipse 🙂

    Requirement:- How to write a Java program in Eclipse?

    Solution:-
    Step1:-
    After downloading Eclipse, launch the IDE and select the WorkSpace.

    Eclipse
    Launching Eclipse



    Step2:-
    File ->New->JavaProject
    Click Finish

    JavaProject Dialog
    Creating Java Project

    Step3:-
    Program will be created,under Package Explorer(On the Top Left Corner)
    Note:-Incase “Package Explorer” is not visible, follow the path, Window->ShowView->Package Explorer

    Launch Package Explorer
    Package Explorer 

    Step4:-
    File->New->Class
    or 
    Right Click the “Java Project ” in Package Explorer ->New ->Class


    Step5:-
    Give the Name of “Class” and click Finish
    Note:- Select the option “public static void main(String[] args)” incase you want default method to be included in the code

    Adding Class in Eclipse
    Adding Class with default Method

    Step6:-
    Type “sysout” -> Press “CTRL+SpaceBar” -> Select the sysout option.

    Note:- We can use -> “main” + CTRL+SpaceBar for creating “Public static void Main” method. 

    SysOut in Eclipse
    SYSOUT shortcut

    Step7:-
    Write most awaited “HelloWorld!” inside the System.out.println(); and “File->Save”

    Step8:-
    RightClick the ProgramName ->RunAs->JavaApplication
    or 
    Directly click the “Run” icon on the ToolBar(CTRL+F11)

    Run Java Project in Eclipse
    Run Java Program 

     Step9:-
    On the bottom, check the results under “Console”

    Result in Eclipse
    Console Result

    Congrats!!We are done with our First Program 🙂

    Now let us learn how to write our first selenium test case..

    How to solve the issue with Resize of TextArea in IE using JQUERY?

    Requirement:- We need our TextArea should be flexible to be re-sized by user in Internet Explorer?

    Solution:-
    We followed the approach of JQuery to solve the problem.

    Method:-
    Resizable 

    Working Demo

    Code:-


    CSS:-

    css for TextArea
    CSS part

    HTML:-

    HTML for TextArea
    HTML Code

    JavaScript:-

    JavaScript for TextArea
    JavaScript

    Result:-

    TextArea
    Resize the TextArea

    Note:-
    -We can apply the above code on other HTML elements also like DIV.
    -We can also write the Directive in Angular to achieve the above results.

    Prerequisites for starting with selenium webdriver?

    Whole automation fraternity is crazy about the emerging demand of selenium.Today we are sharing our 1st post on selenium.We are not doing something out-of-box, however we tend to start a basic step towards helping people learn Selenium.Hope our this initiative can guide and mentor our budding automation coders.

    Requirement:- What is required to execute and get acquaintance with Selenium.

    Solution:- Java,Eclipse,FireBug&Selenium

    Java :-
    JDK(Java development Kit) is the first essential component to start with selenium.

    After downloading, run the exe file to complete the installation


    Steps:-

    Java Download
    Click on Download Link

    Java download for Selenium
    Select the appropriate options

     Note:- Installation is successful, we can verify that by typing “java” in command prompt

    Cmd prompt for Java
    Java is installed 

    Eclipse:-
    IDE(integrated development environment) for doing coding.

    After downloading , extract the file and run the “eclipse.exe” to launch it.

    Steps:-

    Eclipse download
    Select version of Eclipse

    Download Eclipse
    In the workspace, select the location where our code will be saved.
    WorkSpace
    Select Path to save the code
    Firebug:– 
    It is a web development tool that facilitates the debugging, editing, and monitoring of any website’s CSS, HTML, DOM, XHR, and JavaScript.We need this to work with webdriver, to get the location of elements like xpath or ID.

    Steps:-
    Download Firebug
    Download Firebug
    Note:- Try to download the latest available version.
    After Installing, we can launch the plugin by navigating to “Web Developer” >> “Firebug”.

    Selenium WebDriver:

    After downloading and extracting the files,we will get a folder which should contain two jar files related to selenium, a lib folder which also contains jar files inside it. Beside this, there is a change log file as well.
    Selenium Download
    Downloading Selenium

    Selenium Jar
    Selenium Jar files
    Note:- For comprehensive list of all the webdriver versions, click here

    First Program using Eclipse.