Documentation for custom screenshot with python is still wrong
Closed this issue · 5 comments
After having issues with the custom screenshots, I found issue #133 which contained the proper documentation fix.
However, as of the time of writing this comment, the documentation here: https://docs.gauge.org/writing-specifications.html?os=windows&language=python&ide=vscode
is still showing the old method of setting up a custom screenshot (which fails).
I could see the updated docs as per commit ... if you are seeing something different please try hard refreshing the page or if the given snippet does not work for you raise an issue with details.
Hi Nivedha, thank you for your prompt response - and for working on Gauge, it's awesome 👍 .
I can confirm that I do see the docs as per the commit you linked. However, the snippet is not working for me, and the old snippet where the docs were previously fixed (for #133) is working for me.
In other words, it looks like it went: broken -> fixed by #133 -> broken by #302
To be clear, the snippet that is working for me is:
# Using Webdriver
from getgauge.python import screenshot
@custom_screen_grabber
# Return a screenshot byte array
def take_screenshot():
return Driver.driver.get_screenshot_as_png()
and not working:
# Return a screenshot file name
@custom_screenshot_writer
def take_screenshot():
conetnt = Driver.driver.get_screenshot_as_png()
file_name=os.path.join(os.getenv("gauge_screenshots_dir"),screenshot{0}.png".format(uuid1().int))
file = open(file_name, "w")
file.write(conetnt)
return os.path.basename(file_name)
Not only does the annotation @custom_screenshot_writer
appear to be incorrect, the return value of the file name does nothing. An additional minor point is that "content" is spelled incorrectly.
Perhaps I am using something incorrectly, but it seems strange than the old snippet would work, and not the new one.
@custom_screen_grabber is deprecated in latest version of gauge-python v0.3.8 and from gauge v1.0.7 screenshots are saved to files. Please do update gauge and gauge-python to see if it works.
Ah, I see. That's probably why!
This led me to a solution that works using a version of the latest snippet :D.
However, I did run in a few snags that may or may not be issue worthy:
-
The link to the windows installer in the docs is still pointing to v1.0.6, I had to grab v.1.0.7 directly from github.
-
The snippet for writing the screenshot to file has this line
file = open(file_name, "w")
, but thenwrite()
fails because it tries to write a string. I had to pass the binary flag:file = open(file_name, "wb")
You're welcome to close this issue if those 2 points are resolved elsewhere.
Thanks for pointing out.. feel free to create a pull request :) Closing this as the actual issue is addressed.