Javascript 如何在Testcafe中打印页面对象的字符串值?
我想使用testcafe console.log打印在网页上找到的变量的字符串值。我试图获取我用选择器标识的对象的文本值(下面是frameSizetext)。脚本正在运行,.contains()方法验证它是否包含我正在检查的文本,但我还希望将文本值打印到控制台,这将有助于更轻松地调试脚本Javascript 如何在Testcafe中打印页面对象的字符串值?,javascript,testing,automated-tests,console.log,testcafe,Javascript,Testing,Automated Tests,Console.log,Testcafe,我想使用testcafe console.log打印在网页上找到的变量的字符串值。我试图获取我用选择器标识的对象的文本值(下面是frameSizetext)。脚本正在运行,.contains()方法验证它是否包含我正在检查的文本,但我还希望将文本值打印到控制台,这将有助于更轻松地调试脚本 `test('Test ==> Check size details are listed for article ', async t => { const form = main.sear
`test('Test ==> Check size details are listed for article ', async t
=> {
const form = main.searchForm
const list = main.sunglassesList
const firstRow = list.getRowByIndex(0)
const articlesList = main.articlesList
const frameSizeText = articlesList.frameSize.innerText
await t
.wait(1000)
.typeText(form.searchField, '44444')
.click(form.submitButton)
.expect(main.sunglassesList.list.innerText)
.contains('SKODA Bar')
.click(firstRow.element)
.expect(frameSizeText, 'Text matches ' +frameSizeText)
.contains('44/22-144', 'checking framesize text')
console.log("[DEBUG], Framesize is detailed as:"
+frameSizeText.toString())
})`
✓ Test ==> Check frame color is detailed for article
[DEBUG], Framesize is detailed as:[object Object]
✓ Test ==> Check size details are listed for article
我正在寻找的文本目前打印为“[object]”,见上文。如何打印此对象的字符串值
console.log("[DEBUG], Framesize is detailed as:", frameSizeText)
我们应该做到这一点
要获取复杂对象的字符串表示,可以使用
JSON.stringify
函数。是否尝试使用wait
fixture `Sample Test`
.page `https://devexpress.github.io/testcafe/example/`
test('Sample test', async t => {
await t
const sometext = await Selector('#main-form > div > div.row > div.column.col-1 > fieldset:nth-child(1) > legend').innerText;
console.log('sometext -- ' + sometext);
})