从“量角器"错误导入{浏览器,元素,由,按,$,$$,ConditionalConditions} [英] import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor' error

查看:38
本文介绍了从“量角器"错误导入{浏览器,元素,由,按,$,$$,ConditionalConditions}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在全局和本地安装了量角器,打字稿,茉莉花. 通过npm install运行测试时出现以下错误,请指导安装是否有任何问题.

I have installed Protractor, typescript, jasmine with type globally and also locally. Getting following error while running the test via npm install, please guide if anything wrong with the setup.

import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor';
^^^^^^
SyntaxError: Unexpected token import
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at C:\MyFiles\NewTechonologies\Protractor\TypeScript\Test\node_modules\jasmine\lib\jasmine.js:93:5
[13:14:56] E/launcher - Process exited with error code 100
npm ERR! Test failed.  See above for more details. 

下面是我在Visual Studio代码中使用的文件的详细信息

Below are the details of files I am using in visual studio code

Conf.ts

import {Config} from 'protractor';

export let config: Config = {

  framework: 'jasmine',
  capabilities: {
    browserName: 'chrome'
  },
  specs: [ '../spec.ts' ],
   onPrepare: () => {
     let globals = require('protractor');
   let browser = globals.browser;
   browser.manage().window().maximize();
   browser.manage().timeouts().implicitlyWait(5000);
    // doing a browser.get will lead to a transpile error. 
    // undefined does not have a get method
  },
  seleniumAddress: 'http://localhost:4444/wd/hub',

  // You could set no globals to true to avoid jQuery '$' and protractor '$'
  // collisions on the global namespace.
  noGlobals: true
};

spec.ts

import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor';
//import { ElementFinder, browser, by, element } from 'protractor';
import protractor = require('protractor');

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

  it('should greet the named user', async() => {
    setTimeout(function() {
    // Whatever you want to do after the wait
}, 4000);
    element(by.model('yourName')).sendKeys('Julie');
    let greeting = element(by.binding('yourName'));
   // expect(greeting.getText()).toEqual('Hello Julie!');
   expect<any>(greeting.getText()).toEqual('Hello Julie!');
  });

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

package.json

{
  "name": "example-typescript",
  "version": "1.0.0",
  "description": "a typescript example",
  "author": "",
  "license": "MIT",
  "scripts": {
    "tsc": "tsc",
    "pretest": "npm run tsc",
    "test": "protractor tmp/conf.js"
  },
  "dependencies": {
    "@types/jasmine": "^2.5.47",
    "@types/jasminewd2": "^2.0.0",
    "jasmine": "^2.4.1",
     "protractor": "file:../",
    "typescript": "~2.1.6"
  },
  "devDependencies": {
    "@types/jasmine": "^2.5.51",
    "@types/jasminewd2": "^2.0.2",
    "ts-node": "^3.0.2"
  }

推荐答案

根据评论讨论,我已将conf.ts内容从<.>/spec.ts更改为spec.js ,并工作正常

As per the comment discussions, i have changed the conf.ts content from ../spec.ts to spec.js and worked fine

conf.ts

import {Config, browser} from 'protractor';
export let config: Config = {

  framework: 'jasmine',
  capabilities: {
    browserName: 'chrome',
    chromeOptions: {
            'args': ['disable-infobars']
        }
  },

  specs: [ 'spec.js' ],
   onPrepare: () => {
     let globals = require('protractor');
   let browser = globals.browser;
   browser.ignoreSynchronization = true;
   browser.manage().window().maximize();
   browser.manage().timeouts().implicitlyWait(5000);
  },
  seleniumAddress: 'http://localhost:4444/wd/hub',
  noGlobals: true
};

这篇关于从“量角器"错误导入{浏览器,元素,由,按,$,$$,ConditionalConditions}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆