Angular CLI教程

Angular CLI ng e2e 命令

本章解释了 ng e2e 命令的语法、参数和选项以及一个例子。这里,e2e 是指端到端。

语法

ng e2e 命令的语法如下-
ng e2e <project> [options]
ng e <project> [options]
ng e2e 构建、提供应用程序,然后使用量角器运行端到端测试用例。选项是可选参数。

参数

ng e2e 命令的参数如下-
参数和语法 描述
<project> 要测试的项目名称。

选项

选项是可选参数。
选项和语法 描述
--baseUrl=baseUrl 量角器要连接的基本 URL。
--configuration=configuration
一个命名的构建目标,在 angular.json 的"配置"部分中指定。每个命名的目标都伴随着该目标的选项默认配置。明确设置此项会覆盖"--prod"标志
别名:-c
--devServerTarget=devServerTarget 用于运行测试的开发服务器目标。
--grep=grep 执行名称与模式匹配的规范,该规范在内部编译为 RegExp。
--help=true|false|json|JSON
在控制台中显示此命令的帮助消息。
默认值:false
--host=host 主持人收听。
--invertGrep=true|false
反转'grep'选项指定的选择。
默认值:false
--port 用于为应用程序提供服务的端口。
--prod=true|false "--configuration=production"的简写。当为 true 时,将构建配置设置为生产目标。默认情况下,生产目标是在工作区配置中设置的,以便所有构建都使用捆绑、有限的 tree-shaking 和有限的死代码消除。
--protractorConfig=protractorConfig 量角器配置文件的名称。
--specs 覆盖量角器配置中的规范。
--suite=suite 覆盖量角器配置中的套件。
--webdriverUpdate=true|false
尝试更新网络驱动程序。
默认:true
首先转到使用 ng build 命令更新的 angular 项目。该命令可在 https://www.lidihuo.com/angular_cli/angular_cli_ng_build.htm。
现在运行 e2e 命令。

示例

下面给出了 ng e2e 命令的示例-
\>Node\>Lidihuo> ng e2e
...
chunk {main} main.js, main.js.map (main) 14.3 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 141 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 12.4 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 3 MB [initial] [rendered]
Date: 2020-06-06T04:20:15.029Z-Hash: 16f321e3d4599af26622-Time: 20899ms
** Angular Live Development Server is listening on localhost:4200, open your bro
wser on http://localhost:4200/ **
: Compiled successfully.
...
   workspace-project App
    x should display welcome message
     -Failed: No element found using locator: By(css selector, app-root .content span)
   ...
      From: Task: Run it("should display welcome message") in control flow
   ...
**************************************************
*                    Failures                    *
**************************************************
1) workspace-project App should display welcome message
 -Failed: No element found using locator: By(css selector, app-root .content span)
Executed 1 of 1 spec (1 FAILED) in 2 secs.
现在修复失败更新 app.component.html
app.component.html
<div class="content" role="main">
   <span>{{ title }} app is running!</span>
</div>
<app-goals></app-goals>
<router-outlet></router-outlet>
现在运行 e2e 命令。

示例

下面给出了 ng e2e 命令的示例-
\>Node\>Lidihuo> ng e2e
...
chunk {main} main.js, main.js.map (main) 14.9 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 141 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 12.4 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 3 MB [initial] [rendered]
Date: 2020-06-06T04:28:33.514Z-Hash: 5d8bf2fc7ff59fa390b0-Time: 10529ms
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
: Compiled successfully.
...
   workspace-project App
      √ should display welcome message
Executed 1 of 1 spec SUCCESS in 2 secs.
ng e2e 还会打开浏览器并使用它来运行使用 UI 的验收测试用例。
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4