Cypress_ 单击元素直到找不到文本值
Cypress_ Clicking an element until you don't find a text value
我是赛普拉斯的新手。有一个功能可以检查在日历中创建的一些事件
查看。
如果我选择了每月活动,那么我将在日历中获得 12 个活动
(即,#table span.fc-title 中包含文本“my event”的计数将为 12。
每次我需要单击日历中的下一个按钮以转到下个月视图)。
我希望在 cypress 中编写一个方法来验证此功能。
逻辑是这样的:
文本“我的活动”在当月是否可见(重复 12 次){
If yes, add 1 to the constant count and click on the next button and navigate to the next month and do the step1
If the text is not found, exit the loop.}
我刚写了下面的代码。但任何人都可以请审查这个和
帮我完成这个?我想循环直到找不到文本“我的事件”
常量计数=1;
const i = 12;
cy.get('#table span.tc-title')
.each(($span, i) => {
const text = Cypress.$($span).text()
if (text.includes('my event')) {
const count= count+1
cy.get('#table button.tc-next-button').click
//if the text is not there I need to exit the loop;
// I need the value of the count of events too;
return false;
}
})
我自己找到了一个可行的解决方案..所以也为其他人发布代码结构:
for (let i=0; i < 12; i++){
const monthCount = parseInt(12 - monthNum); // This is to find the current
month and navigate through
the remaining months in the current year
for (let i=0; i < monthCount; i++){
// You can use invoke('text') to get the desired text
cy.get(#table).find('span-title').invoke('text')
.then((text) => {
if (text.includes('My events')) {
cy.get('#table button.next-button').should('be.visible').click();
cy.wait(2000);
cy.log(i);
}
})
}
}
我是赛普拉斯的新手。有一个功能可以检查在日历中创建的一些事件 查看。
如果我选择了每月活动,那么我将在日历中获得 12 个活动 (即,#table span.fc-title 中包含文本“my event”的计数将为 12。 每次我需要单击日历中的下一个按钮以转到下个月视图)。
我希望在 cypress 中编写一个方法来验证此功能。
逻辑是这样的:
文本“我的活动”在当月是否可见(重复 12 次){
If yes, add 1 to the constant count and click on the next button and navigate to the next month and do the step1
If the text is not found, exit the loop.}
我刚写了下面的代码。但任何人都可以请审查这个和 帮我完成这个?我想循环直到找不到文本“我的事件”
常量计数=1; const i = 12;
cy.get('#table span.tc-title')
.each(($span, i) => {
const text = Cypress.$($span).text()
if (text.includes('my event')) {
const count= count+1
cy.get('#table button.tc-next-button').click
//if the text is not there I need to exit the loop;
// I need the value of the count of events too;
return false;
}
})
我自己找到了一个可行的解决方案..所以也为其他人发布代码结构:
for (let i=0; i < 12; i++){
const monthCount = parseInt(12 - monthNum); // This is to find the current
month and navigate through
the remaining months in the current year
for (let i=0; i < monthCount; i++){
// You can use invoke('text') to get the desired text
cy.get(#table).find('span-title').invoke('text')
.then((text) => {
if (text.includes('My events')) {
cy.get('#table button.next-button').should('be.visible').click();
cy.wait(2000);
cy.log(i);
}
})
}
}