- Visual (UI) tests for the Analytics extension for the Visual Studio Code
There are two approaches how to test Analytics plugin in VS Code via UI:
- use Selenium + Web Driver because VS Code is based on Electron
- QA people know this approach a bit
- VS Code GUI is autogenerated, there are no IDs for tags etc.
- it really does not check what users see on their screen
- use PyAutoGUI library to match regions on screen, click on them etc.
- straightforward
- tests what users really see and can click on
- flaky, depends on actual rendering engine settings
-> Use an interface and add a separated layer between #1/#2 and actual tests
- Tests are written in Behave (BDD)
- Implementation of test steps use PyAutoGUI
- Available at https://github.com/fabric8-analytics/fabric8-analytics-common/tree/master/vscode-visual-tests
Feature: Visual Studio Code + the Analytics plugin basic functionality
Scenario: Check that the Analytics plugin can be found in the Marketplace
Given The PyAutoGUI library is initialized
And The screen resolution is at least 1024x768 pixels
When I start the Visual Studio Code
Then I should find Visual Studio Code instance
When I click on the extension icon on the activity bar
Then I should find the Search extension in Marketplace input box
When I search for Dependency Analytics plugin
And I select the plugin
Then I should find the OpenShift logo
And I should find the Dependency Analytics header
And I should find the Dependency Analytics title
And I should find the Plugin install button
When I start the installation by clicking on the Plugin install button
Then I should find the Reload and Uninstall buttons
And I should find the Reload button and Gear icon
When I close the Visual Studio Code
Then I should not find any Visual Studio Code instance
Feature: Visual Studio Code + the Analytics plugin basic functionality
Scenario: Check that the Analytics plugin can be found in the Marketplace
Given The PyAutoGUI library is initialized
And The screen resolution is at least 1024x768 pixels
# Start the Visual Studio Code
When I start the Visual Studio Code
Then I should find Visual Studio Code instance
When I look at the whole screen
# Find the Analytics extension
Then I should find the activity bar
And I should find the extension icon on the activity bar
When I click on that region
And I wait 2 seconds
And I look at the whole screen
Then I should find the Search extension in Marketplace input box
When I click on that region
And I type in Depencency Analytics
And I wait 2 seconds
And I look at the whole screen
Then I should find the Dependency Analytics info region
# Install the Analytics extension
When I click on that region
And I wait 2 seconds
And I look at the whole screen
Then I should find the Plugin install button
When I click on that region
And I move mouse cursor to the top left corner
And I wait 2 seconds
Then I should find the Reload and Uninstall buttons
And I should find the Reload button and Gear icon
# Close the Visual Studio Code
When I look at the whole screen
And I click on the File menu
And I click on the Exit menu entry
And I wait 2 seconds
Then I should not find any Visual Studio Code instance
It is possible to use the Litava
project [https://github.com/tisnik/litava] to perform fuzzy pattern matching in raster images.
Using this approach, it is possible to find regions in screenshot even when the GUI is distorted a bit (can be caused by various
reasons, for example by using the different font rendering engine).
When the Litava
project is enabled (see Setup), the pattern on the image is found by using the following algorithm:
- the internal algorithm implemented in
PyAutoGUI
is used to find the exact pattern - if the pattern is not found, then the
Litava
tool is called to find the region using the fuzzy search
- Inputs: a source image (usually screenshot), a pattern (image to be found in the source image)
- Source image pixel values are converted to floats & shifted by computed offset, so the sum of all pixels is zero
- Pattern image pixel values are converted to floats & shifted by computed offset, so the sum of all pixels is zero
- Autocorrelation is computed for the pattern
- Now the pattern is moved over the image in all possible combinations and correlation coefficient is computed for all those combinations
- Maximum value of correlation + pattern position are remembered
- If maximum correlation == autocorrelation, the exact pattern has been found
- If maximum correlation / autocorrelation >= 0.9 (90%) the tool report it as 'fuzzy found'
- Otherwise the results is that pattern can't be found
References: https://patents.justia.com/patent/9298598
- GNU C Compiler installed
- Stadard dev libraries installed (
libc
orlibc6
)
Just use the script:
./install_litava.sh
Set and export the environment variable USE_LITAVA
Error message: Xlib.error.DisplayConnectionError: Can't connect to display ":0.0": b'No protocol specified\n'
You can use the xhost
tool to control user access to X.
First run xhost +
which should disable ALL checks so the test can be started.
This solution is no secure, of course, so use it just for checking.
Better is to use:
xhost -
xhost +SI:localuser:$(you_username)
sudo dnf install python3-xlib