这是我试图在testcafe v1.0.1中运行的一种测试,我对此很新。 这是我的test.js文件,其中我有三个不同的测试用例R03,R05,R06,并且都使用withText()函数搜索网页中的元素。 无论如何,我有一个配置文件(json / js),我可以保存Year_1,Year_2,Year_3和Location_1,Location_2,Location_3的输入,并在我当前的.js文件中使用它。
`import { Selector } from 'testcafe';
fixture `First Fixture`
.page `http://devexpress.github.io/testcafe/example`;
test('R03', async t => {
await t
.click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText('Year_1'))
.click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText('Location_1'))
});
test('R05', async t => {
await t
.click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText('Year_2'))
.click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText('Location_2'))
});
test('R06', async t => {
await t
.click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText('Year_3'))
.click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText('Location_3'))
});
您无法在某些.js文件中存储输入。但是,您可以保存输入选择器并在测试中使用它们。见例子:
element-selectors.json
{
"developerNameInput": "#developer-name",
"populateBtn": "#populate"
}
test.js
fixture `Fixture`
.page('https://devexpress.github.io/testcafe/example/');
const elementSelectors = require('./element-selectors.json');
test('test', async t => {
await t.typeText(elementSelectors.developerNameInput, 'Peter Parker');
});
创建config.js文件 config.js
export default {
// Preview Paramters for R03 Report
year: '2019',
Location: 'Dublin',
};
现在,让您的主文本文件为test.js test.js
import { Selector } from 'testcafe';
import data from "./config.js";
fixture `First Fixture`
.page `http://devexpress.github.io/testcafe/example`;
test('R03', async t => {
var year = data.year.toString();
var location = data.location.toString();
await t
.click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText(year))
.click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText(location))
});
解决方案非常适合我。 如果有人有更好的解决方案,我很乐意实施并测试它。