在使用控制流完成异步操作后导航回webdriver方法后,获取控制流错误

时间:2016-06-28 02:59:56

标签: angularjs protractor angular-promise control-flow

当我的Protractor脚本从异步方法转移到正常的webdriver操作时,它失败并给我错误:

  

失败:在等待Protractor与页面同步时,无法分配给只读属性'stack'的错误:“[ng:test]找不到针对getTestability的元素参数的注入器\ nhttp://errors.angularjs.org /1.4.1/ng/test”   堆:      在C:\ Users \ DELL pc \ AppData \ Roaming \ npm \ node_modules \ protractor \ built \ element.js:377:21           在Promise.invokeCallback_(C:\ Users \ DELL pc \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:1329:14)           在TaskQueue.execute_(C:\ Users \ DELL pc \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:2790:14)           在TaskQueue.executeNext_(C:\ Users \ DELL pc \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:2773:21)           在C:\ Users \ DELL pc \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:2652:27           在C:\ Users \ DELL pc \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ promise.js:639:7           at process._tickCallback(node.js:369:9)       发件人:任务:在控制流程中运行它(“应该能够重置密码”)           在对象。 (C:\ Users \ DELL pc \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ jasminewd2 \ index.js:81:14)       从异步测试:       错误           在套房。 (E:\ newworkspace \ TestAngularpjt \ SRC \的TestCases \ ForgotPasswordForPosse.js:17:2)           在对象。 (E:\ newworkspace \ TestAngularpjt \ SRC \的TestCases \ ForgotPasswordForPosse.js:3:1)           在Module._compile(module.js:409:26)           at Object.Module._extensions..js(module.js:416:10)           在Module.load(module.js:343:32)           在Function.Module._load(module.js:300:12)

以下是我的测试用例的代码:

    var mailFile= require("../commonUtils/mailFile.js");

describe('Test the Reset flow', function(){

var forgotPswdLink = element(by.css('[ng-click="ForgotPassword()"]'));
//var emailField = element(by.xpath("//*[@class='subtitle']/following-sibling::input"));
var emailField = element(by.model("password_reset['username']"));
//var resetpswdBtn = element(by.xpath('//button[text()="Reset password"]'));
var resetpswdBtn = element(by.xpath('//button[text()="Send reset link"]'));
var paswdResendMsg = element(by.css('.email-notification'));
var newPwdOne = element(by.model("password_reset['newPassword']"));
var newPwdTwo = element(by.model("password_reset['newPasswordConfirmation']"));
var submitButton = element(by.id('submit'));

var mailFi = new mailFile();

it('should be able to reset password', function(){
    var flow = protractor.promise.controlFlow();
    var emailAdd= "usernew@mailosaur.io";

    browser.get('https://secure.testurl.com/forgot-password');

    emailField.sendKeys(emailAdd);
    resetpswdBtn.click();
    expect(paswdResendMsg.getText()).toEqual('An email with instructions will be sent to the email address for this account.');

    function emailTokenValues(){

    var Mailosaur = require("mailosaur")("Your_API_key");
    var mailbox = new Mailosaur.Mailbox("MailboxId");

    console.log("Here it begins!");
    var deferred = protractor.promise.defer();
    mailbox.getEmailsByRecipient(emailAdd, function(err, emails) {

    err;
    var htmlBody = emails[0].html.body;
    var regEx = "token=[A-Z|a-z|0-9|%]+";
    var myArray = htmlBody.match(regEx);

    //var tokenVal = myArray[0].split("=");

    console.log(myArray[0]);

    var defaultUrl= "https://secure.testurl.com/reset-password?"

    var newURL = defaultUrl+myArray[0];
    console.log(newURL);
    browser.get(newURL);

    //console.log(emails[0].html.body);

    console.log("Are you even going inside?");
    return deferred.fulfill();

});
deferred.promise;
browser.sleep(5000);
}

flow.execute(emailTokenValues);

newPwdOne.sendKeys('Welcome@123');
newPwdTwo.sendKeys('Welcome@123');
submitButton.click();   
});});

一旦“flow.execute(emailTokenValues)”被执行,那么在寻找执行“newPwdOne.sendKeys('Welcome @ 123')时,它会给出错误;”操作。有什么建议我在这里做错了吗?

0 个答案:

没有答案