purple-hairdresser-80317
05/17/2023, 1:19 AMCypress.Commands.addQuery('findPrimeNgDialog', function(header) {
return subject => subject.findByRole('dialog')
})
I have to use the subject, as I cannot just return subject => cy.findByRole('dialog'). So, when I try to call the query, similar to cy.get() , like this cy.getPrimeNgDialog('HeaderText').as('Dialog'), I expected it to work like get(), however subject is undefined. However calling it with cy.get('body').getPrimeNgDialog('HeaderText').as('Dialog') results in getting a jquery.fn.init object, but I don't really know what to do with that object. I thought I could simply chain the queries together, but it does not work.
Sadly, I haven't found much information or examples about addQuery, therefore I really don't know what to try next. I'm fairly certain I misunderstood how addQuery is supposed to work, can someone explain this to me, or point to a ressource where I could learn more about that?
The only thing I got to work is
Cypress.Commands.addQuery('findPrimeNgDialog', function(header) {
const getFn = cy.now('contains', '[role="dialog"]', header) as any
return subject => getFn(subject) // However not chainable inside here
})
But since cy.now() is not chainable, therefore I have to use contains instead of get to be able to search for the text inside. And at this point i'm questioning myself, if what i'm trying is actually meaningful.gray-kilobyte-89541
05/17/2023, 10:36 AMpurple-hairdresser-80317
05/17/2023, 1:38 PMcy or another element to find elements. Still don't know hab to use jquery.fn.init to search for somethinggray-kilobyte-89541
05/17/2023, 2:42 PMgray-kilobyte-89541
05/17/2023, 2:42 PMpurple-hairdresser-80317
05/17/2023, 2:43 PMgray-kilobyte-89541
05/17/2023, 2:45 PMcy.contains but you could use jQuery :contains selector Here I am showing Cy commands, but you can simply use jQuery there https://glebbahmutov.com/cypress-examples/commands/querying.html#find-text-with-contains-selectorpurple-hairdresser-80317
05/17/2023, 2:51 PMcy.now since I cannot use cy.get or subject.get inside the inner function. But also I cannot chain it from another element?gray-kilobyte-89541
05/17/2023, 3:38 PMpurple-hairdresser-80317
05/17/2023, 3:51 PMpurple-hairdresser-80317
05/17/2023, 3:53 PM