javascript - 如何跟踪 Wikipedia 页面中以文本格式给出的 DOB 并断言一个 DOB 大于另一个使用 cypress 的 DOB?学习柏树
问题描述
这就是我正在做的事情:
- 访问此页面:https ://en.wikipedia.org/wiki/The_Beatles
- 点击第一个链接到 Paul McCartney 的维基百科页面
- 跟踪保罗麦卡特尼的出生日期
- 返回披头士乐队页面
- 点击约翰列侬维基百科页面的第一个链接
- 跟踪约翰列侬的出生日期
- 断言约翰列侬在保罗麦卡特尼之前出生
describe('iCONNECT Test Suite', function () {
it('Test Case 1', function () {
cy.visit('https://en.wikipedia.org/wiki/The_Beatles')
cy.get(':nth-child(8) > [href="/wiki/Paul_McCartney"]').click()
cy.get('.mw-parser-output > :nth-child(6)').contains('18 June 1942')
cy.go(-1)
cy.wait(7000)
cy.get(':nth-child(8) > [href="/wiki/John_Lennon"]').click()
cy.get('.mw-parser-output > :nth-child(6)').contains('9 October 1940')
expect(1940).to.be.lessThan(1942)
})
})
解决方案
你可以这样做:
describe('iCONNECT Test Suite', function () {
it('Test Case 1', function () {
cy.visit('https://en.wikipedia.org/wiki/The_Beatles')
cy.get('.infobox-data')
.find('li > [href="/wiki/Paul_McCartney"]', {timeout: 7000})
.click()
cy.get('.infobox-data', {timeout: 6000})
.eq(0)
.should('be.visible')
.invoke('text')
.should('include', '18 June 1942') //Assert the birth day for Paul McCartney
cy.get('.infobox-data')
.eq(0)
.find('span')
.invoke('text')
.then((text) => text.slice(2, 6))
.as('paulBirthYear') //Get Birth year for Paul McCartney
cy.go(-1)
cy.get('.infobox-data')
.find('li > [href="/wiki/John_Lennon"]', {timeout: 7000})
.click()
cy.get('.infobox-data', {timeout: 6000})
.eq(0)
.should('be.visible')
.invoke('text')
.should('include', '9 October 1940') //Assert the birth day for John Lennon
cy.get('.infobox-data')
.eq(0)
.find('span')
.invoke('text')
.then((text) => text.slice(1, 5))
.as('johnBirthYear') //Get Birth year for John Lennon
cy.get('@paulBirthYear').then((paulBirthYear) => {
cy.get('@johnBirthYear').then((johnBirthYear) => {
expect(+johnBirthYear).to.be.lessThan(+paulBirthYear) //Assert John Lennon is older than Paul McCartney
})
})
})
})
测试运行器执行:
推荐阅读
- node.js - How can get chat history of users in botpress?
- c++ - “初始化”到底是什么意思?
- python - 我编写了这段代码,用于将列表中的值插入 mysql 数据库,但出现编程错误
- node.js - 找不到模块“./client/Client”不和谐机器人错误
- java - java.lang.instrument.Instrumentation 没有给出预期的结果
- php - 无法从使用 PHP Simple DOM 标记
- pine-script - 如何使用内置“句点”变量?
- google-sheets-api - Google Sheet API - 如何仅获取更新的行
- powershell - 通过批处理脚本执行 PowerShell 时,我想存储该 PowerShell 的执行状态日志文件
- python - 将一列的行拆分为熊猫数据框中的不同列