【问题标题】:Where does the browser() object is defined in angluarJS ?angularJS 中的 browser() 对象在哪里定义?
【发布时间】:2012-12-06 23:13:05
【问题描述】:

按照 Angular-phonecat 教程,scenario.js 中的第 7 步,使用了 browser() 和 binding() 对象,但是当我尝试使用它们来测试我的应用程序时,运行 testacular 会说:

ReferenceError: browser is not defined
        at null.<anonymous> 

Intellij Ideal 还说:未解析的函数或方法 browser()。我在这里想念什么?

这里是教程中的代码 sn-p: '使用严格';

/* http://docs.angularjs.org/guide/dev_guide.e2e-testing */

describe('PhoneCat App', function() {

  it('should redirect index.html to index.html#/phones', function() {
    browser().navigateTo('../../app/index.html');
    expect(browser().location().url()).toBe('/phones');
  });


  describe('Phone list view', function() {

    beforeEach(function() {
      browser().navigateTo('../../app/index.html#/phones'); //<---  browser() object is not defined !!! 
    });


    it('should filter the phone list as user types into the search box', function() {
      expect(repeater('.phones li').count()).toBe(20);

      input('query').enter('nexus');
      expect(repeater('.phones li').count()).toBe(1);

      input('query').enter('motorola');
      expect(repeater('.phones li').count()).toBe(8);
    });


    it('should be possible to control phone order via the drop down select box', function() {
      input('query').enter('tablet'); //let's narrow the dataset to make the test assertions shorter

      expect(repeater('.phones li', 'Phone List').column('phone.name')).
          toEqual(["Motorola XOOM\u2122 with Wi-Fi",
                   "MOTOROLA XOOM\u2122"]);

      select('orderProp').option('Alphabetical');

      expect(repeater('.phones li', 'Phone List').column('phone.name')).
          toEqual(["MOTOROLA XOOM\u2122",
                   "Motorola XOOM\u2122 with Wi-Fi"]);
    });


    it('should render phone specific links', function() {
      input('query').enter('nexus');
      element('.phones li a').click();
      expect(browser().location().url()).toBe('/phones/nexus-s');
    });
  });


  describe('Phone detail view', function() {

    beforeEach(function() {
      browser().navigateTo('../../app/index.html#/phones/nexus-s');
    });


    it('should display placeholder page with phoneId', function() {
      expect(binding('phoneId')).toBe('nexus-s');
    });
  });
});

【问题讨论】:

标签: angularjs karma-runner


【解决方案1】:

它在 angular-scenario.js 中定义

【讨论】:

  • 当我包含 angular-scenario.js 时,睾丸的行为非常奇怪
  • Chrome 22.0: Executed 0 of 0 SUCCESS 没有执行测试,当我删除 angular-scenario.js 时,一切正常吗?有什么建议吗?
  • 我建议您先看看是否可以让angular-seed 项目工作。你应该能够运行 node scripts/web-server.js & 然后 testacular start config/testacular-e2e.conf.js runner.html 文件和 testacular-e2e.conf.js 文件应该让你至少走得更远.
【解决方案2】:

//规格文件

'use strict';
describe('demoApp', function() {
it('should redirect node_list.html to node_list.html#/menu', function() {
browser().navigateTo('/node_list.html');
expect(browser().location().url()).toBe('/menu');
  });

describe('menu_view', function() {
beforeEach(function() {
  browser().navigateTo('/node_list.html#/menu'); 
});
});
});

Error:
Chrome 39.0.2171 (Linux) demoApp should redirect node_list.html to node_list.html#/menu FAILED
ReferenceError: browser is not defined at Object.<anonymous> (/test/viewpage.js:5:5)

【讨论】:

  • 我是 karma jasmine 的新手,有人帮忙,这个文件有什么错误。
  • 如果您有新问题,请将其发布在另一个问题上,请勿将其作为答案发布
猜你喜欢
  • 2013-09-13
  • 2011-08-14
  • 2018-01-05
  • 2020-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-04
相关资源
最近更新 更多