量角器-无法获取URL标题,Webdriver只是挂起

时间:2018-11-01 11:27:26

标签: automation protractor ui-automation browser-automation

刚开始为即将到来的项目使用Protractor,可能需要在基于角度的网站上进行前端自动化。在安装了Protractor并运行了给定的示例之后,尝试做一个非常简单的测试,如下所示:

// test.js
describe('Protractor Demo App', function() {
    it('should have a title', function() {
      browser.get('http://www.google.co.uk');
      expect(browser.getTitle()).toEqual('Google');
    });
  }); 

问题是,浏览器会打开,但随后会挂起,直到出现错误:

Failures:
1) Protractor Demo App should have a title
  Message:
    Failed: Cannot read property 'ver' of null
  Stack:
    TypeError: Cannot read property 'ver' of null
        at executeAsyncScript_.then (/usr/local/lib/node_modules/protractor/built/browser.js:716:56)
        at ManagedPromise.invokeCallback_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1376:14)
        at TaskQueue.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:3084:14)
        at TaskQueue.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:3067:27)
        at asyncRun (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2927:27)
        at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:668:7
        at process.internalTickCallback (internal/process/next_tick.js:77:7)
    From: Task: Run it("should have a title") in control flow
        at UserContext.<anonymous> (/usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:94:19)
    From asynchronous test:
    Error
        at Suite.<anonymous> (/Users/rubensantos/Documents/protractor/test.js:3:5)
        at Object.<anonymous> (/Users/rubensantos/Documents/protractor/test.js:2:1)
        at Module._compile (internal/modules/cjs/loader.js:707:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
        at Module.load (internal/modules/cjs/loader.js:605:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:544:12)

1 spec, 1 failure
Finished in 4.056 seconds

[11:18:25] I/launcher - 0 instance(s) of WebDriver still running
[11:18:25] I/launcher - chrome #01 failed 1 test(s)
[11:18:25] I/launcher - overall: 1 failed spec(s)
[11:18:25] E/launcher - Process exited with error code 1

不知道为什么这个简单的测试不起作用。欢迎任何帮助,在此先感谢

1 个答案:

答案 0 :(得分:0)

由于此thread,禁用Control Flow是一个不错的决定。在您的protractor.conf.js文件中,添加SELENIUM_PROMISE_MANAGER: false行。之后,您应该自己解决Promises。例如,您的测试将如下所示:

describe('Protractor Demo App', function() {
    it('should have a title', async function() {
      await browser.get('http://www.google.co.uk');
      expect(await browser.getTitle()).toEqual('Google');
    });
  }); 
相关问题