Reputation: 93
I have my code:
this.Then(/^I should see "([^"]*)" link$/, function (callback) {
var logoutpath = by.xpath('//div[@id="account_logout"]/a');
browser.wait(function() {
return dv.isElementPresent(logoutpath);
}, 30000);
browser.driver.isElementPresent(logoutpath).then(function(isPresent){
expect(isPresent.isPresent()).toBe(true);
browser.driver.findElement(logoutpath).then(function(start){
start.click();
});
});
browser.sleep(2222);
console.log(">>>>>>>"+browser.getTitle());
callback();
});
when i run and get error in console:
TypeError: isPresent.isPresent is not a function
at c:\Users\binhlex\WebstormProjects\untitled\Feature\Steps\login_steps.js:33:30
at [object Object].promise.ControlFlow.runInFrame_ (c:/Users/binhlex/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1857:20)
at [object Object].goog.defineClass.notify (c:/Users/binhlex/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2448:25)
at [object Object].promise.Promise.notify_ (c:/Users/binhlex/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:564:12)
at Array.forEach (native)
I have some question?
- Why didn't i use isPresent
method?
- When i run console.log(">>>>>>>"+browser.getTitle());
, why it display >>>>>>>Promise::222 {[[PromiseStatus]]: "pending"}
, how can i use it to verify with expected title of the page?
Upvotes: 1
Views: 1933
Reputation: 1396
To your latest question, because browser.getTitle() is a promise, if you want to console.log Title you'd have to do: browser.getTitle().then(function(title){console.log(title)});
For your first question, I don't get why you are trying to obfuscate the code so much. in protractor you don't have to wait for element before clicking it. ( if you don't have ignore synchronization on).
So this:
browser.driver.findElement(logoutpath).then(function(start){
start.click();
equeals:
logoutpath.click()
Upvotes: 1