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

时间:2015-03-27 06:04:50

标签: angularjs angularjs-e2e

我是e2e测试的新手,我正在为我的角度应用编写e2e测试用例。在这里,我正在创建一名患者,我想为同一位患者预约。 这是代码

 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?

1 个答案:

答案 0 :(得分:0)

// 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);
});