我们有一个Angular 1.5应用程序,它有一个登录屏幕,在应用程序代码和我们的测试中没有任何改变.我们使用量角器(与grunt-protractor等…)
版本:
版本:
"dependencies": { "async": "^0.9.0","chalk": "^1.1.1","fs-extra": "^0.24.0","grunt": "~0.4.5","grunt-contrib-jshint": "^0.10.0","grunt-protractor-runner": "^4.0.0","grunt-protractor-webdriver": "^0.2.5","jshint-stylish": "^1.0.0","load-grunt-tasks": "~3.1.0","lodash": "^2.4.1","log4js": "^0.6.21","protractor": "^4.0.11","selenium-webdriver": "^3.0.1" }
我们所有的测试都采用以下格式:
>登录应用程序并睡觉
>测试(它).每个它都获得done()函数,该函数在测试结束时从browser.sleep(‘1000’)调用.然后(完成)promise(jasmine语法).
describe('login',function () { browser.get('/'); components.login.loginDefault(); console.log('done login'); browser.driver.manage().window().maximize(); // just in case the driver wont reach the '.add-new-type' button browser.sleep(1000); }); describe('post login',function () { it('just a test for after user loged in',function (done) { console.log('post login'); const ec = protractor.ExpectedConditions; const getStarted = element(by.css('.add-new-type')); // just a button appears on the next page console.log('getStarted ' + JSON.stringify(getStarted)); browser.wait(ec.elementToBeClickable(getStarted),5000); console.log('post wait'); browser.sleep(5000).then(done); })});
我们没有更改依赖项版本或在我们的环境中没有任何内容,突然没有任何工作,测试只通过登录阶段然后失败,因为没有找到元素(我猜)并且卡住直到jasmine抛出超时异常
Session created: count=1,browserName=chrome,chromeOptions={args=[--no-sandBox,--test-type=browser,--disable-extensions],prefs={download={default_directory=./e2e/tmp,prompt_for_download=false}}} node path changed done login Started post login F
登录后测试只是一个例子,我们尝试了其他方法让驱动程序等待“ExpectedConditions”.
如果我在控制台调试器(chrome)中查找元素,我将正确地获取元素…
我们还试图调试和打印repl模式
element(by.css('.add-new-type')).getText()
行为是一样的 – 没有/没有回应
请问有什么帮助!
解决方法
你有没有尝试过等待元素和网址?
'use strict'; var WaitUtils = function () { this.waitElement = function (element,timeout) { timeout = timeout || browser.params.time.long; var expected = protractor.ExpectedConditions; return browser.wait(expected.visibilityOf(element),timeout,"Element not found"); }; this.waitUrl = function (url,timeout) { timeout = timeout || browser.params.time.long; var expected = protractor.ExpectedConditions; return browser.wait(expected.urlContains(url),"URL has not contains "+url); }; }; module.exports = WaitUtils;