-2

config.js

exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',

specs: [
    'Login.js',
    'FeatureList.js',
    'NewApplicationRegistration.js',
    'ApplicationRegistrationManagement.js',
    'RegistrationStatus.js',
],
baseUrl: 'http://localhost:3000',
multiCapabilities: [{
    'browserName': 'chrome'
},
    // {
    //     'browserName': 'firefox'
    // }, 
    // {
    //     'browserName': 'internet explorer'
    // }
],
jasmineNodeOpts: {
    onComplete: null,
    isVerbose: false,
    showColors: true,
    includeStackTrace: true,
    defaultTimeoutInterval: 3000000
},
allScriptsTimeout: 11000,
rootElement: 'html',
onPrepare: function () {
    browser.ignoreSynchronization = true;
    browser.driver.manage().window();
},
};

1st specification file

'use strict'

describe('Application Registration Page', function () {

beforeEach(function () {
    browser.waitForAngular();
    browser.get('/register');
});

// Login
it('Test for Login', function () {
    expect(element(by.xpath('/html/body/admin-app-root/layout/div[1]/div/ng-component/div/form/div/table/tbody/tr[1]/th/label')));
    var EC = protractor.ExpectedConditions;
    var username = element(by.id('login-username'));
    browser.wait(EC.visibilityOf(username), 30000);
    username.sendKeys('sss');

    expect(element(by.xpath('/html/body/admin-app-root/layout/div[1]/div/ng-component/div/form/div/table/tbody/tr[2]/th/label')));
    var EC = protractor.ExpectedConditions;
    var password = element(by.id('login-password'));
    browser.wait(EC.visibilityOf(password), 30000);
    password.sendKeys('sss');

    browser.driver.sleep(1000);

    element(by.xpath('/html/body/admin-app-root/layout/div[1]/div/ng-component/div/form/div/table/tbody/tr[3]/td/button')).click().then(function (username, password) {
        if (username, password) {
            browser.navigateTo('http://localhost:3000/register/core/feature-list');
        } else {
            expect(browser.isElementPresent(element(by.xpath('/html/body/admin-app-root/layout/div[1]/div/ng-component/div/form/div/table/tbody/tr[1]/td/b'))));
        }
    });
});
});

2nd specification

'use strict'

describe('Welcome to feature list', function () {

beforeEach(function () {
    browser.waitForAngular();
    browser.get('/register/core/feature-list');
});


describe('Header', function () {

    // Application Registration text
    it('Test for Application Registration text', function () {
        var EC = protractor.ExpectedConditions;
        var ar = element(by.xpath('/html/body/admin-app-root/layout/div[1]/c-header/nav/div/div[1]/a[2]'));
        browser.wait(EC.presenceOf(ar), 2000000);
        expect(ar.getAttribute('value')).toEqual('Application Registration');
    });


    it('Test for user name', function () {
        var EC = protractor.ExpectedConditions;
        var username = element(by.xpath('//*[@id="cox-navbar"]/ul/li[1]/a'));
        browser.wait(EC.visibilityOf(username), 2000);
        expect(username.isPresent()).toBe(true);
    });     
});

1st specification script is running fine but while running 2nd specification I am getting an error saying:

wait timeout after 2000000ms

Even though script timeout is very big it is getting error. It is not able to find the element from browser for the given timing.

Help me to find the solution.

amit
  • 41
  • 2
  • 10
  • have you tried to use other selector for this element ? It's kinda bad to use that kind of xpath, maybe try to use css class, name or id ? – Hikaryu Oct 05 '17 at 12:13
  • @Hikaryu, ya i have tried for all the expectation but same error i am getting. But one thing i seen that while running 2nd specification it is displaying 1st specification page only, i am not sure is it loading 2nd specification browser.get page. – amit Oct 05 '17 at 12:47

2 Answers2

0

In very short your answer: Get your Protractor working without using ignoreSynchronization to avoid these kind of problems. I'll elaborate in the following a bit about your issues, starting with the one you specifically asked.

Reason for getting the timeout on 2nd spec

EC.presencesOf() is implicitly calling waitForAngular read more about it here

Because you have ignoreSynchronization = true your call for waitForAngular times out (as you ignore the AngularSynchronization protractor can't recognize the presenceOf an object). Because you call it indirectly it times out.

It just doesn't make sense, if you use ignoreSynchronization without knowing the consequences of it. There are very limited reasons, why you should use it.

Your issue with 1st spec without ignoreSynchronization

Given your XPath-queries, to me it seems your Angular-Root-Element is not body, but admin-app-root. Therefore try to change your rootElement: body in config.ts to rootElement: admin-app-root. (as one possible root cause, why your Protractor doesn't work nicely with your Angular Page under test).

After the configuration adjustment: Should you still get the timeouts or missing testability, further check this answer.

Also reduce your timeout of 2000000 for your ar-element. I think, such a long timeout almost never makes sense as many other timeouts apply before (web-timeout, jasmine-timeout, further webdriver-timeouts, etc.).

some more suggestions and infos

  1. put global.EC = protractor.ExpectedConditions; in your onPrepare: section of conf.js, so you don't have to add it to each test case.
  2. add a step with a promise to your onPrepare: section as else your tests might get started early (see this documentation and also a simple example here)
  3. Avoid the use of XPath-Selectors as they're slow and hard to maintain (any any added div or moved form... basically any UI design modification could let your tests fail). Use Angular-Model or CSS-Selectors instead (learn about it here).
  4. as a browser.get() command doesn't create a promise you should put a browser.waitForAngular() in your beforeEach section to make sure, that your tests only starts after your page got fully loaded.
  5. only use ignoreSynchronization, if you know that you test a specific situation in which you need it. In example, if you explicitly try to verify something during the loading process, so while asynchronous tasks are processed (i.e. to test the appearance of a blocker-element). Learn about the purpose of ignoreSynchronization here.
  6. If your Protractor can't synchronize with your Angular-Page or your testing a Non-Angular-Page use browser.waitForAngularEnabled(false). If you deal with an Angular page, first try to debug the reason why Protractor can't synchronize. Learn about these possibilities here
Ernst Zwingli
  • 1,402
  • 1
  • 8
  • 24
  • After removing browser.wait(presenceOf()/visibilityOf()) from test cases, I am getting error saying no element found using locator. – amit Oct 06 '17 at 05:59
  • I just see, that in your conf.js you set `ignoreSynchronization = true`. Any specific reason for, that? Because this basically tells protractor not to wait until a page is loaded. There are rather specific reasons for putting that variable to true. Read more about [here](https://stackoverflow.com/questions/28808463/what-is-browser-ignoresynchronization-in-protractor). I updated my answer now. – Ernst Zwingli Oct 07 '17 at 20:07
  • If i comment on the line browser.ignoreSynchronization = true; then i am getting error for 1st specification also saying waited time out error. – amit Oct 09 '17 at 06:29
  • That sounds like the better error than the other. And as I already wrote in my edited answer, [check this answer](https://stackoverflow.com/a/46608556/8683679) to see your possibilities in debugging timeouts. It also explains a lot of context. – Ernst Zwingli Oct 09 '17 at 19:28
  • Is my specification files are right? because 1st specification is running fine with browser.ignoreSynchronization = true; and if i comment on browser.ignoreSynchronization = true line then it is throwing "couldn't find test-ability for element", but the 2nd specification anyhow throwing "wait timed out error" whether synchronization is true or false; – amit Oct 11 '17 at 08:44
  • "Couldn't find testability" error is a game changer. It means your Protractor is not yet properly configured, so it never fully synchronizes with the Angular Page you'd like to test. I re-wrote my answer and provided you additional info, why your 2nd spec fails, why `ignoreSynchronization` is probably a bad choice and how you can bring it all to work. Take some time to also read through the linked information I provided. – Ernst Zwingli Oct 12 '17 at 10:13
0

@amit Try to use promise inside beforeEach sth like this:

beforeEach(function () {
    browser.waitForAngular().then(funtion(){
      return browser.get('/register/core/feature-list');
    }).then(function(){
       console.log(browser.getCurrentUrl()) // ensure you are on correct url 
    })
});

it should work.

Hikaryu
  • 317
  • 5
  • 17
  • any error ? becouse without it i can't help. If you copy pasted then it might not work becouse i was writing it just for an idea – Hikaryu Oct 06 '17 at 08:39
  • I wrote that code and tried but am getting same error. – amit Oct 06 '17 at 10:01