要解决“Angular 9多应用端到端测试”的问题,可以按照以下步骤进行:
npm install -g @angular/cli
然后,可以使用以下命令创建多个应用程序:
ng new app1
ng new app2
cd app1
ng add @angular/material
ng add @nrwl/angular
ng add @nrwl/jest
cd app2
ng add @angular/material
ng add @nrwl/angular
ng add @nrwl/jest
cd app1
ng generate @nrwl/angular:app-e2e e2e-app1
cd app2
ng generate @nrwl/angular:app-e2e e2e-app2
这将在每个应用程序的根目录下创建一个名为“e2e-app1”和“e2e-app2”的文件夹。
import { AppPage } from './app.po';
import { browser, logging } from 'protractor';
describe('App1', () => {
let page: AppPage;
beforeEach(() => {
page = new AppPage();
});
it('should display welcome message', () => {
page.navigateTo();
expect(page.getParagraphText()).toEqual('Welcome to app1!');
});
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,
}));
});
});
类似地,在“e2e-app2”文件夹中的“app.e2e-spec.ts”文件中添加相应的测试代码。
cd app1
ng e2e
cd app2
ng e2e
这将启动Protractor并运行端到端测试。
通过按照上述步骤,您可以在Angular 9中创建多个应用程序的端到端测试,并在每个应用程序中编写相应的测试代码。