使用量角器在 sendKeys e2e 测试中传递变量

Pass a variable in sendKeys e2e testing using protractor

我是端到端测试的新手,我正在为我的 angular 应用程序编写端到端测试用例。在这里,我正在创建一个病人,我想为同一个病人预约。 这是代码

 it('Add Patient', function(){   

    var fname = element(by.model('newrecord.firstName')).sendKeys('Riaz');
    element( by.css('[ng-click="ok()"]') ).click();
});

it('Create Appointment', function(){ 

     element(by.model('newrecord.patientId')).sendKeys(fname);
});

我收到以下错误

ReferenceError: fname is not defined

如何将变量传递给sendKeys?

// Page Object
var recordPage = {
 firstNameElm: element(by.model('newrecord.firstName')),
 patientIdElm: element(by.model('newrecord.patientId')),
 okBtnElm:     element(by.css('[ng-click="ok()"]')),
};

// Test data
var testData = {
  patient: {
    idTxt: 'Riaz001',
    firstName: 'Riaz',
  },
};

it('adds patient', function() {
  recordPage.firstNameElm.sendKeys(testData.patient.firstName);
  recordPage.okBtnElm.click();
});

it('creates an appointment', function() {
  // not sure what you want to send here but should be text not an ElementFinder
  recordPage.patientIdElm.sendKeys(testData.patient.idTxt);
});