【发布时间】:2018-04-16 12:05:43
【问题描述】:
使用命令执行测试:
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'
我不知道如何解决这个错误。
【问题讨论】:
-
您的表格有问题吗?我的意思是
*ngIf -
我不在此表单上使用
*ngIf -
在浏览器中,它会向我显示这条消息:
Error: ENOENT: no such file or directory, stat 'd:\name-project\dist\index.html' -
所以你的问题是构建后的?
-
在控制台中:
Failed to load resource: the server responded with a status of 404 (Not Found) login Failed to load resource: the server responded with a status of 404 (Not Found)但是如何通过命令ng build运行应用程序这个登录有效
标签: angular e2e-testing