0
votes

I am trying to perform a search for places in a search text field. While typing the place name, the system will display autocomplete of the places under the search field. I have written the test using trigger mousedown in cypress to grab the autocomplete items.

 describe('Search for places', function() {
 it.only('Verify the search is working fine', function() {  
 cy.visit('url')
 cy.get('#search-button').click();
 cy.get('input[type="text"]').type("Salis");
 //cy.get('input[placeholder="Start typing a suburb, city, station or uni"]').parents('.form-container').find('div').find('div').find('input').type("Salis");
 cy.contains('span', 'bury, Brisbane').click();
 //cy.get('.input-autocomplete').find('div.row').eq(0).click(); 
 cy.get('div:contains(" Flatmates")').parents('.search-modes').find('div').find('div').contains(" Flatmates").click();
 cy.get('a:contains("+ Advanced filters")').parents('.show-advanced-wrapper').find('p').find('a').click();
 cy.get('#search-submit > div').contains("Search Flatmates").click();
 cy.get('.section-heading > div > h1').invoke('text').then((text)=>{
    const stext = text;
    expect(stext).to.equal('Salisbury Housemates & Roommates');
 })
  Cypress.on('uncaught:exception', (err, runnable) => {
    // returning false here prevents Cypress from
    // failing the test
   return false
    })
  })

 })

The test runs successfully in Cypress test runner (UI). But while running from the command line, it throws CypressError: Timed out retrying: Expected to find element: '.input-autocomplete', but never found it.

While inspecting the html of the autocomplete item, it disappears the autocomplete items, so unable to get the correcthtml tags. Any idea what could be the reason for that error? Or any other stable way to get the autocomplete items.

enter image description here

enter image description here

Added the html where cypress test fails while running from command line, see the screen shot below highlighted in red

enter image description here

enter image description here

enter image description here

1
Could you send html from moment of assertion fail?Przemyslaw Jan Beigert
@PrzemyslawPietrzak : Added the screenshot where the cypress test failssoccerway
Please share the complete test, screenshots are useful but not enough to try and reproduce the problem.user9161752
@HiramK.Hackenbacker Full test added, please have a looksoccerway
Cheers, I'll take a look.user9161752

1 Answers

0
votes

I can't explain the difference between the results from cypress:open and cypress:run (at a guess it's memory related), but there's a few things wrong with the bit of the test you have shown.

First off, show the whole test not just one line - you make it really hard to help by showing fragmentary code.

.trigger('mousedown',{ which: 1 }) followed by .click() is redundant. Use one method or the other. click() is much better for selecting from a list.

Given the latest info, I would go for clicking the specific text content, assuming that the autocomplete list always comes up with the same suggestion for entry of 'Salis'.

cy.get('input').type('Salis');  // How do you type 'Salis'?
cy.contains('span', 'bury, Brisbane').click();