如何使用 Cypress 获取文件的源代码?
How can I get the source of a file using Cypress?
Selenium 有一个名为 getPageSource 的函数,可以获取页面的源代码。我正在寻找 Cypress 中的等效项。
我试过了
cy.get('html:root')
.eq(0)
.invoke('prop', 'outerHTML')
但是,它并不是真正的 return 页面来源。例如,源包含 ©
,但上面的 cypress 命令将其显示为 ©。我想查看页面的实际来源,如果我去服务器并在任何纯文本编辑器(如记事本)中打开文件,我会看到什么。
天真的答案是使用 string.replaceAll()
cy.get('html:root')
.eq(0)
.invoke('prop', 'outerHTML')
.then(pageSource => pageSource.replaceAll('©', '©'))
参考图表请参阅dev.w3.org/html5/html-author/charref。
但我感觉某处有一个转换函数可以执行任何和所有事件。
获取等效于“查看页面源代码”*
cy.request(my-url)
.its('body') // NB the response body, not the body of your page
.then(content => {
// send content to validator.w3.org
// you can probably cy.visit('validator.w3.org') and manipulate the
// validation page, pasting in content value as required
})
Selenium 有一个名为 getPageSource 的函数,可以获取页面的源代码。我正在寻找 Cypress 中的等效项。
我试过了
cy.get('html:root')
.eq(0)
.invoke('prop', 'outerHTML')
但是,它并不是真正的 return 页面来源。例如,源包含 ©
,但上面的 cypress 命令将其显示为 ©。我想查看页面的实际来源,如果我去服务器并在任何纯文本编辑器(如记事本)中打开文件,我会看到什么。
天真的答案是使用 string.replaceAll()
cy.get('html:root')
.eq(0)
.invoke('prop', 'outerHTML')
.then(pageSource => pageSource.replaceAll('©', '©'))
参考图表请参阅dev.w3.org/html5/html-author/charref。
但我感觉某处有一个转换函数可以执行任何和所有事件。
获取等效于“查看页面源代码”*
cy.request(my-url)
.its('body') // NB the response body, not the body of your page
.then(content => {
// send content to validator.w3.org
// you can probably cy.visit('validator.w3.org') and manipulate the
// validation page, pasting in content value as required
})