简体   繁体   中英

Angular2 + Protractor test running with no result

I'm starting simple Protractor test for an Angular 2 app which looks like this:

    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();
        });
    });
});

as a result system runs the browser, goes to the required page and I can't see a result - if test executed successfully. In console I always see 'Spec started' message.

在此处输入图片说明

What I do wrong?

Protractor config file:

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());
    }
};

I believe it should have logged a period for a passed test; however, since you are using a SpecReporter , this may override the default reporter to console. There are two ways you can debug this:

  1. You can use the cool and new BlockingProxy feature. This feature should highlight the element before getting the text. You can read about how to do it here: how to debug the protractor files?

  2. I believe there are a few cases where BlockingProxy will not highlight the element. If that is the case, you could try a couple of things to debug:


(updating answer for more logging):

  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);
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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