【问题标题】:simple protractor test failing with unexpected result简单的量角器测试失败并出现意外结果
【发布时间】:2016-08-09 09:25:39
【问题描述】:

我正在尝试对 url http://na5.keylo.co/ 运行量角器测试,目标是:

  1. 用数据“Oracle Corporation”填充_model 字段
  2. click搜索按钮
  3. 预期搜索结果为计数 508

规格代码:

describe('keylocations home page', function () {
it('should search condos', function () {
    browser.get('http://na5.keylo.co/');

    element(by.model('_model')).sendKeys("Oracle Corporation");
    element(by.css('.search__block.search__submit')).click();


    var condos = element.all(by.repeater('condo in scrollResults'));
    expect(condos.count()).toEqual(508);

    // this also can be used to get desired test completed
    //expect(element(by.css('.bar__number'))).toEqual("508 condos found");

});
});

问题:

我总是在by.repeater 结果中得到0,而当我在浏览器上手动使用时,我看到了确切的结果,它很简单,但我犯了错误不知道是什么?

编辑:

按照@Gunderson 的建议使用 conf.js:

//this works and sows success
browser.driver.wait(browser.driver.isElementPresent(by.css('.bar__number')));


//this fails with following error log
expect(element(by.css('.bar__number')).getText()).toEqual("508 condos found");


//this also fails with following error log
browser.driver.wait(expect(element(by.css('.bar__number')).getText()).toEqual("508 condos found"));

使用 http://localhost:4444/wd/hub 的 selenium 服务器 [launcher] 开始运行 1 个 WebDriver Spec 实例 Started WARNING - 更多 比定位器找到的一个元素 by.model("_model") - 第一个 结果将被使用

keylocations 主页 ?应该搜索公寓 - 失败:等待 Protractor 与页面同步时出错:“[ng:test] 找不到元素参数的注入器 getTestability\nhttp://errors.angularjs.org/1.5.2/ng/test"

F


  • 失败 *

1) keylocations 主页应该搜索 condos - 失败:等待 Protractor 与页面同步时出错:“[ng:test] 找不到元素参数的注入器 getTestability\nhttp://errors.angularjs.org/1.5.2/ng/test"

在 14 秒内执行了 1 个规范中的 1 个(1 个失败)。

失败:1) keylocations 主页应该搜索 condos 消息: 失败:等待量角器与页面同步时出错:“[ng:test] 找不到元素参数的注入器 getTestability\nhttp://errors.angularjs.org/1.5.2/ng/test" 堆栈: 错误:失败:等待量角器与页面同步时出错:“[ng:test] 找不到元素参数的注入器 getTestability\nhttp://errors.angularjs.org/1.5.2/ng/test" 在 C:\Users\Hair\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:101:16 在 Promise.invokeCallback_ (C:\Users\Hair\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1329:14) 在 TaskQueue.execute_ (C:\Users\Hair\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2790:14) 在 TaskQueue.executeNext_ (C:\Users\Hair\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2773:21)

1 个规范,1 个失败在 14.407 秒内完成 [启动器] 0 个实例 WebDriver 仍在运行 [launcher] chrome #01 failed 1 test(s) [启动器] 总体:1 个失败的规范 [启动器] 进程退出 错误代码 1

【问题讨论】:

    标签: angularjs selenium-webdriver protractor angularjs-e2e e2e-testing


    【解决方案1】:

    对我来说,您的本地设置似乎有问题。我复制了你的代码,它通过了(失败了,因为数字错误,但它检索到了公寓的数量)。

    describe('keylocations home page', function () {
      it('should search condos', function () {
        browser.get('http://na5.keylo.co/');
    
        element(by.model('_model')).sendKeys("Oracle Corporation");
        element(by.css('.search__block.search__submit')).click();
    
    
        var condos = element.all(by.repeater('condo in scrollResults'));
        expect(condos.count()).toEqual(508);
    
        // this also can be used to get desired test completed
        //expect(element(by.css('.bar__number'))).toEqual("508 condos found");
      });
    });
    

    这会返回:

    看来您在本地有问题。我将粘贴一个指向我的配置文件 https://gist.github.com/anonymous/7a682f45999c0377013e409fe6dd4e24 的链接——除此之外,我建议您更新 Protractor、webDriver 和 Jasmine。

    我正在使用 Protractor 2.5.1 和 Jasmine 2.3.4。

    【讨论】:

    • 感谢您的努力,如果您取消注释 expect(element(by.css('.bar__number'))).toEqual("508 condos found"); 测试应该通过,您认为是吗?
    • 我假设您的意思是 expect(element(by.css('.bar__number')).getText()).toEqual("508 condos found"); - (添加了 getText)因为否则您正在对对象进行操作。但是我运行了它,该网站现在似乎响应缓慢,所以它现在返回一个空字符串。
    • 我赞成您的回答,如果它按需要工作,我可以接受。我正在尝试获取 OP 中提到的内容。
    • @ZeeshanHassanMemon 查看this doc
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-27
    • 1970-01-01
    • 1970-01-01
    • 2020-08-14
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多