admin管理员组文章数量:1401134
I want to print the string value of a variable I find on a web page using testcafe console.log. I am trying to get the text value of an object I identify with a selector(frameSizetext below). The script is running and .contains() method verifies it contains the text I am checking for already but I would like to also print the text value to the console which would help to debug scripts more easily.
`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
The text I am looking for is currently being printed out as "[object Object]" see above. How do I print the String value of this object?
I want to print the string value of a variable I find on a web page using testcafe console.log. I am trying to get the text value of an object I identify with a selector(frameSizetext below). The script is running and .contains() method verifies it contains the text I am checking for already but I would like to also print the text value to the console which would help to debug scripts more easily.
`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
The text I am looking for is currently being printed out as "[object Object]" see above. How do I print the String value of this object?
Share Improve this question edited Dec 20, 2019 at 15:28 Alex Skorkin 4,2743 gold badges27 silver badges48 bronze badges asked Oct 15, 2018 at 11:59 Pat O'HaraPat O'Hara 671 silver badge3 bronze badges 02 Answers
Reset to default 4console.log("[DEBUG], Framesize is detailed as:", frameSizeText)
should do the trick.
To get a string representation of a plex object you can use JSON.stringify
function.
Did you try using await?
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);
})
本文标签: javascriptHow to print string value of a page object in TestcafeStack Overflow
版权声明:本文标题:javascript - How to print string value of a page object in Testcafe? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744302512a2599648.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论