简体   繁体   English

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

[英]AngularJS: e2e testing with protractor

First of all I'm a noob with e2e testing. 首先,我是e2e测试的新手。 What I've done is 我所做的是

  • installed protractor nmp install protractor 安装了量角器nmp install protractor
  • installed webdriver-manager 安装的webdriver-manager
  • run webdriver-manager start from the directory where my angularjs app sits. 从我的angularjs应用程序所在的目录webdriver-manager start运行webdriver-manager start it runs fine 运行良好
  • run protractor tests/e2e/conf.js it also runs fine 运行protractor tests/e2e/conf.js它也运行良好

However in few seconds it says Timed out waiting for page to load 但是在几秒钟内它说Timed out waiting for page to load

Here are my files: 这是我的文件:

tests/e2e/conf.js: 测试/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
    }
};

tests/e2e/example_spec.js tests / 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!');
    });
});

I just can't understand where to define my webapp laypout/placement so protractor/webdriver knows which context to run. 我只是不明白在哪里定义我的webapp布局/位置,因此量角器/ webdriver知道要运行哪个上下文。

With that setup protractor will be trying to navigate to "/". 通过该设置,量角器将尝试导航到“ /”。 You need to either set the baseUrl property in the configuration file, or put an absolute url in the browser.get(). 您需要在配置文件中设置baseUrl属性,或者在browser.get()中放置一个绝对URL。 If all your tests are going to be on the same domain I'd recommend the first option. 如果您所有的测试都在同一个域中,则建议您选择第一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM