Cypress operates insides a browser, it's internally using NodeJS.
That's a key difference with tools such as Selenium.
**From the Cypress documentation:**
> But what this also means is that your test code **is being evaluated inside the browser**. Test code is not evaluated in Node, or any other server side language. The **only** language we will ever support is the language of the web: JavaScript.
Good starting points with Cypress are the [Getting started guide](https://docs.cypress.io/guides/getting-started/writing-your-first-test.html#Write-your-first-test), and the [Trade-offs](https://docs.cypress.io/guides/references/trade-offs.html#Permanent-trade-offs-1)
The general workflow of a Cypress test is to
- Start a browser (yarn run cypress open)
- Visit a URL
- Trigger user actions
- Assert that the DOM contains expected texts and elements using selectors
The first noticeable thing about a test is the description (`Ensure cells are blanked down`), which describes what the test is doing.
Lines usually starts with `cy.something...`, which is the main way to interact with the Cypress framework.
A few examples:
-`cy.get('a.my-class')` will retrieve the `<a class="my-class" />` element
-`cy.click()` will click on the element
- eventually, `cy.should()` will perform an assertion, for example that the element contains an expected text with `cy.should('to.contains', 'my text')`
On top of that, OpenRefine contributors have added some functions for common OpenRefine interactions.
For example
-`cy.loadAndVisitProject` will create a fresh project in OpenRefine
-`cy.assertCellEquals` will ensure that a cell contains a given value
See below on the dedicated section 'Testing utilities'
Cypress execution can be configured with environment variables, they can be declared at the OS level, or when running the test
Available variables are
- OPENREFINE_URL, determine on which scheme://url:port to access OpenRefine, default to http://localhost:333
Cypress contains [exaustive documentation](https://docs.cypress.io/guides/guides/environment-variables.html#Setting) about configuration, but here are two simple ways to configure the execution of the tests:
Tests generally ensure application behavior by making assertions against the DOM, to ensure specific texts or css attributes are present in the document body.
Visual testing, on the contrary, is a way to test applications by comparing images.
A reference screenshot is taken the first time the test runs, and subsequent runs will compare a new screenshot against the reference, at the pixel level.
Here is an [introduction to visual testing by Cypress](https://docs.cypress.io/plugins/directory#visual-testing).
In some cases, we are using visual testing.
We are using [Cypress Image Snapshot](https://github.com/jaredpalmer/cypress-image-snapshot)
Identified cases are so far:
- testing images created by OpenRefine backend (scatterplots for example)
Reference screenshots (Called snapshots), are stored in /cypress/snapshots.
And a snapshot can be taken for the whole page, or just a single part of the page.