question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: natural language query functions for links and form elements

See original GitHub issue

I’d like to see Cypress add natural language query functions for links and standard form elements.

One of the nicest things about the capybara API is that it has a few tricks that make selecting links and form elements (the element types an integration test will interact with most frequently) queryable with the same natural language text that users will see.

Here are a few examples from Capybara:

  • click_link('Link Text'), click_button('Button Text'), click_on('a link or a button')
  • fill_in('First Name', with: 'John')
  • check('A Checkbox'), uncheck('A Checkbox')

And so on. None of these matchers are particularly challenging to implement, but they can dramatically improve the UX of a browser automation API, especially to people in non-typical developer roles. Additionally, selecting on text can improve the durability of a test suite against subsequent implementation changes, since you’re coupling to text users can see and not markup.

This style has been found to have a few benefits over the years:

  • The intent of the test is more apparent, especially in cases where the markup is obtuse or unclear (and where making the markup cleaner is outside the control of the tester)
  • The test is less likely to break due to implementation changes that are unimportant to the user. If the label of a form element changes, however, that’s almost always meaningful to somebody, since it’s visible to the users. This has the effect of decreasing the occurrence of false negatives (tests that fail but for which nothing is broken)
  • It encourages better a11y, in particular for form elements, which sadly still often fail to have proper for & id attribute matching. If the test can select a form element correctly based on given label text, so can a screen reader

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
searlscommented, Jul 15, 2018

Okay, I just published cypress-capybara, which implements the three most relevant and useful Capybara finder methods for the purposes outlined in the opening issue.

I scanned the rest of the Capybara DSL but didn’t see anything else that’d provide much value that isn’t (a) already implemented in Cypress’s built-in API, or (b) wouldn’t undercut the chaining API in the way @brian-mann described earlier.

Would love if you’d add this to your docs! 💚

0reactions
patconcommented, Apr 27, 2022

For anyone reading along after, I just want to acknowledge that the philosophy espoused in the Cypress docs (using data-testid etc) is not the only philosophy, and some tools seem to have an opposite one. e.g., testing-library maintained by kentcdodds, used for react components https://kentcdodds.com/blog/making-your-ui-tests-resilient-to-change

so if you’re reading along feeling confused for feeling differently, you’re not alone – there are lots of different ways! Cypress just has opinions, like everyone 😃

EDIT: I do think the docs could do a better job of hinting at other philosophies, as I was hardcore data-testid for awhile (on blind faith in cypress docs) and am now realizing the wisdom of other ways, and kinda wondering why Cypress didn’t acknowledge this valid choice, and just kinda made it for me in the documentation 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Natural Language Query - Product Documentation | ServiceNow
Natural Language Query (NLQ) enables you to query the data in your instance by entering plain language requests into the user interface.
Read more >
Natural Language API Basics | Google Cloud
The Natural Language API provides a powerful set of tools for analyzing and parsing text through syntactic analysis. To perform syntactic analysis, use...
Read more >
Natural Language Queries - Microsoft Academic Services
This article describes how MAKES generates semantic interpretations of a natural language query that enable entities to be retrieved.
Read more >
What is Natural Language Processing? An Introduction to NLP
Research being done on natural language processing revolves around search, especially Enterprise search. This involves having users query data sets in the form...
Read more >
How Google uses NLP to better understand search queries ...
Learn the role that natural language processing plays in making Google search even more semantic and context-based. · What is natural language ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found