量角器:一次测试通过,但另一次测试失败

时间:2017-12-28 16:47:28

标签: javascript angularjs selenium-webdriver jasmine protractor

我想检查两件事 - 搜索功能是否适用于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()输出?

错误日志:

enter image description here

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);
    });
});

1 个答案:

答案 0 :(得分:2)

searched_term元素是input元素 - 它没有“文本”,输入的值存储在value属性中。将getText()替换为getAttribute("value")

expect(searched_term.getAttribute("value")).toEqual('Baking a Cake without Margarine');