我是Angular和e2e的新手。我正在尝试从Angular随附的e2e默认模板开始。我对尝试运行做了一些小的修改。但是我的测试在by.Css
这里是app.po.ts
import { browser, by, element } from 'protractor';
export class AppPage {
navigateTo() {
return browser.get(browser.baseUrl) as Promise<any>;
}
getTitleText() {
return element(by.css('h4.caption-title')).getText() as Promise<string>;
}
}
下面是我正在使用的HTML
<div class="news-caption">
<h4 class="caption-title">App</h4>
</div>
这是我的app.e2e-spec.ts
,
import { AppPage } from './app.po';
import { browser, logging } from 'protractor';
describe('workspace-project App', () => {
let page: AppPage;
beforeEach(() => {
page = new AppPage();
});
it('should display app caption title', () => {
page.navigateTo();
expect(page.getTitleText()).toEqual('App');
});
afterEach(async () => {
// Assert that there are no errors emitted from the browser
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
expect(logs).not.toContain(jasmine.objectContaining({
level: logging.Level.SEVERE,
}));
});
});
但是,在此预期步骤中,测试始终失败。我会丢失任何东西还是使用错误的CSS选择器吗?