Please advise what could be problem here.
userLogin
is provided properly at the end of test but password has value 'undefined
'. Seems that function takePasswordFromNotification()
doesn't return relevant value from notification - why ?
The flow is that after account creation the pop-up notification temporarily appears with assigned login and password and I want to take login and password (which is generated randomly) from notification in order to logout and login to system using login. The rest of code works fine apart of this function.
fit('should create new user and log in by his account', function () {
var userId = Math.random().toString(36).substr(2, 20);
havingTestUser(userId);
var userLogin = givenAccountOfUser(userId);
console.log(userLogin);
var newPassword = takePasswordFromNotification();
console.log(newPassword);
welcomePage.logout('newly created (deleted) account');
browser.driver.get(browser.params.rootUrl);
browser.wait(EC.presenceOf(loginPage.userLogin), WAIT_TIMEOUT, 'login input field was not present');
loginPage.userLogin.sendKeys(userLogin);
loginPage.userPassword.sendKeys(newPassword);
dv.sleep(10000);
clickWithWait(loginPage.signInButton);
expectVisible(welcomePage.usersButton, 'users button after login by new account');
});
function givenAccountOfUser(userId) {
userDetailsPage.goTo(userId);
browser.executeScript('window.scrollTo(0,0);');
goToLoginInput();
var userLogin = Math.random().toString(36).substr(2, 20);
userDetailsPage.loginInputField.sendKeys(userLogin);
expectClickable(userDetailsPage.saveAccountButton, 'save account button');
clickWithWait(userDetailsPage.saveAccountButton);
expectVisible(userDetailsPage.successNotification, 'success notification');
return userLogin;
}
function takePasswordFromNotification() {
userDetailsPage.successNotification.getText().then(function (text) {
var expectedPasswordLength = 12;
var newPassword = text.substring(text.length - expectedPasswordLength, text.length);
return newPassword;
});}