Is it possible to test Flutter applications using the Cypress framework instead of using the built-in testing components that Flutter provides? If so, what are the pros & cons of both for Flutter testing if I know Cypress well?
Yes, technically, it's possible.
Here's a spec that passes with the basic flutter counter app:
describe('Counter app', () => {
beforeEach(() => {
cy.visit('http://localhost:_example_port_/#/')
cy.get('flt-semantics-placeholder').click({force: true})
})
it('Increments on button press', ()=>{
cy.get(`[aria-label="0"]`)
cy.get(`[aria-label="Increment"]`).click()
cy.get(`[aria-label="1"]`)
})
})
To explain, if you enable semantics by clicking on the hidden 'flt-semantic-placeholder' element, flutter adds a semantics layer used by screen readers. Widgets with tooltips and text are automatically assigned aria-labels, which Cypress can use to find and click on elements. (You can get more control over these labels using a Semantics Widget.)
I found this worked for the canvas renderer, but it crashed when I tried to run multiple test cases in the same run. So, use the html renderer, ie run flutter for the test with something like:
flutter run -d chrome --web-renderer html --web-port 3443
Okay, so clicking a button is pretty straightforward. What about other interactions?
Inputing text into a field:
Pretty straightforward. See this example.
Simulating a scroll event:
In short, no solution yet. See this markdown.
Simulating drag and drop:
Not likely. See this markdown.
Now for the pros and cons...
Pros:
Cons:
See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With