1
我有我的代碼:量角器黃瓜:isPresent不發揮作用
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();
});
當我運行,並在控制檯中看到的錯誤:
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)
我有一些問題? - 爲什麼我沒有使用isPresent
方法? - 當我運行console.log(">>>>>>>"+browser.getTitle());
,爲什麼它顯示>>>>>>>Promise::222 {[[PromiseStatus]]: "pending"}
,我如何使用它來驗證頁面的預期標題?
感謝您的回覆,有關問題'isPresent.isPresent不是function'功能,我想檢查元素'logout'存在在頁面上還是沒有。那麼你有什麼建議嗎? – Luasg
我會使用預期條件:https://angular.github.io/protractor/#/api?view=ExpectedConditions '變種EC = protractor.ExpectedConditions;' '//等待利用ID的元素'account_logout'在dom上可見。# 'browser.wait(EC.visibilityOf($('#account_logout')),5000);' – cvakiitho