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 0
Add a ment  | 

2 Answers 2

Reset to default 4
console.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