我正在使用cucumber
,webdriverio
,wdio-cucumber-framework
,wdio-selenium-standalone-service
和wdio-spec-reporter
进行UI接受测试。
npm
个要执行的脚本:
"test": "npm run test:run && npm run test:report",
"test:report": "nyc report --temp-directory=test/coverage --reporter=lcov --report-dir=test/report",
"test:run": "cross-env BABEL_ENV=test wdio test/wdio.conf.js"
所有测试在本地和jenkins
上都运行良好。以下是jenkins
的测试功能之一的输出。默认超时时间是10000毫秒。
Should be able to navigate to individual ticket
[chrome #0-10] ✓ I am logged in as "admin@abc.com"
[chrome #0-10] ✓ I open the url "/apps/tickets/!metric/emergency"
[chrome #0-10] ✓ The number of "tr" elements in the "table" component should eventually be more than "0"
[chrome #0-10] ✓ I click the "a" in the "1st tr" item in the "e-table" component
[chrome #0-10] ✓ I expect the path to contain "/apps/ticket-view/!ticketId/"
在这里,它显示了已通过的所有步骤。并且在所有测试结束时,它显示所有测试都通过了,没有失败。但是它仍然在jenkins
管道上失败。当我通过测试的控制台输出时,下面是我发现的错误。
Starting test: I expect the "1st tr" item in the "table" element to eventually contain "Emergency"
Completed: I expect the "1st tr" item in the "table" element to eventually contain "Emergency"
Error: element ("table") still not existing after 10000ms
现在,由于这个错误,最终输出为false,因此未能通过jenkins
上的验收测试步骤。
下面是获取元素中的元素数量并打开url的定义。
When(
/^The number of "([^"]*)" elements in the "([^"]*)" (component|element|dropdown) should eventually be (more than|less than|equal to) "([^"]*)"$/,
{ wrapperOptions: { retry: 2 }, timeout },
(elementsToCount, parent, parentType, comparator, name) => {
const { selectors } = generateSelectors(parentType, parent);
const expected = parseFloat(parseTemplateString(name));
return browser.waitUntil(async () => {
const actual = await countElements(selectors, elementsToCount);
return {
'more than': actual > expected,
'less than': actual < expected,
'equal to': actual === expected,
}[comparator];
});
},
);
async function gotoUrl(method, url) {
url = parseTemplateString(url);
await (method === 'push'
? browser.execute(`history.pushState(null, null, "${url}")`)
: browser.url(url));
return pathShould('be', url);
}
When(/^I (open|push) the url "([^"]*)"$/, { timeout }, gotoUrl);
即使增加了超时时间,我也无法弄清楚哪个步骤实际上会引发错误。
在测试结束时获得以下输出:
342 passing (329.10s)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! edsp-ui@0.119.0-0 test:run: `cross-env BABEL_ENV=test wdio test/wdio.conf.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the edsp-ui@0.119.0-0 test:run script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
更新 再次尝试并由于测试失败而出现以下错误。
The number of "tr" elements in the "table" component should eventually be more than "0":
function timed out, ensure the promise resolves within 10000 milliseconds
running chrome
Error: function timed out, ensure the promise resolves within 10000 milliseconds
更新2 我尝试在jenkins上运行单个功能文件以获取可用的功能文件。在詹金斯身上一切都很好。似乎在执行多个测试时,存在一些网络问题(延迟获取服务器响应)。但是,如何在进行api调用时检测到缓慢的网络?
这里可能是什么问题?