I have been searching a solution for this warning for weeks, I looked a hundered github or stackoverflow topics but solutions gave me peace never or temporary. So I opened about this topic pls don't get mad at me I'm stuck.
I am writing e2e test with async await in AngularJs.
I canceled control flow with: SELENIUM_PROMISE_MANAGER: false
this is my login.Spec test file for testing login page:
var LoginPage = require('../pages/login.page.js');
describe('Testing Login Page', function (){
const EC = protractor.ExpectedConditions;
var loginPage = new LoginPage();
beforeAll(async () => {
await loginPage.get().catch((e)=>{
console.log(e);
})
await loginPage.login().catch((e)=>{
console.log(e);
})
});
it('there should be user name and user password area',async () => {
expect(await $('[ng-model="user.name"]').isPresent()).toBe(true);
expect(await $('[ng-model="user.password"]').isPresent()).toBe(true);
});
it('there should be login button',async () => {
expect(await $('[test-id="loginSubmit"]').isPresent()).toBe(true);
});
});
this is my login.page.js for get and login functions:
let LoginPage = function(){
const EC = protractor.ExpectedConditions;
this.get = async ()=>{
await browser.get(`${browser.baseUrl}`);
await browser.wait(
EC.presenceOf(element(by.css('.container.login'))), 30000,
'Waiting too long to open login page'
)
}
this.login=async ()=>{
await $('[ng-model="user.name"]').clear().sendKeys(browser.params.login.user);
await $('[ng-model="user.password"]').clear().sendKeys(browser.params.login.password);
const loginSubmit = await $('[test-id="loginSubmit"]');
await loginSubmit.click();
}
}
module.exports = LoginPage;
this is my export config part in protractor.config.js:
framework: 'jasmine',
specs: ['../test/e2e/specs/*Spec.js'],
SELENIUM_PROMISE_MANAGER: false,
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 900000 //for timeout error: timed out after 30000 msec waiting for spec to complete
},
getPageTimeout: 900000, //for Error: Timed out waiting for page to load after 10000ms
//for Error: Angular could not be found on the page: retries looking for angular exceeded
allScriptsTimeout: 900000, //for Error: Timed out waiting for asynchronous Angular tasks to finish after 11 seconds.
//for ScriptTimeoutError: asynchronous script timeout: result was not received in 11 seconds
multiCapabilities: [{
browserName: 'chrome',
chromeOptions: {
args: ["--window-size=1368,700" ]
}
}],
onPrepare: ()=>{
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: 'test/e2e/results/',
screenshotsSubfolder: 'images',
jsonsSubfolder: 'jsons',
takeScreenShotsOnlyForFailedSpecs: true,
preserveDirectory: false,
docName: 'index.html' ,
cssOverrideFile: 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'
}).getJasmine2Reporter());
},
this is version of test packages in package.json:
"jasmine": "^3.0.0",
"jasmine-core": "^3.0.0",
"jasmine-reporters": "^2.0.0",
"jquery": "^3.2.1",
"karma": "^2.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-jasmine": "^1.1.1",
...
"protractor": "^5.4.0",
"protractor-beautiful-reporter": "^1.1.1",
...
Finally here is my error. I run e2e and before everything gives me this error and then it makes selenium start:
.. [10:43:11] I/update - chromedriver: unzipping chromedriver_2.42.zip (node:17016) UnhandledPromiseRejectionWarning: Error: EPERM: operation not permitted, rename 'C:\ProjectPath\node_modules\protractor\node_modules\webdriver-manager\selenium\chromedriver.exe' -> 'C:\ProjectPath\node_modules\protractor\node_modules\webdriver-manager\selenium\chromedriver_2.42.exe' at Object.fs.renameSync (fs.js:766:18) at unzip (C:\ProjectPath\node_modules\protractor\node_modules\webdriver-manager\built\lib\cmds\update.js:235:8) at files_1.FileManager.downloadFile.then.downloaded (C:\ProjectPath\node_modules\protractor\node_modules\webdriver-manager\built\lib\cmds\update.js:205:13) at at process._tickCallback (internal/process/next_tick.js:188:7) (node:17016) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:17016) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. Blockquote
Okay I tried to put catch block after every test but it seemed not good and didn't get the solution. I made ever function,on async and put before every statement await. I tried to remove browser.wait() in beforeAll code block but it didn't work too so I take it back.
I mean my test run with success and sometimes I don't even get this warning at all. But I changed nothing then it keeps giving me this error.
How can I prevent the unhandled promise rejection?