Is it possible to verify a Hover text using cypress?

ⅰ亾dé卋堺 提交于 2020-06-17 04:15:31

问题


I am new to cypress and exploring the tool. I would like to know if there is an option to verify a hovered text.

This is my scenario, My data is dynamic and changes every second. Imagine a table with Column city and city in charge. The city of incharge is dynamic and changes every minute.

This is clickable, hovered and holds a link. When hovered over it shows the full name while on the button it has the first name alone. Also, the name changes more frequently and not constant so cannot use contains to check.

I want to check if we store the hovered text, so in this way, I can assign it to a variable and check if the href holds the correct value.

example snippet:

<a href="/City/incharge/Mr.A" data-toggle="tooltip" title="" data-original-title="Mr.ABCDEFGH" "MR.ABCD">
</a>

So the actual text displayed will be Mr.ABCD but the hovered text will be MR.ABCD EFGH. I want to store the whole text that is MR.ABCD EFGH to some variable and check that with href if it is same.

Part of cypress code which I tried:

it('Check click function on inchargename', () => {
let name = ''
cy.get('td').eq(1)
  .then(incharge => {
name = incharge.text()
cy.get('td').eq(1).click()
cy.url().should('eq',`https://worldmap.com/city/${name}`)

}) })

However, this verifies only the first part of the name. I.e. the name holds Mr.ABCD but the actual result should be MR.ABCD EFGH. The part I wanted to access lies on data-original-title and I dont know how to access that. and the actual href will be 'https://worldmap.com/city/Mr.ABCDEFGH'

Note: I know we can access data-original-title using [data-original-title="Mr.ABCD EFGH"] but here the problem is the name is dynamic and we can't access it directly.


回答1:


This will be fixed in a future version of Cypress, but at the moment a .click will not send all the mouse events for hovering, which includes mouseover, mouseenter, and mousemove

However you can simulate those events yourself with:

cy.get('td').eq(1).trigger('mouseover')


来源:https://stackoverflow.com/questions/55033029/is-it-possible-to-verify-a-hover-text-using-cypress

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!