1

Node Version: v6.9.4

Protractor Version: 5.1.1

Angular Version: 1.2.28

Browser(s): Chrome:Version 58.0.3029.96 (64-bit) Chrome WebDriver:Version 2.29

Operating System and Version: MAC OS Siera 10.12.3

protractor configuration file

exports.config = {
  directConnect: true,
  capabilities: {
    'browserName': 'chrome'
  },
  framework: 'jasmine',
  specs: ['./Test/LoginTest.js'],
  allScriptsTimeout: 120000,
  getPageTimeout: 120000,
  jasmineNodeOpts: {
  showColors: true,
  defaultTimeoutInterval: 120000
}

A relevant example test

There is button in the page, when i try to click using protractor , It throws time out error . Unable to click on the element. Same thing work on selenium webdriver.

Step to Reproduce Step 1: Open website using this URL https://www.neonmob.com/login

Step 2: Enter the user name and password mentioned below and click on Login button UserName: sharif33332 Password: 1234

Step 3: After login navigate to this URL https://www.neonmob.com/shariftestuser to navigate to exact page where problem occurs.

Issue :Now at this page unable to click on Trade Button and it throws time out exception error.

Same element can be found using jQuery. Please follow the above steps to reproduce this issue.

Used the below code to click on this button

element(by.css("span[id='trade-btn']")).click();

Please let me know if you are not able to follow the steps. I believe there is an issue in protratcor

Nick Tomlin
  • 28,402
  • 11
  • 61
  • 90

3 Answers3

1

I found the problem. There is nothing wrong with protractor. There is something wrong with the page. You don't get a timeout on clicking on the button / not finding it. You get an error because the page times out because Angular didn't release the page. There are still open calls or what so ever that keep Angular not ready. This was the log I got

Failures:
1) click on trade button should click on the trade button
  Message:
    Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
  Stack:
    Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
        at ontimeout (timers.js:365:14)
        at tryOnTimeout (timers.js:237:5)
        at Timer.listOnTimeout (timers.js:207:5)
  Message:
    Failed: Timed out waiting for asynchronous Angular tasks to finish after 30 seconds. This may be because the current page is not an Angular application. Please see the FAQ for more details: https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular
    While waiting for element with locator - Locator: By(css selector, #trade-btn).
    The following tasks were pending:
     - $timeout: function (){ownershipPromise=artPieceService.syncOwnership()}

If you disable the wait for angular with this it will work

describe('click on trade button', () => {
    beforeEach(function () {
        browser.get(browser.baseUrl);
        $('#field-username').sendKeys('sharif33332');
        $('#field-password').sendKeys('1234');
        $('#signin-btn').click();
        browser.driver.wait(() => browser.getCurrentUrl().then((currentUrl) => currentUrl === 'https://www.neonmob.com/sharif33332'));
        browser.get('https://www.neonmob.com/shariftestuser')
    });

    it('should click on the trade button', () => {
        // Disable wait for Angular
        browser.ignoreSynchronization = true;
        // Wait 2 seconds for the page to be loaded
        browser.sleep(2000)
        $('#trade-btn').click();
        // Wait to verify that the trade button has been clicked.
        browser.sleep(5000);
    })
});

This will confirm that there is nothing wrong with protractor but you need to dive into Angular on this page / ask a developer to fix this.

wswebcreation
  • 2,365
  • 2
  • 10
  • 18
  • if it is an angular page, there is a function that waits for the page to load before checking the object. you can also use browser.sleep but the seconds are fixed. you can also try using a recursive function that can act as a "waitForAngular" function. http://stackoverflow.com/questions/43656135/changing-protractor-default-timeout-inside-function/43679616#43679616 – Paul Co May 07 '17 at 05:37
  • Also set the timeout to 120 seconds, that didn't help. That means that the sleep also will not work. I think there is something wrong with the interval on the page that keeps open http calls – wswebcreation May 07 '17 at 05:40
0

@wswebcreation , Are you sure this is not the angular page. If it is not then angular wait will not work. Will be needed to browser.ignoreSynchronization=true .

Anyway I will ask our developer to look onto this and debug it more to fix from application side.

Anyway current solution provided above working fine.

Thank you so much for your help

  • Hi, I'm sure. Check the sourcecode of the page. If you open the page, check the source you will see at line 567 the first reference to Angular, then at line 586 the loading of the angular files and in the body tag `` the `ng-app` reference. More proof couldn't be given. You now have accepted a correct answer with a wrong explanation. I hope you understand that his and my answer are only a workaround (with the `browser.ignoreSynchronization=true `) and will hold you down in automating the page / application in a right way. – wswebcreation May 07 '17 at 17:19
-1

After checking, your second URL (does not seem) to be an angular page and requires ignoreSynchronization.

Try using the code below:

describe('angularjs homepage todo list', function() {
  it('should add a todo', function() {
    browser.get('https://www.neonmob.com/login');
    element(by.id('field-username')).sendKeys('sharif33332');
    element(by.id('field-password')).sendKeys('1234');
    element(by.id('signin-btn')).click();
    browser.waitForAngular();
    browser.ignoreSynchronization=true
    browser.executeScript('this.document.location = "https://www.neonmob.com/shariftestuser"');
    element(by.id('trade-btn')).click();
  });
});

I did not fix the format, you can do that one. :)

Nothing special on config as well, I only use this:

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['spec.js'],
  jasmineNodeOpts: {defaultTimeoutInterval: 60000}
};
Paul Co
  • 447
  • 2
  • 9
  • Have you tried it in with the info that was provided? Then you will see it will not work due to a timeout on waiting for angular – wswebcreation May 07 '17 at 07:33
  • One question, why don't you login 'shariftestuser' instead of 'sharif33332'? Are you testing a specific function here? – Paul Co May 07 '17 at 09:28
  • The page "https://www.neonmob.com/shariftestuser" is an angular page. Just open your console and type `angular` and you will get the angular object. You can also find the Angular debug info in the code when you look at the DOM through devtools in Chrome. – wswebcreation May 07 '17 at 10:30
  • anyway, just try the code above, I tested it and is working on my desktop. Not sure why you voted down – Paul Co May 07 '17 at 16:39
  • The above provided solution is (browser.waitForAngular(); browser.ignoreSynchronization=true) working.Thanks for the Help. – Perwez Alam May 07 '17 at 16:43
  • Please vote up and mark as answer. :) not sure who voted down though hmmm – Paul Co May 07 '17 at 16:45
  • btw, waitForAngular is needed because when you try to login, user was not logged in immediately, it needs to finish loading first before we change the URL. :) – Paul Co May 07 '17 at 16:47
  • @PaulCo Yes I am testing a specific function, I need to login with one user and then only i can search other user and do the Trade. – Perwez Alam May 07 '17 at 17:04
  • @PaulCo I voted down due to the incorrect explanation. It is an Angular page, check the source code, see my comment in the answer of Perwez Alam. The code you (and I also) provided is only a workaround due to Angular not being ready. This should be fixed in the code of the app – wswebcreation May 07 '17 at 17:25