Angular2 + Protractor测试运行没有结果

时间:2017-06-08 18:10:57

标签: angular protractor

我正在为Angular 2应用程序开始简单的Protractor测试,看起来像这样:

    import { browser, element, by } from 'protractor';

    describe('My Page', function() {
      it('should load news block', () => {
        browser.get('/my/page');

        element(by.id('news')).getText().then(function(text) {
          expect(text.length > 0).toBeTruthy();
        });
    });
});

因此系统运行浏览器,转到所需的页面,我看不到结果 - 如果测试成功执行。在控制台中,我总是看到“Spec started”消息。

enter image description here

我做错了什么?

量角器配置文件:

exports.config = {
    allScriptsTimeout: 2500000,
    specs: [
        './e2e/**/*.e2e-spec.ts'
    ],
    capabilities: {
        'browserName': 'chrome'
    },
    directConnect: true,
    baseUrl: 'http://localhost:4200/',
    framework: 'jasmine',
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 2500000,
        print: function() {}
    },
    useAllAngular2AppRoots: true,
    beforeLaunch: function() {
        require('ts-node').register({
            project: 'e2e'
        });
    },
    onPrepare: function() {
        jasmine.getEnv().addReporter(new SpecReporter());
    }
};

1 个答案:

答案 0 :(得分:1)

我相信它应该已经记录了通过测试的时间段;但是,由于您使用的是SpecReporter,因此可能会将默认报告者覆盖到控制台。有两种方法可以调试它:

  1. 您可以使用酷炫的新BlockingProxy功能。此功能应在获取文本之前突出显示该元素。您可以在此处阅读有关如何执行此操作的信息:how to debug the protractor files?

  2. 我相信在某些情况下BlockingProxy不会突出显示该元素。如果是这种情况,您可以尝试一些事情来调试:

  3. (更新答案以获取更多日志记录):

      console.log('we are going to find the news id');
      element(by.id('news')).getText().then(text => {
        // If we do have text, let's log it so we know we got to this block of code.
        console.log('Pass! We have text: ' + text);
        expect(text.length > 0).toBeTruthy();
      }).catch(err => {
        // Else we could not fid the 'news' id, so we should log an error.
        console.log('The id for news could not be found.);
        console.log(err);
      });
    
相关问题