angular2 +硒webdriver:无法解析'child_process [英] angular2 + selenium webdriver: Can't resolve 'child_process
本文介绍了angular2 +硒webdriver:无法解析'child_process的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我这样做了:
ng new typescript-selenium-example
npm install selenium-webdriver --save
(此外,我已将chromedriver
复制到我的/Application
)
(in addition I have copied chromedriver
to my /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
推荐答案
当我的一个测试中包含错误的beforeEach
方法时,也会出现此问题.该函数试图在初始化之前到达函数中的全局变量.也许对您有帮助?
This problem showed up for me also when one of my tests had a bad beforeEach
method in it. The function was trying to reach a global variable in the function before it was initialized. Maybe that will help you?
正如评论所指出的那样,当您导入错误时也可能发生这种情况,例如:
As the comments point out, this can also happen when you have a bad import, such as:
import {describe} from 'selenium-webdriver';
或
import {beforeEach} from "selenium-webdriver/testing";
这篇关于angular2 +硒webdriver:无法解析'child_process的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文