小编Ale*_*kin的帖子

Testcafe how to read json response and pick first item and pass it to selector

Read JSON response

1) When I visit this URL 'http:example.com/fruits', it hits an endpoint 'http:example.com/v1/collections/fruits' and I see JSON in the browser network response:

{
   "total":3,
   "page":1,
   "pageSize":24,
   "rows":[
      {
         "id":19,
         "title":"Apple"

      },
      {
         "id":21,
         "title":"Grape",

      },
      {
         "id":6,
         "title":"Orange",

      },

   ]
}
Run Code Online (Sandbox Code Playgroud)

2) I want to pick up the first title - Apple and pass it to a selector and click on it

javascript json automated-tests e2e-testing testcafe

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

如何使用TestCafe确定元素属性是否存在?

我正在使用TestCafe,并想确定checkbox元素是否存在。在HTML元素中,如果该复选框已被选中,则该属性checked存在,否则不存在。如何确定使用TestCafe?

我使用了TestCafe中可用的功能- .hasAttribute('checked')但返回的是undefined

选中此复选框时,以下是HTML代码:

<input class="jss1523" tabindex="-1" type="checkbox" data-indeterminate="false" value checked>

取消选中此复选框时,这是HTML代码:

<input class="jss1523" tabindex="-1" type="checkbox" data-indeterminate="false" value>

如何使用TestCafe解决此问题?

automated-tests css-selectors e2e-testing testcafe

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

如何仅指定具有特定元标记的测试

我有一个使用元标记的测试套件,我正在尝试运行特定的测试。

我尝试使用以下方法:

  .filter((fixturePath, fixtureName, testMeta) => {
    return testMeta.smoke == 'true';
  })
Run Code Online (Sandbox Code Playgroud)

跑步者.ts

const createTestCafe = require('testcafe'); let testcafe = null; createTestCafe('localhost', 1337, 1338) .then((tc) => { testcafe = tc; const runner = testcafe.createRunner(); return runner .src(['tests/specs/**/*.spec.ts']) .filter((fixturePath, fixtureName, testMeta) => { return testMeta.smoke == 'true'; }) .browsers(['chrome']) .reporter([ 'list' ]) .run(); }) .then((failedCount) => { console.log('Tests failed: ' + failedCount); testcafe.close(); });

示例测试

test('Login with correct credentials', async (t) => { await LoginPage.login(data.users.userPrivate.username, data.users.userPrivate.password); await t.expect(Helper.getLocation()).contains(endpoints.personalAreaOverview); }).meta('regression', 'true').meta('smoke', 'true'); …

testing automated-tests node.js typescript testcafe

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

如何获得testCafe退出代码

我在通过黄瓜运行Testcafe时遇到问题。无论出于何种原因,当我通过黄瓜运行testCafe时,即使测试失败,该过程也始终会以退出代码0退出。

如果我通过黄瓜来操纵木偶戏,我不会遇到这个问题。我认为这种行为是由于我在我的钩子文件中设置了东西的方式造成的,在该文件中我没有正确解释测试咖啡馆出口代码。

在我的hooks文件中,我将在我的Before钩子中创建一个testCafe运行器,然后在我的after钩子中将其关闭。

我想知道我可以使用什么命令来获取TestCafe退出代码,而我却找不到任何信息。

例如,退出代码是从close函数返回的还是什么?

testing automated-tests exit-code e2e-testing testcafe

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

转到上一页的“ alt + left”不适用于testcafe,但可以手动正常运行

我正在尝试TestCafe使用以下代码从现有页面返回上一页:

await t.pressKey('alt+left');
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用。页面没有变化。但是,当我在浏览器中进行验证时,手动进行似乎可以正常工作。

有人可以帮我这个忙,我希望能够仅使用键盘击键返回上一页。

javascript testing automated-tests accessibility testcafe

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

断言 testcafe 中是否存在包含特定文本的 td DOM

我刚刚开始使用 testcafe,到目前为止,我发现文档有助于进行测试和自动化 E2E。

我想断言 td 中是否存在一个值,如下所示:

async checkBankAccount(accountNumber, currencyCode){
         const formatedAccount = formatBankAccount(accountNumber, currencyCode);
         console.log(formatedAccount);
         await t
         .expect(Selector('td').withText(formatedAccount).innerText).eql(formatBankAccount);
     }
Run Code Online (Sandbox Code Playgroud)

我遇到以下错误:

未指定断言方法。

我想断言我的 HTML 中是否存在包含 formatedAccount 文本的 td。

谢谢

javascript testing dom assertion testcafe

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

选项不适用于跑步者

我正在尝试在隔离模式下运行一个简单的测试:

test.only("test", async t => { await t.expect(true).notOk(); });

这是我的跑步者

const createTestCafe = require("testcafe");

let testcafe = null;

const runTests = (testFiles) => {
const runner = testcafe.createRunner();
  return runner
  .src(testFiles)
  .browsers(["chrome"])
  .run({
    quarantineMode: true
  });
};

createTestCafe("localhost", 1337, 1338)
  .then(tc => {
   testcafe = tc;
   return runTests(["src/tests/"])
})
.then(() => testcafe.close());
Run Code Online (Sandbox Code Playgroud)

但测试仍然只运行一次。我还尝试在我的 package.json 文件附近添加配置文件,并在我的 runner 文件附近添加配置文件,但仍然没有结果。

testing automation automated-tests e2e-testing testcafe

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

Testcafe 页面重新加载

如何使用 testcafe 重新加载当前页面?我发现

.eval(() => location.reload(true))
Run Code Online (Sandbox Code Playgroud)

但看起来像旧代码,目前的TestCafe 不理解这一点。(无功能错误)

testing automated-tests page-refresh e2e-testing testcafe

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

如何将参数注入 TestCafé 测试?

设想:

\n\n

我使用 API 运行封装在代码中的 TestCaf\xc3\xa9 \n我有一个想要参数化的测试,使用不同的动态值进行测试。

\n\n

问题

\n\n

Testcaf\xc3\xa9 不支持向测试发送参数。有没有办法注入值?

\n

javascript automated-tests inject e2e-testing testcafe

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

如何在 TestCafe 中单击未渲染的虚拟化元素

我正在使用react-virtualized来获取一长串(1000 多个)项目列表以供选择。我正在尝试设置一个端到端测试,需要单击当前未渲染的元素之一。

通常,我会简单地使用类似的东西:

await t.click(
    ReactSelector('ListPage')
        .findReact('ListItem')
        .nth(873) // or .withText(...) or .withProps(...)
)
Run Code Online (Sandbox Code Playgroud)

但由于只渲染了 s 的一小部分ListItem,TestCafe 无法找到所需的元素。

我一直在试图弄清楚如何使用 TestCafe 的ClientFunction滚动列表容器,以便ListItem呈现所需的内容。

但是,我遇到了一些问题:

  • 有没有办法共享SelectorClientFunction修改DOM元素的scrollTop?或者我是否必须直接通过 DOM 重新查询元素?
  • 由于ListItems 的高度不同,滚动位置不是索引x项目高度的简单计算。如何在此函数中不断更新/滚动,直到所需的内容Selector可见?

automated-tests typescript reactjs react-virtualized testcafe

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