【问题标题】:angular2 + selenium webdriver: Can't resolve 'child_processangular2 + selenium webdriver:无法解析'child_process
【发布时间】:2017-04-24 18:05:27
【问题描述】:

我这样做了:

ng new typescript-selenium-example
npm install selenium-webdriver --save

(另外我已经将chromedriver复制到我的/Application

app.component.ts 更新为:

import { Component } from '@angular/core';
import { Builder, By, until } from 'selenium-webdriver';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor() {
    var driver = new Builder()
    .forBrowser('chrome')
    .build();

    driver.get('http://www.google.com/ncr')
        .then(_ => driver.findElement(By.name('q')).sendKeys('webdriver'))
        .then(_ => driver.findElement(By.name('btnG')).click())
        .then(_ => driver.wait(until.titleIs('webdriver - Google Search'), 1000))
        .then(_ => driver.quit());
    console.log('hi');
  }
  title = 'app works!';
}

出现错误:

ERROR in ./~/selenium-webdriver/net/portprober.js
Module not found: Error: Can't resolve 'child_process' in '/Users/myname/tmp/typescript-selenium-example/node_modules/sele
nium-webdriver/net'
 @ ./~/selenium-webdriver/net/portprober.js 20:11-35
 @ ./~/selenium-webdriver/chrome.js
 @ ./~/selenium-webdriver/index.js
 @ ./src/app/app.component.ts
 @ ./src/app/index.ts
 @ ./src/main.ts
 @ multi main

ERROR in ./~/selenium-webdriver/firefox/binary.js
Module not found: Error: Can't resolve 'child_process' in '/Users/myname/tmp/typescript-selenium-example/node_modules/sele
nium-webdriver/firefox'
 @ ./~/selenium-webdriver/firefox/binary.js 25:14-38
 @ ./~/selenium-webdriver/firefox/index.js
 @ ./~/selenium-webdriver/index.js
 @ ./src/app/app.component.ts
 @ ./src/app/index.ts
 @ ./src/main.ts
 @ multi main

ERROR in ./~/selenium-webdriver/io/exec.js
Module not found: Error: Can't resolve 'child_process' in '/Users/myname/tmp/typescript-selenium-example/node_modules/sele
nium-webdriver/io'
 @ ./~/selenium-webdriver/io/exec.js 20:21-45
 @ ./~/selenium-webdriver/remote/index.js
 @ ./~/selenium-webdriver/index.js
 @ ./src/app/app.component.ts
 @ ./src/app/index.ts
 @ ./src/main.ts
 @ multi main

【问题讨论】:

    标签: angularjs selenium typescript


    【解决方案1】:

    当我的一个测试中有一个错误的beforeEach 方法时,我也遇到了这个问题。函数在初始化之前试图访问函数中的全局变量。也许这会对你有所帮助?

    正如 cmets 指出的那样,当您导入错误时也会发生这种情况,例如:

    import {describe} from 'selenium-webdriver';
    

    import {beforeEach} from "selenium-webdriver/testing";
    

    【讨论】:

    • 哦,我早就放弃了这个,如果我回到它,我会试试你的建议投票。
    • 根据您的建议,我注释掉了我修改的最后一组测试,果然,一切又开始工作了。 @Jas 如果你有机会,你应该接受这个作为答案。
    • 具体来说,刚刚发现这是因为 Webstorm 根据我的错字自动添加了import {describe} from 'selenium-webdriver';。这会导致 selinium 喷溅。删除错误的导入解决了我的问题。
    • 遇到了完全相同的问题。有以下狡猾的进口......import {beforeEach} from "selenium-webdriver/testing";
    • import { promise } from 'selenium-webdriver' --- 感谢 IntelliJ 损失了 2 小时。
    【解决方案2】:

    对我来说,我不小心在组件中导入了错误的库。

    我改变了这个:

    import { EventEmitter } from 'selenium-webdriver';

    进入这个:

    import { EventEmitter } from '@angular/core';

    它又可以工作了。

    【讨论】:

    • 是的!就是这样!
    • 该死的自动导入!
    • 谢谢。
    猜你喜欢
    • 2014-03-30
    • 2018-12-03
    • 1970-01-01
    • 2018-05-03
    • 2016-05-27
    • 2018-11-18
    • 2019-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多