![](/img/trans.png)
[英]Tests of a non-angular page with protractor cannot click on a link element
[英]Angular 2 - Protractor Tests: Cannot find name 'element' and 'name'
惠,
我创建了app.e2e-spec.ts文件来创建单元测试:
import {} from 'jasmine';
import {} from 'protractor';
describe('Testing login button disable if empty input texts', function() {
it('should username have null value', function() {
var inputsLogin = element(by.name('username'));
expect<any>(inputsLogin.getAttribute('value')).toBe(null);
});
it('should password have null value', function() {
var inputsPassword = element(by.name('password'));
expect<any>(inputsPassword.getAttribute('value')).toBe(null);
});
it('should login button disable', function() {
var loginButton = element(by.id('button-confirm'));
expect<any>(loginButton.getAttribute('disabled')).toBe("true");
});
});
单元测试工作但问题是,当我运行tsc
命令时,我得到这些错误:
tests/tests-e2e/app.e2e-specs.ts(10,27): error TS2304: Cannot find name 'element'.
tests/tests-e2e/app.e2e-specs.ts(10,35): error TS2304: Cannot find name'by'
tests/tests-e2e/app.e2e-specs.ts(15,30): error TS2304: Cannot find name'element'
...
但我有时可以运行我的测试,因为Intellj为我创建了js
我的tsconfig.js:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2015"
],
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"./node_modules/@types/"
]
},
"include": [
"src/**/*.ts",
"tests/**/*.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
您将导入语句留空了。
import {by, element} from 'protractor';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.