Home > OS >  How do test the title is showing in full length and not displaying with a dotted line with cypress?
How do test the title is showing in full length and not displaying with a dotted line with cypress?

Time:04-04

I am new to working with cypress. I want to test the title text with any length is showing completely with full length and not dotted. I tested the title like below but still, I do not know how to check if the title with long length is displaying with dotted or not!! Thank you for any help.

cy.get(selectors.Content)   
  .find(selectors.dataComponent('title'))     
  .should('be.visible')     
  .and('not.be.empty')

CodePudding user response:

If you want to test that there is no ellipsis, try

cy.get(selectors.Content)    
  .find(selectors.dataComponent('title'))      
  .should('be.visible')      
  .and('not.be.empty')  

cy.get(selectors.Content)    
  .find(selectors.dataComponent('title'))      
  .invoke('text')
  .should('not.contain', '...')

Or more strict,

cy.get(selectors.Content)    
  .find(selectors.dataComponent('title'))      
  .invoke('text')
  .should(title => expect(title.endsWith('...')).to.eq(false))

CodePudding user response:

If you know the full length,

cy.get(selectors.Content)    
  .find(selectors.dataComponent('title'))      
  .invoke('text')
  .should('have.length', 20)
  • Related