2
votes

I've been looking at the documentation for protractor and I want to be able to select an array of via a selector of any sort and get the text value of the first one and assert it. No matter what I try with protractor it times out when I try getText() and get().

This is what I'm looking at. Reference

Here is my code:

describe('E2E: Global Scan', function () {

    beforeEach(function () {
        browser.get('#/dashboard/global-scan');
    });

    it('should grab all a tags within li tags', function () {

        element.all(by.css('li a')).then(function(items) {
            expect(items.length).toBeDefined()
            expect(items[0].getText()).toBeDefined();
        });

        var list = element.all(by.css('li a'));
        expect(list.length).toBeDefined()
        expect(list.get(0).getText()).toBeDefined();

    });

});

As you can see I tried both with a then promise function and save the result of element.all to a variable and looping through that. That doesn't work either. What happens is the test just times out.

Failures:

1) E2E: Global Scan should grab all a tags within li tags Message: Error: Timed out waiting for Protractor to synchronize with the page after 10 seconds. Please see https://github.com/angular/protractor/blob/master/docs/faq.md

If I try browser.element that starts to return me something. But it still breaks when I use get or getText().

Does anyone have any ideas? Doing what the documentation says doesn't actually work. Do I have a really old version of protractor?

2
try adding a timeout: beforeEach(function () { browser.get('#/dashboard/global-scan'); },10000); ... btw: your error message is not from your posted test("should grab the tabs Message") .. you can also try adding "browser.ignoreSynchronization = true;" before running your first test - nilsK
@nilsk thank you, browser.ignoreSynchronization = true; did do the trick. From what I read you don't need to do timeouts anymore. They have fixed Protractor to hook into Angular better now. Thanks again. - Chester Rivas

2 Answers

1
votes

You can increase that with setting protractor config

allScriptsTimeout: timeout_in_millis

Refer the https://github.com/angular/protractor/blob/master/docs/timeouts.md page Waiting for Page Synchronization topic for more info.

0
votes

I was facing the same issue while doing E2E for Angular Project. Finally, I configured the protractor.conf.js file and spec.e2e.ts to get rid of "Times Out Waiting For Element ".

protractor.conf.js

const { SpecReporter } = require('jasmine-spec-reporter')

exports.config = {
  allScriptsTimeout: 110000,
  getPageTimeout: 110000,
  specs: [
'./e2e/**/example.e2e-spec.ts',
  ],
  capabilities: {
browserName: 'chrome'
  },
  directConnect: true,
  baseUrl: 'http://localhost:8123/',
  framework: 'jasmine',
  jasmineNodeOpts: {
 showTiming: true,
showColors: true,
includeStackTrace: false,
defaultTimeoutInterval: 600000
  },
  onPrepare () {
require('ts-node').register({
  project: 'e2e/tsconfig.e2e.json'
})
browser.driver.manage().deleteAllCookies();
browser.driver.manage().window().maximize();
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
  }
}

example.e2e-spec.ts

import { browser, by, protractor, element, promise, ElementFinder, ElementArrayFinder } from 'protractor';

describe('Test', () => {
var originalTimeout;

beforeEach(() => {
    originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;
    browser.driver.sleep(3000);
});

afterEach(function () {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
    browser.driver.sleep(5000);
});

it('It should display title and it should login also',() => {
    browser.ignoreSynchronization = true;
    browser.get('/',5000);
    expect(browser.getTitle()).toEqual('TitleExample');
});

});