我有以下代码,它往往会在单个输入表单中输入验证码。
该表单是角度应用程序注册过程的一部分,该应用程序将检查验证码与mySQL表中写入的验证码相同。
在验证之前有一个前一个表单,它有多个输入(名字,姓氏,电话和密码),下一个按钮进入验证过程。
所有网页元素都已成功找到,注册功能正在使用q
按顺序执行所有操作。
以下是代码:
.then(function() {
return signupModalButton.click(); // The next button on the first form
})
.then(function() {
return common.waitForElementToBeVisible(signupModalCode); // Wait for the code input to be visible
})
.then(function() {
return getVerificationCodeFromDatabase(phoneUsed); // Read the code from mySQL database
})
.then(function(code) {
console.log('Got verification code: ' + code); // Logs correctly
signupModalCode.sendKeys(code); // No keys get sent to the text box event if I change this to:
//signupModalCode.sendKeys('test');
browser.wait(function() {
var ec = protractor.ExpectedConditions;
return ec.textToBePresentInElement(signupModalCode);
}, config.WAITING_TIMEOUT); // Same output with or without this browser.wait
signupModalCode.getText().then(function(text) {
console.log('text inside element: ' + text);
}) // Nothing gets logged
console.log('Entered code...'); // Gets logged!
return signupModalButton.click(); // Doesn't happen
})
.then(function() { // Code doesn't reach here
console.log('Promise resolved...'); // Doesn't get logged
})
当测试运行时,我可以看到文本框但是我看到没有文本输入,然后浏览器关闭,控制台中会出现以下错误:
C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:108
var template = new Error(this.message);
^
UnknownError: Session ID is null. Using WebDriver after calling quit()?
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'Morbid-PC', ip: '169.254.67.136', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_72'
Driver info: driver.version: EventFiringWebDriver
at new bot.Error (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:108:18)
at Object.bot.response.checkResponse (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\response.js:109:9)
at C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:379:20
at [object Object].promise.ControlFlow.runInFrame_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1857:20)
at [object Object].goog.defineClass.notify (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2448:25)
at [object Object].promise.Promise.notify_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:564:12)
at Array.forEach (native)
at [object Object].promise.Promise.notifyAll_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:553:15)
at goog.async.run.processWorkQueue (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:130:15)
at runMicrotasksCallback (node.js:337:7)
Error
at [object Object].ElementArrayFinder.applyAction_ (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\lib\element.js:392:21)
at [object Object].self.(anonymous function) [as sendKeys] (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\lib\element.js:76:19)
at [object Object].self.(anonymous function) [as sendKeys] (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\lib\element.js:721:11)
at C:\Users\ramtin\trooptraining\troop\troop-web\test\protractor\assets\lib-auth.js:224:23
at [object Object].promise.ControlFlow.runInFrame_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1857:20)
at [object Object].goog.defineClass.notify (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2448:25)
at [object Object].promise.Promise.notify_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:564:12)
at Array.forEach (native)
at [object Object].promise.Promise.notifyAll_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:553:15)
at goog.async.run.processWorkQueue (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:130:15)
From: Task: WebDriver.quit()
at [object Object].webdriver.WebDriver.schedule (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:362:15)
at [object Object].webdriver.WebDriver.quit (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:445:21)
at C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\lib\driverProviders\driverProvider.js:59:14
at [object Object].promise.ControlFlow.runInFrame_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1857:20)
at [object Object].goog.defineClass.notify (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2448:25)
at [object Object].promise.Promise.notify_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:564:12)
at Array.forEach (native)
at [object Object].promise.Promise.notifyAll_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:553:15)
at goog.async.run.processWorkQueue (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:130:15)
at runMicrotasksCallback (node.js:337:7)
[launcher] Process exited with error code 1
我无法弄清楚访问这个文本框有什么问题,以及量角器如何跳过与该文本框相关的问题。
任何帮助都将不胜感激。
答案 0 :(得分:3)
我认为您必须嵌套回调:
.then(function() {
return signupModalButton.click().then(function() {
return common.waitForElementToBeVisible(signupModalCode).then(function() {
return getVerificationCodeFromDatabase(phoneUsed).then(function(code) {
// etc...
});
});
});
});
或者,不要明确解决承诺,让Control Flow处理它。