Protractor unable to find elements and script timeout

徘徊边缘 提交于 2019-12-02 04:28:42

问题


I'm running protractor, it runs successfully and load my angular app. The very first test I wrote is to get the sign-up button. Although I can see the sign-up button in my view and I'm targeting it with proper CSS.

Still, all I get is this error after running the test.

App
    ✗ should get the text of sign up button
      - Failed: script timeout: result was not received in 11 seconds
        (Session info: chrome=71.0.3578.98)
        (Driver info: chromedriver=2.45.615355 (d5698f682d8b2742017df6c81e0bd8e6a3063189),platform=Mac OS X 10.14.2 x86_64)

I've tried to increase the allScriptsTimeout in the protractor.conf.ts file but to no avail.

app.e2e-spec.ts file

    it('should get the text of sign up button', () => {
      page.navigateTo();
      expect<any>(page.getButtonText()).toEqual('Sign up');
    });

app.po.ts

  getButtonText() {
    return element(by.css('a[data-e2e="nav-signup"]')).getText();
  }

  navigateTo() {
    return browser.get('/');
  }

What might I be doing wrong here?


回答1:


Updated some syntax and removed async/awaits from page object function.

As I mentioned your failure is likely due to an async issue. Can you try changing your code to disable the promise_manager in the conf and use the async/await syntax and see if that helps you?

a previous answer of mine on the subject of the async/await & the promise manager

Every action that interacts with the browser will need an await before it and every function that contains an await will need to be labeled async

Conf.js

exports.config = {
    framework: 'jasmine',
    specs: ['./app.js'],
    // specs: ['./app.js','./app.1.js'],
    seleniumAddress: 'http://localhost:4444/wd/hub',
    SELENIUM_PROMISE_MANAGER: false
}

Page Object

getButtonText() {
  return element(by.css('a[data-e2e="nav-signup"]')).getText();
}

navigateTo() {
  return browser.get('/');
}

Spec File

it('should get the text of sign up button', async () => {
  await page.navigateTo();
  expect(await page.getButtonText()).toEqual('Sign up');
});


来源:https://stackoverflow.com/questions/54421734/protractor-unable-to-find-elements-and-script-timeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!