嗨,当我在使用带有angular cli的protractor typescript时,我遇到了以下错误:“无法读取未定义的属性'sendUsername'”。我是typescript的新手,请建议我如何解决这个问题。
错误
失败:无法读取未定义的属性'sendUsername'
app.e2e-spec.ts
import { PatientInquiryPrototypePage } from './patiq-common.po';
import { LoginAdmin } from './patiq-login.po';
describe('patient-inquiry-prototype App', () => {
let page: PatientInquiryPrototypePage;
let loginAdmin: LoginAdmin;
beforeEach(() => {
page = new PatientInquiryPrototypePage();
});
it('Launch the Test URL', () => {
page.navigateTo();
});
it('Login as Administrator', () => {
loginAdmin.sendUsername('PILabAdmin');
loginAdmin.sendPassword('password$123');
loginAdmin.openHostSystem();
loginAdmin.selectHostSystem();
loginAdmin.openHostRole();
loginAdmin.selectHostRole();
});
});
patiq-login.po.ts
import { browser, by, element, protractor, ExpectedConditions, $, $$ } from 'protractor';
export class LoginAdmin {
sendUsername(Username: string) {
return element(by.css('[formcontrolname="username"]')).sendKeys(Username);
}
sendPassword(Password: string) {
return element(by.css('[formcontrolname="password"]')).sendKeys(Password);
}
openHostSystem() {
return element(by.css('[formcontrolname="hostSystem"]')).click();
}
selectHostSystem() {
return element(by.css('[class="mat-option"]')).get(0).click();
}
openHostRole() {
return element(by.css('[formcontrolname="hostRole"]')).click();
}
selectHostRole() {
return element(by.css('[class="mat-option"]')).get(6).click();
}
}