是否可以使用cypress验证悬停文字? [英] Is it possible to verify a Hover text using cypress?

查看:130
本文介绍了是否可以使用cypress验证悬停文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是柏树和工具探索的新手。我想知道是否存在验证悬停的文本的选项。

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.

我想检查是否存储了悬停的文本,因此,可以将其分配给变量,并检查href是否具有正确的值。

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.

示例代码段:

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

因此,实际显示的文字为Mr.ABCD,但悬停在上方文本将是MR.ABCD EFGH。我想将MR.ABCD EFGH的整个文本存储到某个变量中,并使用href检查该文本是否相同。

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}`)

})
})

但是,此操作仅验证名称的第一部分。即名称为ABCD先生,但实际结果应为MR.ABCD EFGH。我想访问的部分位于data-original-title上,我不知道如何访问它。并且实际的href将为 https://worldmap.com/city/Mr.ABCDEFGH '

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'

注意:我知道我们可以使用[data-original-title = Mr.ABCD EFGH]访问data-original-title,但是这里的问题是名称是动态的,我们不能直接访问它。

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.

推荐答案

此问题将在赛普拉斯的将来版本中修复,但在 .click 不会立即发送所有鼠标悬停事件,包括 mouseover mouseenter mousemove

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')

这篇关于是否可以使用cypress验证悬停文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆