Thursday 7 April 2011

QTP - Getting current browser URL

I'm going to show and explain how to get current URL which is opened in a browser.
For example, how to get URL "http://motevich.blogspot.com" from the following browser:

There are two solutions:
  1. Using GetROProperty("URL") method (run-time object property)
  2. Using "URL" property of "Object" (IE DOM Object)
Let's consider both variants.

  1. GetRoProperty("URL") method (run-time object property)

    GetRoProperty
    function reads properties of a run-time object in an application.
    If you open QTP Help on GetRoProperty function, you 'll see that this function can work with all objects:
    So, for example:
    • to check whether a link is visible or not, use:
      Browser("bname").Page("pname").Link("lname").GetROProperty("visible")
    • to get a page's title, use:
      Browser("bname").Page("pname").GetROProperty("title")
    • to check whether a window is maximized, use:
      Window("wname").GetROProperty("maximized")
    • to get width of WebButton, use:
      Browser("bname").Page("pname").WebButton("btname").GetROProperty("width")
    Others properties are described in QTP Help.

    In our case, to get URL of the current WebPage, we will use:
    Browser("bname").Page("pname").GetRoProperty("URL")
    This is a sample QTP script:
    (Click the image to enlarge it)


  2. "URL" property of "Object" (IE DOM Object)

    The sample syntax is:

    Browser("bname").Page("pname").Object.URL

    What is "Object" in the above statement?

    Actually, this is Internet Explorer Document Object Model (DOM) Object.
    You can read more about DOM here and here.
    Also, I recommend to read this interested article on working with IE DOM from Visual Basic.

    Tip:
    You can use DOM Object when running QTP test on Internet Explorer only!

    To make the long story short, I can say that using Object property you can get almost all elements and properties from Web page.

    Thus, I use URL property of Internet Explorer's DOM Object.
    All properties, collections, and methods of DOM Object are described in this MSDN article.

    Tip:
    The number of properties, accessed via DOM Object, is more bigger, than properties accessed via GetROProperty method.

    So, the result of above code is:
    (Click the image to enlarge it)
Summary:
Two ways were discussed:
  1. GetROProperty("URL") (run-time object property)
  2. "URL" property of "Object" (IE DOM Object)
GetROProperty method supports both IE & FireFox, but IE DOM Object provides more accessible properties and methods.
Both can get URL of the current Web page.

Source

Wednesday 6 April 2011

quotes in VBScript

There two ways to do that:
  1. Double the quotes (""):
    MsgBox "#1: ""QTP - QuickTest Professional"""
    Use 2 double quotation marks to include a quote character in the string.
    So, the result is:

  2. Use ANSI character code - Chr(34):
    MsgBox "#2: " & Chr(34) & "QTP - QuickTest Professional" & Chr(34)
    Since, the ANSI code if quotation mark = 34, we can use Chr function.
    The result is:
Source

Tuesday 5 April 2011

How to set/get system time and date?

QTP allows running different types of test. And sometimes, it needs perform time and date manipulations on a computer. In this article, I will show and explain - how to get system time/date and change them.

Actually, today's lecture consists of two questions:
  1. How to get system time and date?
  2. How to set system time and date?
Let start training right now :)
So, the first section is:


How to get system time and date?


Actually, this is not difficult task! Use the following functions:
  • Now - function returns the current date and time according to the setting of your computer's system date and time.
  • Date - function returns the current system date.
  • Time - function returns a Variant of subtype Date indicating the current system time.
So, the code is very simple. I provide it with a screen shot containing results:


Well, let's deal with the second section:


How to set system time and date?

For that, I will use simple DOS commands:
  • time - this command displays or sets the system time:
    To change the time, pass it as a parameter to time command. See the above screen shot as an example.

  • date - this command displays or sets the system date:
    To change the date, pass it as a parameter to date command. See the above screen shot as an example for date manipulations :)
Now, I will combine all the above VBScript functions (Now, Date, Time) and DOC commands (time and date):

As you can see, initial date and time were '26.10.2007 22:45:10'. Then I added 3 days and 2 hours to initial date & time. The result of addition is - '30.10.2007 0:45:10'.

By the way, could you guess, why the result day is 30th, not 29th? :) To answer, please pay attention that we added 2 hours too :)

The last step - running of time and date commands from command line. I used Run method of WScript.Shell object.


So, as you can see - date and time manipulation is easy enough.

Source
Apex Monkeys © 2008. Design by :Yanku Templates Sponsored by: Tutorial87 Commentcute Software blogs Computers Blogs