小编Gau*_*rav的帖子

testcafe - 如何断言包含在 html 正文中的文本

我正在使用 testcafe 进行 api 测试,但是我们的 api 需要登录。下面是我的代码。我可以很好地看到 json 响应。但我不确定如何在页面上断言。

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');
});
Run Code Online (Sandbox Code Playgroud)

运行此代码后,Testcafe 挂起。我也试过 Selector('body') 但它不起作用。

javascript automated-tests assert e2e-testing testcafe

3
推荐指数
1
解决办法
4645
查看次数