AngularJS:使用量角器进行e2e测试

时间:2014-02-08 12:07:43

标签: javascript angularjs selenium protractor angularjs-e2e

首先,我是e2e测试的菜鸟。我所做的是

  • 已安装量角器nmp install protractor
  • 已安装webdriver-manager
  • 从我的angularjs app所在的目录运行webdriver-manager start。它运行良好
  • 运行protractor tests/e2e/conf.js它运行良好

然而,在几秒钟内,它显示Timed out waiting for page to load

以下是我的文件:

测试/ E2E / conf.js:

// An example configuration file.
exports.config = {
    // The address of a running selenium server.
    seleniumAddress: 'http://localhost:4444/wd/hub',

    // Capabilities to be passed to the webdriver instance.
    capabilities: {
        'browserName': 'chrome'
    },

    // Spec patterns are relative to the current working directly when
    // protractor is called.
    specs: ['example_spec.js'],

    // Options to be passed to Jasmine-node.
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 30000
    }
};

测试/ E2E / example_spec.js

var protr;

describe('addressBook homepage', function() {

    var ptor;

    beforeEach(function() {
        ptor = protractor.getInstance();
    });

    it('should greet the named user', function() {
        browser.get('/'); // <-- exception here

        element(by.model('yourName')).sendKeys('Julie');

        var greeting = element(by.binding('yourName'));

        expect(greeting.getText()).toEqual('Hello Julie!');
    });
});

我无法理解在哪里定义我的webapp laypout / placement,因此protractor / webdriver知道要运行哪个上下文。

1 个答案:

答案 0 :(得分:0)

使用该设置量角器将尝试导航到“/”。您需要在配置文件中设置baseUrl属性,或在browser.get()中放置绝对URL。如果您的所有测试都在同一个域中,我建议您使用第一个选项。