Highlighted
Absent Member.
Absent Member.
1132 views

Capturing Screenshot

i was make a function for capturing screenshot and it will run properly, but my concern is to can i also pass image name and image url like dynamic. please review my code.

Class xyz


' Capture Screenshot

Function capture_bitmap(br,pg)
if browser ("title:="&br).page("title:="&pg).Exist(10) then
browser ("title:="&br).page("title:="&pg).CaptureBitmap "D:\way2sms\screenshot\login.bmp"

Reporter.Reportevent micPass,"success","data entry successful"
else
Reporter.Reportevent micfail,"fail","object identifiction unsuccessful "
End if
capture_bitmap="Screenshot Captured Successfully"
End Function


End class

0 Likes
3 Replies
Highlighted
Respected Contributor.
Respected Contributor.

Re: Capturing Screenshot

Hi Abhishek,

We can pass the image name at dynamic using Environment value. Please refer below code for dynamic image name change.

Environment.Value("Counter") = 1

filepath = "C:\Automation\QTPResults\ScreenImages\"

CaptureBitmap filepath&"\"&"_Image"&Environment.Value("Counter")&".png", true

Environment.Value("Counter") = Environment.Value("Counter") +1

To pass the Image URL at run time from sheet:

sSetURL= Trim(DataTable("ImageURL",dtLocalSheet))

Browser(“name:=XXX”).Page(“title:=YYY”).Image(“html tag:=IMG”, “src:=” &sSetURL).Highlight

                (or)

If you want to get the Image URL at runtime and pass the image URL, please use GetROProperty using descriptive programming.

Regards,

Sakthi.K


If you find that this or any post resolves your issue,
please be sure to mark it as an accepted solution and give Kudos to the author for their assistance.

Regards,
Sakthirajan Kathirvel
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Capturing Screenshot

Aabhishek,

Does you mean by " pass image name and image url " is you want to dynamically send file path and image file name to your fucntion.

Try below mathod

make a local verible and store yur file path and imagefile there.

dim imagename ,Filepath

Filename = "c:\desktop\user\......" (this is for example this can be changed as per requirement)

image file name you can create dynamcally

imagename = " Screencapture" & "_" & testSenario/application name & "_" &  now()

adding datetime stamp to image will make it more easy find out.

Browser("title:=.*").Page("title:=.*").CaptureBitmap Filepath & imagename &".png"    

your function will be like this

call  capture_bitmap(br,pg,imagename ,Filepath )

Function capture_bitmap(br,pg,imagename ,Filepath )
if browser ("title:="&br).page("title:="&pg).Exist(10) then
browser ("title:="&br).page("title:="&pg).CaptureBitmap Filepath & imagename &".png" 

Reporter.Reportevent micPass,"success","data entry successful"
else
Reporter.Reportevent micfail,"fail","object identifiction unsuccessful "
End if
capture_bitmap="Screenshot Captured Successfully"
End Function


End class

 

Hope i understand your Scenario correctly , let me know

 
0 Likes
Highlighted
Super Contributor.
Super Contributor.

Re: Capturing Screenshot

How could I do the same in LeanFT?

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.