Assuming you have created a virtual environment (for Python 3.7),
installed the requirements.txt dependencies, and activated the virtual environment:
$ python uitests download
$ python uitests install
$ python uitests test- These are a set of UI tests for the Python Extension in VSC.
- The UI is driven using the selenium webdriver.
- BDD is used to create the tests using Behave.
Here are the steps involved in running the tests:
- Setup environment:
- Download a completely fresh version of VS Code.
- Identify the version of Electron that VS Code is built upon.
- Download Chrome Driver corresponding to the version of Electron used.
- When running tests, the
chrome driverneeds to be in the current path.
- When running tests, the
- Use selenium webdriver to drive the VSC UI.
- Create a folder named
.vsccode-testwith the following sub-directories:
- When launching VSC, we will launch it as a completely stand alone version of VSC.
- I.e. even if it is installed on the current machine, we'll download and launch a new instance.
- This new instance will not interfere with currently installed version of VSC.
- All user settings, etc will be in a separate directory (see
userfolder). - VSC will not have any extensions (see
extensionsfolder).
- Automate VSC UI
- Launch VSC using the Chrome Driver
- Use selenium webdriver to drive the VSC UI.
- The tests are written and executed using Behave.
- Workspace folder/files
- Each feature can have its own set of files in the form of a github repo.
- Just add a tag with the path of the github repo url to the
feature. - When starting the tests for a feature, the repo is downloaded into
workspace folder. - At the begining of every scenario, the workspace folder is reset.
- This ensures each scenario starts with a clean workspace folder.
- Reports
- Test results are stored in the
reportsdirectory - These
json(cucumber format) report files are converted into HTML using annpmscript cucumber-html-reporter.
- Test results are stored in the
- 99% of the code is written in
Python. - Downloading of
chrome driverand generatinghtml reportsis done innode.js(using pre-existingnpmpackages). - The tests are written using Behave in
Python. GitHubrepos are used to provide the files to be used for testing in a workspace folder.- The reports (
cucumber format) are converted into HTML using annpmscript cucumber-html-reporter.
- If using the
node.jsscripts from VSC itself, most of the following caveats do not apply. However as we're using Python, hence there are a few drawbacks. - VSC UI must be a top level window for elements to receive focus. Hence when running tests, do not do anything else.
- Screenshots are generally embedded into the HTML report, however as the number of tests grow so would the size of the generated
jsonand resultanthtmlfile.- If the size is too large then consider storing the
screenshotsas external files (see--embed-screenshotsCLI arg).
- If the size is too large then consider storing the
- Reloading VSC will reset the connection (
driverconnection).- Hence reloading is basically performed by re-starting VSC.
- As reloading of VSC is not a cheap operation, resettting workspaces is slow.
- Current approach is to
cloneagit repodirectly into the workspace folder and usegit resetfor ever scenario. - Note: Deleting workspace folder is not an option, as this would result in VSC loosing the workspace folder (things go south from there).
- Current approach is to
chrome driveronly supports arguments that begin with--. Hence arguments passed to VSC are limited to those that start with--.Terminaloutput cannot be retrieved using thedriver. Hence output from terminal cannot be inspected.- Sending characters to an input is slow, the
selenium driverseems to send text one character at a time. Hence tests are slow. Behavedoes not generate reports that comply with thecucumber jsonreport format. Hence the custom formatter inreport.py.- Using a
cucumber jsonreport format allows us to use existing tools to generate other HTML reports out of the rawjsonfiles.
- Using a
- Sending keyboard commands to VSC is currently not possible (not known).
Selenium drivercan only send keyboard commands to a specifichtml element.- But kyeboard commands such as
ctrl+pare to be sent to the main window, and this isn't possible/not known. - Fortunately almost everything in VSC can be driven through commands in the
command palette.- Hence, we have an extension that opens the
command palette, from there, we useselenium driverto select commands. - This same extension is used to
activatethePython extension. - This extension is referred to as the
bootstrap extension.
- Hence, we have an extension that opens the
- The folder
.vsccode-testin the root directory is where VSC is downloaded, workspace files created, etc.extensionsThis is where the extensions get installed for the instance of VSC used for testing.reportsLocation where generated reports are stored.screenshotsLocation where screenshots are stored.stableLoaction where stable version of VSC is downloaded and stored.insidersLoaction where insiders version of VSC is downloaded and stored.userLoaction where user information related to VSC is stored.workspace folderWorkspace folder opened in VSC (this is where files used for smoke tests will be stored).
uitests/tests/bootstrapThis is where the source for the bootstrap extension is stored.uitests/tests/featuresLocation where allBDD featuresare stored.uitests/tests/stepsLocation where allBDD stepsare defined.uitests/tests/jsLocation with helperjsfiles (download chrome driver and generate html reports).uitests/tests/vscodeContains all modules related tovscode(driving the UI, downloading, starting, etc).environment.pyenviroymentfile forBehave.
- Use the debug configuration
Behave Smoke Testsfor debugging. - In order to pass custom arguments to
Behave, refer to theCLI(passbehavespecific args after--inpython uitests test).