打字稿设置问题中的量角器

时间:2017-06-07 14:43:28

标签: typescript protractor visual-studio-code

尝试使用打字稿运行量角器,但出现以下错误

C:\MyFiles\NewTechonologies\Protractor\TypeScript\Test>npm install
npm ERR! not a package C:\Users\skp\AppData\Roaming\npm\node_modules\protractor\bin\protractor
npm ERR! addLocal Could not install C:\Users\skp\AppData\Roaming\npm\node_modules\protractor\bin\protractor
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "
install"
npm ERR! node v6.10.3
npm ERR! npm  v3.10.10
npm ERR! path C:\Users\skp\AppData\Local\Temp\npm-8952-eac08724\unpack-b2acb3b1\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\skp\AppData\Local\Temp\npm-8952-eac08724\unpac
k-b2acb3b1\package.json'
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\skp\AppData\Local\Temp\npm-8952-eac08724\unpac
k-b2acb3b1\package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR!     C:\MyFiles\NewTechonologies\Protractor\TypeScript\Test\npm-debug.log

我的设置就像 config.ts

的package.json

{
  "name": "example-typescript",
  "version": "1.0.0",
  "description": "a typescript example",
  "author": "",
  "license": "MIT",
  "scripts": {
    "tsc": "tsc",
    "pretest": "npm run tsc",
    "test": "C:/Users/skp/AppData/Roaming/npm/node_modules/protractor/bin/protractor tmp/conf.js",
   "debug": "node --inspect --debug-brk C:/Users/skp/AppData/Roaming/npm/node_modules/protractor/bin/protractor asyncAwait/conf.js"
  },
  "dependencies": {
    "@types/jasmine": "2.5.41",
    "@types/jasminewd2": "^2.0.0",
    "jasmine": "^2.4.1",
    "protractor": "C:/Users/skp/AppData/Roaming/npm/node_modules/protractor/bin/protractor",
    "typescript": "~2.0.0"
  },
  "devDependencies": {
    "@types/jasminewd2": "^2.0.0",
    "ts-node": "^3.0.2"
  }
}

spec.ts

import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor';

describe('protractor with typescript typings', () => {
  beforeEach(() => {
    browser.get('http://www.angularjs.org');
  });

  it('should greet the named user', () => {
    element(by.model('yourName')).sendKeys('Julie');
    let greeting = element(by.binding('yourName'));
    expect(greeting.getText()).toEqual('Hello Julie!');
  });

  it('should list todos', function() {
    let todoList = element.all(by.repeater('todo in todoList.todos'));
    expect(todoList.count()).toEqual(2);
    expect(todoList.get(1).getText()).toEqual('build an angular app');
  });
});

tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
    "inlineSourceMap": true,
    "declaration": false,
    "noImplicitAny": false,
    "outDir": "tmp"
  },
  "exclude": [
    "node_modules",
    "asyncAwait",
    "plugins.ts"
  ]
}

我在全球范围内安装了量角器,茉莉花,打字稿。 仍然会出现上述错误,conf.ts也会在量角器文本上引发错误,如图所示 请指导设置出错的地方。

2 个答案:

答案 0 :(得分:0)

由于您已在全局安装了上述模块,因此它们应该在没有npm安装的情况下工作。

尽管如此,您应该在package.json中将这些模块作为依赖项。这显然是一个路径问题,npm无法在npm install期间找到量角器模块。

您有2个选项 -

  • 更正package.json中的本地量角器路径

    "dependencies": {
    "@types/jasmine": "2.5.41",
    "@types/jasminewd2": "^2.0.0",
    "jasmine": "^2.4.1",
    "protractor": "C:/Users/skp/AppData/Roaming/npm/node_modules/protractor",
    "typescript": "~2.0.0"
    },
    
  • 提及package.json中的量角器版本,就像你对其余模块所做的一样

    "dependencies": {
    "@types/jasmine": "2.5.41",
    "@types/jasminewd2": "^2.0.0",
    "jasmine": "^2.4.1",
    "protractor": "^5.1.1",
    "typescript": "~2.0.0"
    },
    

现在如果你运行``npm install`,它应该成功安装依赖项。

答案 1 :(得分:0)

提供依赖后,您必须运行npm install

//conf.ts
// An example configuration file.
exports.config = {
  directConnect: true,

  // Capabilities to be passed to the webdriver instance.
  capabilities: {
    'browserName': 'chrome'
  },

  // Framework to use. Jasmine is recommended.
  framework: 'jasmine',

  // Spec patterns are relative to the current working directory when
  // protractor is called.
  //specs: ['../Tests/LoginTestCases.js'],



  // Options to be passed to Jasmine.
  jasmineNodeOpts: {
    defaultTimeoutInterval: 30000
  }
};


//Package.json
{
  "name": "newprotractor",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@types/jasmine": "2.8.7",
    "@types/jasminewd2": "2.0.3",
       "@types/node": "12.12.2",
    "jasmine": "3.5.0",
       "protractor": "^5.4.2",
    "protractor-jasmine2-html-reporter": "^0.0.7",
    "ts-node": "8.5.4",
    "typescript": "3.4.3",
    }
}

使用命令npm install,量角器将为当前项目安装,然后错误将消失