angularjs - angular2 + Selenium 网络驱动程序 : Can't resolve 'child_process

标签 angularjs selenium typescript

我这样做了:

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

最佳答案

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

正如评论所指出的,当您导入错误时也会发生这种情况,例如:

import {describe} from 'selenium-webdriver';

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

关于angularjs - angular2 + Selenium 网络驱动程序 : Can't resolve 'child_process,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41057396/

相关文章:

javascript - Angular ES6 - $inject 不是函数

process - 在 C# DLL 生命周期内运行并终止 Selenium 服务器单例进程

javascript - 如何使用selenium和python点击Javascript按钮?

javascript - 如何从 JSON 数组中获取数据并在表中显示数据?

javascript - Google Geocoder 和 TypeScript 中的 'this' 引用

javascript - Angular 2路由在导航时隐藏选择器

javascript - 如何以单一形式使用多个 Angular UI Bootstrap Datepicker?

jquery - 使用 AngularJS 动态滑动切换

javascript - Angular 没有根据模型更新我的选择元素

python - 如何使用带有下拉菜单的 Selenium 来抓取历史数据?