How to capture the whole web page using QTP? - capture

How to capture the Whole web page when using QTP?
I am aware of 'CaptureBitmap' method for the screenshot. But how to capture the Whole page? Help !!

What do you want to capture? If it's the HTML you can create a checkpoint on the Page test object and check the HTML source checkbox in the HTML verification section.
If you want to capture an image of the page then you can only capture the visible part with CaptureBitmap there is no way to get an image of the scrolled out parts (unless you scroll and use multiple captures).

Use Browser("").Capturebitmap.
This takes the screenshot of the visible browser.
Use the sendkeys method to do a page down, then use Browser("").Capturebitmap again!

A full screen shot can be taken by toggling QTP's run settings rather than using CaptureBitmap. We can tell QTP to always take screen shots, interact with the page (or object) we wish to capture (e.g. call .Exist(0)) and this will feed a screen shot in to the results.
The code to do this:
Dim App 'As Application
Set App = CreateObject("QuickTest.Application")
App.Options.Run.ImageCaptureForTestResults = "Always"
Browser("index:=0").Page("index:=0").sync
App.Options.Run.ImageCaptureForTestResults = "OnError"
Technically this seems to be capturing the html and then presenting this to the user in the run results, rather than an actual image of the browser's presentation of the html. But still, this means we can see what's on the page but not visible.

I have went through lot of surfing but couldn't get right answer or I coudn't implement what I found due to restriction of using third party APIs in my office. By using dot net factory, we can use dot net libraries to take screen shots and merge them. refer the below page for complete code
http://www.testbasket.com/2015/08/capture-whole-web-page-using-uftqtp.html
However here i have pasted the contents from the page and hope it helps.
In order to do take the screenshot of complete page, I have used DotNetFactory and System.Drawing dot net library.
Lets go step by step to the solution,
As part of implementing the solution, we need to get the height and weight of the entire page. In order to get that we using DOM of a page using .object method.
#Get the Full Height of Page
FullHeight = Browser("Wikipedia, the free encycloped").Object.document.body.scrollheight
#Get the Full width of Page
Fullwidth = Browser("Wikipedia, the free encycloped").Object.document.body.scrollwidth
Once we found the complete page size, we need to find the client size (how much browser can show)
#Get the visible height - Viewable part of the page
BrowserHeight = Browser("Wikipedia, the free encycloped").Object.document.body.clientHeight
#Get the visible width - Viewable part of the page
Browserwidth = Browser("Wikipedia, the free encycloped").Object.document.body.clientwidth
Next we need to import required dot net libraries using Dot Net Factory
Set oGraphics=DotNetFactory.CreateInstance("System.Drawing.Graphics")
Set oPoint=DotNetFactory.CreateInstance("System.Drawing.Point")
Set oImgFormat=DotNetFactory.CreateInstance("System.Drawing.Imaging.ImageFormat","System.Drawing", Nothing)
Set oImageLib = DotNetFactory.CreateInstance("System.Drawing.Image")
Set oPens=DotNetFactory.CreateInstance("System.Drawing.Pens","System.Drawing")
As a final step, we need to loop through the page and take screenprints separately. finally using Dotnet library we will merge the images using graphics. draw method. It is easy to implement, complete set of code is available in the above mentioned link for reference

If you would like a single screenshot of the whole page, try using SnagIt.
There's a handy PDF with more info on how to go about it (http://download.techsmith.com/snagit/docs/comserver/enu/snagitcom.pdf)
In QTP it might look like this:
Sub Capture_Scroll_Image ()
Set objShell = CreateObject("WScript.Shell")
Set oSnag = CreateObject("SNAGIT.ImageCapture")
oSnag.IncludeCursor = False
oSnag.OutputImageFile.FileType = 5
oSnag.OutputImageFile.FileNamingMethod = 1
oSnag.OutputImageFile.Directory = "C:\Screens\"
oSnag.OutputImageFile.Filename = "Name"
oSnag.EnablePreviewWindow = False
oSnag.AutoScrollOptions.AutoScrollMethod= 1
oSnag.Capture()
Wait (1)
objShell.SendKeys "{ENTER}"
capDone = oSnag.IsCaptureDone
Do Until oSnag.IsCaptureDone
Loop
Set oSnag=Nothing
Set objShell=NothingEnd Sub
End Sub

Related

XWiki AppWithinMinutes add custom velocity script on display

I am new to XWiki and not a Java Developer. I would like to develop a simple AppWithinMinutes app (Let us call it ServerCatalog) for a list of servers with their properties like OS, Environment, etc.. That is all doable. I can develop that from AppWithinMinites UI.
I also have developed a macro which lists all pages by tags.
Now for example, when Someone creates an entry in my ServerCatalog say SERVERD56 Where D stands for Development environment.
when we display that Entry, I also want to execute my macro that I developed so that it can list all pages that matches the tag SERVERX56.
Note that I replaced D with X So before executing macro, I want to manipulate that page title and remove Environment prefix (in this case D for Development Environment) with X.
I hope it is clear of what I want to accomplish. Please let me know if it is unclear.
If someone can assist me on doing it, I will truly appreciate that.
EDITS:
As suggested by Eduard Moraru, I tried following things:
I have created a custom macro called "PageListByTag".
Since python has more control over string operations, I added following at the end of ServerCatalogSheet
.
.
.
.
{{/html}}
{{/velocity}}
{{python}}
title = document.getTitle()
newTitle = title[:6] + "X" + title[6+1:]
print(newTitle)
{{/python}}
There are several problems with it..
my html tag is already ended. I can't inject any new content in it anymore
I can't add python code inside velocity tags as nested scripting is not allowed by XWiki
I still don't know how to call my macro inside python code if I want to use python
If I can replace 6th character in a string using velocity, then everything works. I can use macro inside velocity script since it is within that html boundaries.
As far as I understand, you want to customize the "sheet" of the application which is used when displaying an application entry.
If you have a look a the documentation's section on customization, you get a lot of starting points on where you should be looking:
https://extensions.xwiki.org/xwiki/bin/view/Extension/App%20Within%20Minutes%20Application#HCustomization
This line would be interesting (but also the above links on how XWiki applications work):
The sheet, which is used to display and edit application entries (e.g. HolidaySheet)
In your case, it the document to customize (edit in wiki syntax mode) should be ServerCatalog.Code.ServerCatalogSheet
Inside that document, you have code automatically generated by AWM to which you can add a call to your macro.
## AWM generated code...
...
## Customization:
{{displayAssociatedPages /}}
Then, inside this macro (called displayAssociatedPages, in this example), you could do something like:
{{velocity}}
#set ($title = $doc.title)
## OR #set ($title = $doc.name), depending if your pages have titles
#if ($title.startsWith('SERVERD'))
#set ($tag = $title.replaceFirst('SERVERD', 'SERVERX'))
##
## We can reuse and customize this snippet: https://snippets.xwiki.org/xwiki/bin/view/Extension/Display%20pages%20with%20a%20specific%20tag/
##
#set ($references = $xwiki.tag.getDocumentsWithTag($tag))
#foreach($reference in $references)
#set ($document = $xwiki.getDocument($reference))
#set ($label = $document.getTitle())
[[$label>>$reference]]
#end
#end
{{/velocity}}
API documentation and more info at https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/API/
Also, you should understand that once you customize an AWM application, you should be careful when editing it with AWM itself. For example, if you add a new field, AFAIK, you risk having the customizations done to your sheet, as in the above example, overwritten, so you should recover them from document history and re-apply them.

How to copy text from a web element division having "CALSS" tag plus "Data-Role" tag in the same division

I am trying to copy the text highlighted in Yellow (from the HTML image) using a Selenium VBA code with MS Excel to a string. However, it is crashing and not getting copied. But the same code is working if I were to use it on other websites where the division does not contain "Data-Role" element within a webpage. I tried to make use of all element type like ByName ById ByClass but none of these technique seems to be working. Please note I am using Selenium to access the Chrome browser. I am trying to store the Yellow highlighted text data into a string "Res". Any help or tip is much appreciated. Below is the sample code which I am trying to use.
Dim Res As String
Dim be As New WebDriver
On Error Resume Next
be.Start "chrome", ""
be.Get "the website from which I am tryig to pull data"
Res = be.FindElementByClass("text--1jzYQ uppercase--tL_HU").Text
[![enter image description here][2]][2]
Without having the website address (if able to test with it), or any error messages, can't tell you why it is crashing. Possibly accessing a dynamic element which is still resolving? Dunno.
However, those classes look dynamic, so in terms of robustness, perhaps try using a combination of more stable looking attribute = value css selectors:
be.FindElementByCss("[data-role=status-bar] [data-role=status-text]").text

How to set PhantomJS's ViewPort Size in VBA?

I'm working on a project in VBA with Selenium, and I've been trying to set the size of the virtual "window" phantomJS simulates (since it's headless) so that a website loads correctly, since it relies on window size to reorganize css elements in a grid.
I need it to be 1920*1080 in resolution. I'm pretty sure it's just about changing the viewportSize property using arguments, but I'm not sure how to specify this particular one in VBA. I haven't seen any post mentioning how to do it in VBA, so I thought I'd ask here.
Thanks!
Looks like this has an example on how to add the screen size.
Set driver = CreateObject("Selenium.PhantomJSDriver")
'Open Google search UK
driver.Get "https://www.google.co.uk"
'Set the window's size in pixels
driver.Window.SetSize 1024, 768
'Capture the rendering with a 500ms delay
Set imageA = driver.TakeScreenshot(500)

IE automation through Excel vba

The problem that I'm having is quite simple. I'm opening a webpage, looking for the input box where I type some text and then hit a Search button. Once the new webpage is uploaded I gather all the info I need. My problem is in the time spent uploading the webpage. My gathering code doesn't work because the new webpage is still not loaded. I have the following code to wait for that:
Do While ie.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
where ie was set like this
Set ie = New InternetExplorer
Is there another code except the application.wait that I can use to fix this?
I've run into similar issues when attempting the same. The issue is that the ready state on the IE object can't always be trusted, or at the very least, it's not signaling what you think. For example it will let you know when each frame is ready, not the whole page. So if you don't actually need to see the web browser control, and you only care about sending and receiving data. My suggestion is to not bother rending the page in a web browser object, instead just send and receive data using a WinHttpRequest.
Tools>References>Microsoft WinHTTP Services
Using this, you can send and receive the HTML data directly. If your page uses URL parameters, you send a "GET" then parse the reply. Otherwise you will have to send a "PUT" and send the edited HTML (Basically take the blank form page you begin with and set all the values). When first using, it can be a bit tricky to get the formatting correct depending on the complexity of the page you are trying to automate. Find a good web dugging tool (such as Fiddler) so that you can see the HTML being sent to your target page.

Set OpenSeaDragon Viewer Home to "Top" of Image

I'm using OSD to display a few pages from a PDF. Each page is lined up one on top of the other.
I'd like the viewer to start at the top of the image, zoomed to fit. I've played with various settings, but what seems to work for one image of three pages, doesn't work for another image of five. I can get close to what I want with this command:
viewer.viewport.panTo(new OpenSeadragon.Point(.5, .5));
viewer.viewport.zoomTo(1);
But I'll be honest that I don't quite understand what that means, and I have no idea how to set this as the "home" bounds. I've been through the documentation several times, but this escapes me.
Appreciate any guidance!
Rather than using panTo and zoomTo, I recommend using fitBounds instead. You'll want to base it off of the aspect ratio of your viewer so the result is snug. Something like so:
var oldBounds = viewer.viewport.getBounds();
var newBounds = new OpenSeadragon.Rect(0, 0, 1, oldBounds.height / oldBounds.width);
viewer.viewport.fitBounds(newBounds, true);
The true in the fitBounds is to make it snap there immediately instead of animating.

Resources