Input 如何接受用户的实时输入
我正在尝试使用量角器自动化我的应用程序测试。在登录应用程序时,我需要输入我在手机中收到的密码。我正在尝试使用javascript的“prompt”命令来实时接受来自tester的密码。但是我犯了个错误 “ReferenceError:未定义提示” 我怎样才能解决这个问题 有没有其他方法可以让Ⅸ接受来自测试仪的实时用户输入 使用的命令:Input 如何接受用户的实时输入,input,protractor,real-time,Input,Protractor,Real Time,我正在尝试使用量角器自动化我的应用程序测试。在登录应用程序时,我需要输入我在手机中收到的密码。我正在尝试使用javascript的“prompt”命令来实时接受来自tester的密码。但是我犯了个错误 “ReferenceError:未定义提示” 我怎样才能解决这个问题 有没有其他方法可以让Ⅸ接受来自测试仪的实时用户输入 使用的命令: prompt('Enter the passcode from your mobile', '') 我确实设法获得了您正在使用的功能的一个版本,包括async/
prompt('Enter the passcode from your mobile', '')
我确实设法获得了您正在使用的功能的一个版本,包括async/await和promise manager方法 选项1-从浏览器提示获取值(异步/等待) 使用Promise manager添加了备选方案 根据您的评论,我可以看出您正在使用promise manager,因此我也为该方法提供了一个答案。但是,我强烈建议您在框架中使用异步/等待方法
let getValueFromUserViaPrompt = () => {
browser.executeScript("window.promptPasscode=prompt('Please enter your passcode','default')");
//verify that the prompt is displayed
browser.wait(EC.alertIsPresent(), 3000, 'alert is not present');
browser.wait(() => {
//if alert is still present on page then return false so main browser.wait will check again.
return browser.wait(EC.alertIsPresent(), 500)
.then(() => false)
.catch(() => true);
}, 30 * 1000, 'Alert has not been closed');
//return the prompt value
return browser.executeScript("return window.promptPasscode");
}
getValueFromUserViaPrompt().then(res => {
console.log(res);
})
请添加一个。谢谢。这是一个有趣的问题,我尝试了一些类似于
wait browser.executeScript(“返回提示('please enter value'))的方法
但无法按预期工作此密码是否在短时间内更改?是的。每次登录时,我都会收到一个需要输入的新密码。登录过程类似于。1.我需要提供我的用户id和密码,然后单击登录按钮2。将显示一个新页面,要求我选择要将密码发送到的位置(邮件/手机)3。将显示一个新页面,要求我输入我收到的密码(通过邮件或手机)我的代码:element(by.name(“用户名”)).sendKeys('XXXXX');元素(按名称(“密码”)).sendKeys('XXXXX');元素(by.buttonText('Sign-In'))。单击();browser.wait(EC.url包含'XXXX',9000);元素(by.linkText(“将密码发送到我的手机”))。单击();browser.wait(EC.visibilityOf(element)(by.id(“otppswd”))),9000。然后(function(){prompt('Enter the passcode from your mobile','')。然后(function(passcode){element(by.id(“otppswd”))。sendKeys(passcode);element(by.buttonext('Submit')。click();})
let getValueFromUserViaPrompt = () => {
browser.executeScript("window.promptPasscode=prompt('Please enter your passcode','default')");
//verify that the prompt is displayed
browser.wait(EC.alertIsPresent(), 3000, 'alert is not present');
browser.wait(() => {
//if alert is still present on page then return false so main browser.wait will check again.
return browser.wait(EC.alertIsPresent(), 500)
.then(() => false)
.catch(() => true);
}, 30 * 1000, 'Alert has not been closed');
//return the prompt value
return browser.executeScript("return window.promptPasscode");
}
getValueFromUserViaPrompt().then(res => {
console.log(res);
})