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.

find function lacks options parameter

See original GitHub issue

Current behavior

It’s well written here that the find function has 2 arguments: https://docs.cypress.io/api/commands/find#Arguments But in my case, the function has only one argument (the selector).

I am trying to use the timeout functionality with the find function but it does not wait for the timeout.

Desired behavior

I expect that the find function accepts the second argument as described in the documentation and similar to the get function.

Test code to reproduce

body.find('.find-this-tag', { timeout: 10000 })

Cypress Version

9.5.2

Other

Thank you!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
emilyrohrboughcommented, Mar 22, 2022

Ah I see! Thanks for providing the example you were working with.

cy.get() will yield the DOM element(s) found, which can be returned as an JQuery element. In the example you provided, you are trying to use JQuery’s find method instead of the .find() Cypress command. I suggest updating your test to be something like this:

const selector = '.item-that-loads-after-http-request-finishes'

cy.visit(Cypress.config().baseUrl + '/some-url', { timeout: 100000 })
    .get('body')
    .find(selector, { timeout: 5000 })

This will look for you selector for the given timeout and if it does not exist your test will fail.

If you are trying to mitigate the test failures, you can listen to the fail Cypress event to determine the best way to handle this, however we do not necessarily recommend this approach beyond debugging. Docs for catching test failures.

Give it a shot! However I do think this issue can be closed.

0reactions
directcuteocommented, Mar 22, 2022

This is what I try to achieve: I have a non-deterministic case for my application and I want to test a specific part of the application only in a certain case. To achieve this I use the find function. As I said, the problem is that the function doesn’t wait for the element to be shown as the timeout option is provided but it yields the result instantly (which ofc is that it doesn’t exist because it depends on other parts of the app).

cy.visit(Cypress.config().baseUrl + '/some-url', { timeout: 100000 })
    .get('body')
    .then((body) => {
      const selector = '.item-that-loads-after-http-request-finishes'
      if (body.find(selector, { timeout: 5000 }).length > 0) {
        console.log('Test running');
        // test body
      } else {
        console.log('Test is not running');
      }
    });

If I go to the method’s declaration, I will be taken to the same definition as the functionality is: one parameter function

JQuery.d.ts - line 4136 find(selector_element: JQuery.Selector | Element | JQuery): this;

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get function parameter names/values dynamically?
The following function will return an array of the parameter names of any function passed in. var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?
Read more >
Using Python Optional Arguments When Defining Functions
In this section, you'll learn how to define a function that takes an optional argument. Functions with optional arguments offer more flexibility in...
Read more >
about Functions Advanced Parameters - PowerShell
If a function has no positional parameters, PowerShell assigns positions to each parameter based on the order the parameters are declared.
Read more >
Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >
How To Use ES6 Arguments And Parameters
This function expects two arguments, but when it is called without arguments, it will use the default values. Inside the function, missing ...
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