How to capture dynamic text in QTP? Step-by-step illustrative example.

3,393 views
Skip to first unread message

Dmitry Motevich

unread,
Jan 12, 2007, 3:34:27 AM1/12/07
to QTP - Mercury QuickTest Professional - Automated Testing
Hello,

I want to tell about the capturing of dynamically changing text.
Let's we have a task - it is needed to get the quantity of found results for some google search query. Please, see screenshot task.jpg. I highlighted the text to be captured.

So. let's start! :) It's easy, believe me :)

1. Start script recording for site www.google.com. See step1.jpg
2. Enter "any query". See step2.jpg
3. Press "Google Search" btn
4. Results are shown. OK. See step3.jpg
5. Stop script recording in QTP
6. In QTP editor: Set cursor to last resorded step (Browser("Google").Page(" any query - Google Search").Sync) and see active screen (step4.jpg).
7. Select text we want to capture ("76,400,000" in our case), right-mouse click and select ("Insert Text Output"). See step5.jpg
8. Set "Text Before" to "10 of about ". See step6.jpg
9. Set "Text After" to " for ". See step7.jpg
Note: I have changed default value of "Text After". Initial value was " for any query. ( 0.05 seconds) Script ". Default value does not suit us, since query ("any query") and time ("0.05 seconds") can vary from search to search, so we cannot capture the text correctly every time.
10. Set output value to be saved to DataTable. See step8.jpg
11. Modify script - Add one line to show captured text:
MsgBox(DataTable. Value("Quantity"))

That's all !!!

Run our script now and enjoy! We have done it! Please, see step9.jpg

To make sure we wrote correct script, I changed the query to "play chess". And new captured result is "3,940,000". See step10.jpg
As I've said - it's easy!

Any questions/comments?

--
Dmitry Motevich
task.jpg
step7.jpg
step8.jpg
step1.jpg
step2.jpg
step3.jpg
step4.jpg
step5.jpg
step6.jpg
step9.jpg
step10.jpg

Dmitry Motevich

unread,
Jan 12, 2007, 3:47:20 AM1/12/07
to QTP - Mercury QuickTest Professional - Automated Testing
I have attached step9.jpg and step10.jpg files.


---------- Forwarded message ----------
From: Dmitry Motevich <mang...@gmail.com >
Date: Jan 12, 2007 11:34 AM
Subject: How to capture dynamic text in QTP? Step-by-step illustrative example.
To: QTP - Mercury QuickTest Professional - Automated Testing < mercu...@googlegroups.com>

Hello,

I want to tell about the capturing of dynamically changing text.
Let's we have a task - it is needed to get the quantity of found results for some google search query. Please, see screenshot task.jpg. I highlighted the text to be captured.

So. let's start! :) It's easy, believe me :)

1. Start script recording for site www.google.com . See step1.jpg

2. Enter "any query". See step2.jpg
3. Press "Google Search" btn
4. Results are shown. OK. See step3.jpg
5. Stop script recording in QTP
6. In QTP editor: Set cursor to last resorded step (Browser("Google").Page(" any query - Google Search").Sync) and see active screen (step4.jpg).
7. Select text we want to capture ("76,400,000" in our case), right-mouse click and select ("Insert Text Output"). See step5.jpg
8. Set "Text Before" to "10 of about ". See step6.jpg
9. Set "Text After" to " for ". See step7.jpg
Note: I have changed default value of "Text After". Initial value was " for any query. ( 0.05 seconds) Script ". Default value does not suit us, since query ("any query") and time ("0.05 seconds") can vary from search to search, so we cannot capture the text correctly every time.
10. Set output value to be saved to DataTable. See step8.jpg
11. Modify script - Add one line to show captured text:
MsgBox(DataTable. Value("Quantity"))

That's all !!!

Run our script now and enjoy! We have done it! Please, see step9.jpg

To make sure we wrote correct script, I changed the query to "play chess". And new captured result is "3,940,000". See step10.jpg
As I've said - it's easy!

Any questions/comments?

--
Dmitry Motevich


--
Dmitry Motevich
task.jpg
step7.jpg
step8.jpg
step9.jpg
step10.jpg
step1.jpg
step2.jpg
step3.jpg
step4.jpg
step5.jpg
step6.jpg
step9.jpg
step10.jpg
Message has been deleted

Dmitry Motevich

unread,
Jan 16, 2007, 6:10:57 AM1/16/07
to Mercu...@googlegroups.com
Mabobine, this ("the data table dissappears") is a correct behaviour.
I would be surprised if it turned out in a different way :)

Please, don't confuse run-time Data Table with design-time Data Table.

During the run session, QuickTest creates a run-time Data Table - a live version of the Data Table associated with your test or component. During the run session, QuickTest displays the run-time data in the Data Table pane so that you can see any changes to the Data Table as they occur.

When the run session ends, the run-time Data Table closes, and the Data Table pane again displays the stored design-time Data Table.

Data entered in the run-time Data Table during the run session is NOT saved with the test or component. The final data from the run-time Data Table is displayed in the Run-Time Data Table in the Test Results window.

Mabobine, If it is important for you to save the resulting data from the run-time Data Table, you can insert a DataTable.Export statement to the end of your test or component to export the run-time Data Table to a file.
You can then import the data to the design-time Data Table using the Data Table's File >Import menu.
Alternatively you can add a DataTable.Import statement to the beginning of your test or component to import the run-time Data Table that was exported at the end of the previous run session.



On 1/16/07, mabobine <raheel...@gmail.com> wrote:

One more thing that i have noticed is that the value stored in the data
table dissappears as long as the test is completed. Can't it remain
there

Thanks


Dmitry Motevich
Message has been deleted

Dmitry Motevich

unread,
Jan 18, 2007, 8:51:22 AM1/18/07
to Mercu...@googlegroups.com
See answers below, please...

On 1/17/07, mabobine <raheel...@gmail.com> wrote:

Thanks a lot. Your answers are really descriptive and easy to
understand. I really appreciate the way you have guided me and others.

So with the command DataTable.Export, can we capture more than one
values of the dataTable, or only the last value of the DataTable.

You can save values into different lines of DataTable and then you can perform exporting to save all captured values.
Try this:

DataTable.Value("Quantity")  = "first line"
DataTable.SetCurrentRow(DataTable.GetCurrentRow + 1)
DataTable.Value("Quantity") = "second line"
DataTable.SetCurrentRow(DataTable.GetCurrentRow + 1)
DataTable.Value("Quantity") = "third line"
DataTable.Export("C:\res.xls")

Now, file "C:\res.xls" will contain all tree lines. See attached screenshot.


One more question. I hope you would guide me in the same manner as you
have been guiding me previously.

In my application, what is going on is that we create a letter on the
first page. Then a success message appears with the document ID of that
document. On the next page, there is a table which displays the list of
all the created documents. The user can open the document by clicking
on the document ID (which is a hyperlink).

Now, i want to automate the whole test, i.e. first capture the
dynamically generated string (which you have taught me how to do it),
then on the next page, i can use that captured generated string to use
as a hyperlink

Browser("").Page("").Link("JJNI9").Click

The above generated script is generated by QTP when i click on that
hyperlink (on the second page). JJNI9 is the document ID of the
document. I need to change this script so that I can use the captured
dynamically string from the first page, to use it here.

Regards
Please, create new topic for this question.


> > Thanks--
> Dmitry Motevich


Dmitry Motevich
lines.jpg
Message has been deleted
Message has been deleted

Dmitry Motevich

unread,
Feb 8, 2007, 6:19:17 PM2/8/07
to Mercu...@googlegroups.com
To export DataTable to a file, run the following code:
DataTable.Export("C:\res.xls")

Also, you export one sheet only:
DataTable.ExportSheet("C:\res.xls" ,1)


On 1/19/07, mabobine < raheel...@gmail.com> wrote:

Thanks a lot for replying.

Please ellaborate me a little bit more about the code you have recently
provided to export more than one values from dataTable to some file,
say excel sheet.

Can you update your code by your google example where you searched a
text and results were displayed. Run that test for 3 times. Now the
generated strings for results are also 3. So export those 3 values in
the excel file.

Thanks again for taking your time to solve the problems.

Regards


Dmitry Motevich
Reply all
Reply to author
Forward
0 new messages