Gaurav
Gaurav

Reputation: 141

testcafe - how to assert text contains in html body

I am using testcafe for api testing however our api requires login. Below is my code. I can see json response fine. But i am not sure how to assert on the page.

import { Selector } from 'testcafe';

import Page from './page';
// Page model
const page = new Page();
const url = 'https://myexample.com';

const elementWithIdOrClassName = Selector(value => {
  return document.getElementById(value) || document.getElementsByTagName(value);
});

fixture `Test`
    .page(url + '/talent/career')
    .beforeEach( async t => {
      await t
      .typeText(page.username, 'gvp50')
      .typeText(page.password, 'password')
      .click(page.login_button)
    });



// Tests
test('Text typing basics', async t => {
    await t
      .navigateTo(url+'/api/learner/learning_items')
      .expect(Selector('html')).contains('learning_items');
});

Testcafe just hangs after i run this code. I tried Selector('body') as well but it doesn't work.

Upvotes: 3

Views: 6673

Answers (2)

Meet
Meet

Reputation: 345

const cellcomparedata =await Selector('[role="gridcell"]').textContent;
console.log("cellcomparedata is",cellcomparedata);

either you can use this.

Upvotes: 0

Alex Skorkin
Alex Skorkin

Reputation: 4274

You need to specify what element property (state) you'd like to obtain (verify).

After you selected the entire 'html' element (Selector('html')), specify what property (state) you'd like to access (attributes, childNodes, style, size, etc.). See the DOM Node State topic to learn more.

It looks like you wanted to access the text content as follows:

.expect(Selector('html').textContent).contains('learning_items');

However, such selector usage is unlikely to be the cause of the hang as TestCafe will properly display a message about invalid selector usage. You might want to simplify your test and/or debug it to find what causes the hang.

Upvotes: 5

Related Questions