使用以下命令执行测试:
ng e2e --port 4200
给我一个错误:
- Failed: No element found using locator: By(css selector, *[id="login-form"])
我的剧本:
app.e2e-spec.ts
import { AppPage } from './app.po';
import {browser, by, element} from 'protractor';
describe('nameProject App', () => {
let page: AppPage;
beforeAll(() => {
page = new AppPage();
browser.waitForAngularEnabled(false);
page.navigateTo();
const formLogin = page.showFormLogin();
const login = page.fillFormAndSendLogin(formLogin);
browser.sleep(19000);
browser.waitForAngularEnabled(true);
});
beforeEach(() => {
});
it('should display welcome message', () => {
});
});
app.po.ts:
import { browser, by, element } from 'protractor';
export class AppPage {
navigateTo() {
return browser.get('/user/login');
}
fillFormAndSendLogin(form) {
const user_data_login_password = 'www'; form.element(by.css('input[name=userName]')).sendKeys(user_data_login_password);
form.element(by.css('input[name=password]')).sendKeys(user_data_login_password);
form.element(by.buttonText('Login')).click();
return user_data_login_password;
}
getLoginBtn() {
return element(by.buttonText('Login'));
}
getFormLogin() {
return element(by.id('login-form'));
}
click_login() {
const btnLoginItem = this.getLoginBtn();
btnLoginItem.click();
}
showFormLogin() {
return this.getFormLogin();
}
}
登录正常,因为我有一个正在运行的服务器,我将执行ng build
命令
登录表单
<div class="panel-body">
<form id='login-form' class="example-form" [formGroup]="loginForm" >
<label for="name">Name user *</label>
<input required type="text" class="form-control" formControlName="userName" name ="userName" required>
<label for="name">Password *</label>
<input required type="password" class="form-control" formControlName="password" name ="password" required>
<button type="submit" (click)="login()" class="btn btn-success" id="Login" title="Login">Login</button>
</form>
</div>
我使用MongoDB数据库。 MongoDB数据库适用于localhost:4200
。该应用也适用于localhost:4200
。
在浏览器中,它会向我显示此消息:
Error: ENOENT: no such file or directory, stat 'd:\name-project\dist\index.html'
我不知道如何修复此错误。
答案 0 :(得分:0)
命令帮助:
ng e2e --delete-output-path=false