我想检查两件事 - 搜索功能是否适用于AskJeeves以及搜索框是否存储了正确的字符串。
为了检查这一点,我运行了三个期望语句:
expect(searched_term.getText()).toEqual('Baking a Cake without Margarine');
expect(searched_term.getText()).toEqual('Baking a Pie without Butter');
expect(searched_term.getText()).toEqual(search_box.getText());
只有第二个应该失败。但第一个也失败了。这是为什么?这是错误日志。另外,我如何计算我有多少期望语句和console.log()输出?
错误日志:
browser.waitForAngularEnabled(false);
describe('Enter Search Query in Ask Jeeves', function() {
it('This will insert a query', function() {
browser.get(browser.baseUrl);
element(by.xpath('//*[@id="search-box"]'));
var search_box = element(by.name("q")).sendKeys('Baking a Cake without Margarine');
browser.pause(1500);
var button = element(by.xpath('//*[@id="sbut"]'));
button.click();
var searched_term = element(by.name("q"));
expect(searched_term.getText()).toEqual('Baking a Cake without Margarine');
expect(searched_term.getText()).toEqual('Baking a Pie without Butter');
expect(searched_term.getText()).toEqual(search_box.getText());
// This expect statement checks if the term in the following page reflects the term originally searched.
// In addition this will check functionality of the search engine.
browser.pause(1500);
});
});
答案 0 :(得分:2)
searched_term
元素是input
元素 - 它没有“文本”,输入的值存储在value
属性中。将getText()
替换为getAttribute("value")
:
expect(searched_term.getAttribute("value")).toEqual('Baking a Cake without Margarine');