如何禁用量角器中的动画? [英] How to disable animations in protractor?
问题描述
我在Google上找到了一些答案,但是它们似乎不适用于我的项目.
I've found some answers on google, but they don't seem to be applicable to my project.
一些答案涉及将一些代码添加到其conf.js
文件的onPrepare()
函数中,但是我的项目中没有该文件.我有一个名为protractor.config.js
的文件,默认情况下该文件位于angular快速入门项目中.无论如何,此配置文件还具有onPrepare()
函数,因此我尝试在此问题中添加答案2中的代码:
Some of the answers talked about adding some code to their conf.js
file's onPrepare()
function, but I don't have that file in my project. I have a file named protractor.config.js
, which was in the angular quickstart project by default. Anyway, this config file also has an onPrepare()
function, so I tried to add the code from answer #2 in this question: How to disable animations in protractor for angular js application, but then my tests failed with:
message: Failed: Trying to load mock modules on an Angular2 app is not yet supported.
推荐答案
我设法使用查询参数来做到这一点.
I managed to accomplish this using a query parameter.
以Neils为基础,我能够更新SharedModule以在BrowserAnimationModule
和NoopAnimationModule
之间切换.
Building on Neils answer I was able to update my SharedModule to switch between BrowserAnimationModule
and NoopAnimationModule
.
我创建了一个添加查询参数的方法,稍后我将寻找它.我将这种方法用于测试中的所有导航,因此可以确保该参数始终存在.
I created a method that appends a query parameter that I will look for later. I use this method for all navigation in my tests so I can be sure the parameter is always present.
E2eCommon
public static navigateTo(path: string) {
browser.get('/' + path + '?qa=true');
browser.waitForAngular();
}
然后在我声明动画模块的模块中,我检查查询参数,并根据是否存在该参数加载BrowserAnimationModule
或NoopAnimationModule
Then in my module where I declare the animation module I check for the query parameter and based on whether or not it's present I either load BrowserAnimationModule
or NoopAnimationModule
shared.module.ts
@NgModule({
declarations: [
...
],
exports: [
AnimationModule(),
...
],
imports: [
AnimationModule(),
...
]
})
export class SharedModule { }
export function AnimationModule(): any {
return window.location.search.indexOf('qa=true') > -1 ? NoopAnimationsModule : BrowserAnimationsModule;
}
这篇关于如何禁用量角器中的动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!