如何在量角器茉莉花中重试失败的测试规格 [英] How to retry failed test specs in protractor jasmine
问题描述
我正在尝试使用量角器重试机制来运行量角器e2e测试。
我已经安装了Protractor-retry软件包,并在conf.js文件中添加了所需的内容,如下所示:
I am trying to use protractor-retry mechanism to run my protractor e2e tests. I have installed Protractor-retry package and added required things in conf.js file as below:
var PropertiesReader = require('properties-reader');
var properties = PropertiesReader('config.properties');
var retry = require('protractor-retry').retry;
exports.config = {
plugins: [{
package: 'jasmine2-protractor-utils',
disableHTMLReport: false,
disableScreenshot: false,
//screenshotPath: './reports/screenshots',
screenshotPath: './ExecutionResults/reports/screenshots',
screenshotOnExpectFailure: true,
screenshotOnSpecFailure: true,
clearFoldersBeforeTest: true,
htmlReportDir: './reports/htmlReports',
failTestOnErrorLog: {
failTestOnErrorLogLevel: 1100,
excludeKeywords: ['keyword1', 'keyword2']
}
}],
directConnect: true,
// Capabilities to be passed to the webdriver instance.
multiCapabilities: [
{
'browserName': properties.get('browserName'),
}],
onCleanUp: function(results) {
retry.onCleanUp(results);
},
suites: {
test: '../test_spec/smoke/cards/test.js'
},
// Options to be passed to Jasmine.
allScriptsTimeout: properties.get('allscriptTimeOutSeconds'),
getPageTimeout: properties.get('pageTimeOut'),
jasmineNodeOpts: {
defaultTimeoutInterval: 2000000
},
onPrepare: function () {
retry.onPrepare();
var jasmineReporters = require('jasmine-reporters');
var width = 1400;
var height = 1000;
browser.driver.manage().window().maximize();
useAllAngular2AppRoots: true,
browser.driver.get(properties.get('envUrl'),);
browser.driver.manage().timeouts().implicitlyWait(10000);
var AllureReporter = require('jasmine-allure-reporter');
jasmine.getEnv().addReporter(new AllureReporter({
allureReport: {
resultsDir: 'allure-results'
}
}));
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'testresults',
filePrefix: 'xmloutput'
}));
var junitReporter = new jasmineReporters.JUnitXmlReporter({
// setup the output path for the junit reports
savePath: 'output/',
consolidateAll: false
});
jasmine.getEnv().addReporter(junitReporter);
return global.browser.getProcessedConfig().then(function (config) { });
},
afterLaunch: function() {
return retry.afterLaunch(2);
},
onComplete: function () {
var browserName, browserVersion;
var capsPromise = browser.getCapabilities();
capsPromise.then(function (caps) {
browserName = caps.get('browserName');
browserVersion = caps.get('version');
var HTMLReport = require('protractor-html-reporter');
testConfig = {
reportTitle: 'Test Execution Report',
outputPath: './ExecutionResults/reports',
screenshotPath: './screenshots',
testBrowser: browserName,
browserVersion: browserVersion,
modifiedSuiteName: false,
screenshotsOnlyOnFailure: true
};
browser.sleep(5000)
new HTMLReport().from('testresults/xmloutput.xml', testConfig);
browser.close();
});
}
};
我的测试文件如下:
describe("Timesheet_Apply_Approved_Card", function () {
it ("Retest 1." , function(){
//browser.get("http://www.google.com")
// browser.sleep(3000)
console.log("test var : "+ testing.label)
console.log("test " + testing._exitReasonFamilyReason)
console.log("after test")
expect("a").toEqual("b")
})
it ("Restest 2." , function(){
console.log("after test 2")
expect("a").toEqual("a")
})
})
但是当我运行上面的test.js文件时。它不会再次运行失败的测试。它给出以下错误:
But when I run the above test.js file. It does not run the failed test again.It gives below error:
test var : undefined
test undefined
inside method undefined
after test
Fafter test 2
.
Failures:
1) Timesheet_Apply_Approved_Card Retest 1.
Message:
Expected 'a' to equal 'b'.
Stack:
Error: Failed expectation
at UserContext.<anonymous>
(D:\GIT\altworklife\CARDS\test_spec\smoke\cards\test.js:20:21)
2 specs, 1 failure
Finished in 0.545 seconds
[17:43:43] I/launcher - 0 instance(s) of WebDriver still running
[17:43:43] I/launcher - chrome #01 failed 1 test(s)
[17:43:43] I/launcher - overall: 1 failed spec(s)
Re-running tests , attempt : 1
Re-running the following test files :
D:\GIT\altworklife\CARDS\test_spec\smoke\cards\test.js
[17:43:43] E/launcher - spawn
C:\Users\amit.hada\AppData\Roaming\npm\node_modules\protractor\bin\protractor
ENOENT
[17:43:43] E/launcher - Error: spawn
C:\Users\amit.hada\AppData\Roaming\npm\node_modules\protractor\bin\protractor
ENOENT
at _errnoException (util.js:1022:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
[17:43:43] E/launcher - Process exited with error code 199
它打印出它正在再次尝试,但突然失败,并显示上述错误。
It prints that it is trying again but than abruptly fails with error as given above.
任何想法,为什么不重试就会失败?
Any idea, why it is failing without retrying?
推荐答案
看起来您是从Windows笔记本电脑/服务器运行CMD,此量角器重试pkg不支持该命令
Look Like you are running your CMD from a windows laptop/server, which is not supported by this protractor-retry pkg
这篇关于如何在量角器茉莉花中重试失败的测试规格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!