【问题标题】:Failed: No element found using locator: By(css selector, *[id="name-form"]) - ng e2e失败:使用定位器找不到元素:By(css selector, *[id="name-form"]) - ng e2e
【发布时间】: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


【解决方案1】:

该命令有帮助: ng e2e --delete-output-path=false

【讨论】:

    猜你喜欢
    • 2018-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-16
    • 2019-11-25
    • 1970-01-01
    • 2017-12-25
    • 1970-01-01
    相关资源
    最近更新 更多