-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Base64 encoded screenshot and additional screenshot creation from XPATH element #194
Conversation
- Add xpath to ValueContainer - Add additional actions for element and Base64 format - add automation to init - Add capture function for base64 using MemoryStream - Add optional xpath to both capture functions
… by XPATh - Adjust 'take screenshot' keyword with optional base64 boolean - Add keyword 'take screenshot from element' for capturing element with xpath
- Fix initialization error due to missing automation parameter - fix line too long - Fix build errors, add ignore for ImageFormat - Remove ScreenshotType - Remove unused Optional import
Please update Changelog file to upcoming unreleased new keywords. |
Is it possible to extend some Screenshots tests under ATests to see if log are resolved? (Optional would be nice) |
Probably a switch would be nice to decide default behavior from screenshots to create files or base64 like Set Screenshot Log Mode (Base64 | File) |
I'll get to address the changes right away, please keep in mind that I noticed that my commits made were using the wrong user configuration by mistake. It should be visible in a moment. |
…apture based on mode
… with optional XPATH, Add set mode keyword
…rom Screenshot module
errors/warnings, adjust docstrings
if identifier: | ||
module = self._container.create_or_get_module() | ||
element = module.get_element(identifier, None, msg) | ||
image_var = self._screenshots.execute_action(Screenshot.Action.CAPTURE_ELEMENT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will always create a screenshot, even if the element could not be found. If the element is not found, the whole screen is captured like in default.
Might be better if the screenshot will not get created if the element was not found?
I'm done from my point of view, please have another look @Nepitwin |
It triggers me hard that they are not working. I should be better at this ;D |
Feel free this is the challenge of testing to execute them correctly on a testing system 📦 |
@Nepitwin I do need some help on this last test case. I do not know what runs differently on appveyor. When I run the test locally, it creates the screenshot file and finds it correctly, but on appveyor it doesn't. I changed the format to use ${TEST_NAME} instead of hardcoding, but that didn't change results. By the way, if you also have some suggestions on further necessary test cases, I can add those as well, but I believe with the feature being so small, the ones created should suffice.
Attached is my local log file of the successful execution of that test case. I did not run it via the Execution log
C:; cd 'C:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\robotframework-flaui\atests'; & 'C:\Users\RINI\AppData\Local\Temp\rf-ls-run\run_env_00_38e9sp6_.bat' '-u' 'c:\Users\RINI\.vscode\extensions\robocorp.robotframework-lsp-1.12.0\src\robotframework_debug_adapter\run_robot__main__.py' '--port' '7111' '--no-debug' '--listener=robotframework_debug_adapter.events_listener.EventsListenerV2' '--listener=robotframework_debug_adapter.events_listener.EventsListenerV3' '--outputdir' 'C:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\robotframework-flaui/result/tmp' '--pythonpath' 'c:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\robotframework-flaui/.venv/lib/python3.8/site-packages' '--pythonpath' 'c:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\robotframework-flaui/atests' '--variable' 'UIA:UIA3' '--prerunmodifier=robotframework_debug_adapter.prerun_modifiers.FilteringTestsSuiteVisitor' 'c:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\robotframework-flaui\atests\Screenshot.robot' s\x5cRINI\x5c#Entwicklung_TechNICK\x5c0_Git_Stash\x5crobotframework-flaui\x5catests\x5cScreenshot.robot'
==============================================================================
Screenshot :: Test suite for screenshot keywords. XPath not found error han...
==============================================================================
Take Screenshot Of Window | PASS |
------------------------------------------------------------------------------
Screenshot :: Test suite for screenshot keywords. XPath not found ... | PASS |
1 test, 1 passed, 0 failed
==============================================================================
Output: C:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\robotframework-flaui\result\tmp\output.xml
Log: C:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\robotframework-flaui\result\tmp\log.html
Report: C:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\robotframework-flaui\result\tmp\report.html
|
It would be better to always have it in the teardown, as currently it will not be executed on failure for the test that has to also stop the application. I'll add a keyword I think to combine the two. |
Run a case in a robotfile, you can execute command like .\keen.bat install cd .\atests\ python -m robot --name "UIA3" --variable UIA:UIA3 --outputdir ../result/uia3 --test "Take Screenshot Of Window" .\Screenshot.robot --test is the casename you edit in robotfile |
There seems to be an unrelated problem on AppVeyor. The last commit had all tests successful, but the script had a failure somewhere. See console log for details on AppVeyor. ...
5 File(s) copied
Command exited with code 28
$wc = New-Object 'System.Net.WebClient'
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\result\xunit.xml)) |
I debuged that, job "call:pylint" in keen.bat maybe retrurn the %ERRORLEVEL%=28, so the %result%=28 and it donnot change in left jobs, so keen.bat ended with EXIT /B %result%=28. EXIT code not be 0, it is marked as a Failure. I add the attachment debug-flaui.zip with debugcode and EXIT code with 0 EXIT code with 28 in log, job "call:pylint" and job "tidy" print like |
@JimRevolutionist Alright, applied the changes to I also adjusted all screenshot test cases with a proper teardown keyword for resetting to default state, which should also run on error to not influence other test cases. I also ran the screenshot suite beforehand, should all be green. Fingers crossed, we should be good to go for merge after this. Do you want me to create issues for the keen.bat so we can reference it in the PR? I should also update Changelog to reflect the minor adjustments made. |
optmize keen.bat should be an Independent issue,pr separate from screenshot issue,pr. We should not put keenbat commits into screenshot pr. |
Oh. I'll revert the change then. |
Oh yes i forgot to update all related verifiction from pylint to see in error logs from appveyor. Sorry for this mistake. If you got already an solution you can create a new pr from it. Because all issues can be seen afterwards in artifact files to guarantee python code style guides and robotframework has to be fixxed. @JimRevolutionist Sometimes api call failed from appveyor --> Command exited with code 28 It's not nice if a run was failed but for this case i would rerun the testcase from my perspective. Sorry for late response. |
@JimRevolutionist By actuall solution error code is handled but appveyor does not upload zip file :( ERRORLEVEL after call xcopy uia3 is: 0 In zip file from artifact the reasons from pylint is described what to fix. |
But it can be seen in logs ************* Module src.FlaUILibrary.flaui.module.screenshot |
Verification locally can be done with keen.bat pylint But you should first install new package with keen.bat install |
Alright, after all that… I think we finally have a valid one. I fixed all the pylint errors, so appveyor should also give green light if my luck hasn't forsaken me. Unfortunately, due to my bad behavior of pushing too much, it will take a bit until it gets to the last commit. |
… XPATH element (GDATASoftwareAG#194) * Update .gitignore, add VSCode directory and .venv * Add base64 logging function to robotlog * Change screenshot module behaviour to accomodate base64 image conversion - Add xpath to ValueContainer - Add additional actions for element and Base64 format - add automation to init - Add capture function for base64 using MemoryStream - Add optional xpath to both capture functions * Change screenshot keywords to use optional base64 and allow capturing by XPATh - Adjust 'take screenshot' keyword with optional base64 boolean - Add keyword 'take screenshot from element' for capturing element with xpath * Fix multiple build errors - Fix initialization error due to missing automation parameter - fix line too long - Fix build errors, add ignore for ImageFormat - Remove ScreenshotType - Remove unused Optional import * Add screenshot mode, Adjust parameter to retrieved element, execute capture based on mode * Add AutomationInterfaceContainer, Combine capture into single keyword with optional XPATH, Add set mode keyword * Remove unused imports * Change example text * Add simple testcases for new screenshot keyword behaviour * Fix init to use container for screenshot keywords, remove container from Screenshot module * Fix ScreenshotMode not defined (missing self) * add getter for screenshot mode, Fix linting errors/warnings, adjust docstrings * Update changelog * Fix missing default value for element in _capture_base64 * Improve screenshot testcases for base64 mode and xpath * Fix argument name typo * Tiny fix of take_screenshot docstring to explain identifier * Fix AttributeError due to improper key access * Add truthy checks in base64 screenshot tests before checking length * Remove redundant None, explicit msg argument for get_element * Add return statement to _capture function * Fix check for None (wrong keyword used) * Fix element assigned to wrong argument for screenshot action * Remove redundant screenshot logging in keyword * Fix filename for screenshot in test * Fix Screenshot.robot (reorder test cases, deactivate Base64) * Update Screenshot.robot (Minor format adjustment) * Add getter keyword for screenshot log mode * Add teardown mechanism with default state for all screenshot cases * Add missing PID for reset to properly close applications * Update .gitignore for custom keen.bat file in development * Fix pylint errors to get them good grades * Fix missing trailing blank line * Fix via robotidy
This PR adds another logging function, to directly embed screenshots as base64 encoded strings in the output log.
It also expands the screenshot functionality to allow for screenshot creation based on a provided element XPATH.
It will create a screenshot based on that element, so a screenshot of a window will contain the whole window, a screenshot of a button, will only contain that button.
Fixes #192 and fixes #193