Reputation: 87
I wanted to create a cucumber test step with protractor,but I got in the expect step the '2019' is not thenable. Here is my source code:
this.Then(/^I check that the calculated year from the current month\(if current month >= 6 ==> current year = current year \+ 2,else current year = current year \+ 1\)$/,function(callback) {
var actualDate=new Date();
var actualYear=actualDate.getFullYear();
var actualMonth=actualDate.getMonth()+1;
//expect(targetAmountPO.getYesInflationLabel().isDisplayed()).eventually.to.equal(true).then(callback);
targetAmountPO.getYesInflationLabel().isDisplayed().then(function() {
targetAmountPO.getYesInflationCorrectionAnswer().isSelected().then(function(){
targetAmountPO.getYesInflationLabel().getAttribute("outerText").then(function(text,callback){
//console.log(text);
var splittedString=text.split(":");
//console.log(splittedString[1]);
if(actualMonth>=6)
{
actualYear+=2;
var yearString=actualYear.toString();
console.log(yearString);
expect(yearString).to.eventually.contain(splittedString[1]).and.notify(callback);
//console.log(actualYear);
}
else
{
expect(actualYear+1).to.include(splittedString[1]).and.notify(callback);
}
})
})
})
})
At the expect(yearString).to.eventually.contain(splittedString[1]).and.notify(callback);
I got the '2019' is not thenable. The yearString is 2019 is good. But why is not thenable?
Can you help me?
Upvotes: 0
Views: 1274
Reputation: 171
As you've properly handled the promise returned by getAttribute("outerText")
the values in yearString
and splittedString
are just actual values and not promises so you can just use a chai assertion and not a chai as promised assertion like
expect(yearString).to.contain(splittedString[1])
callback()
and you'll be able to test that to ensure its not calling back before the assertion actually does the check
Upvotes: 1