加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – angular2 selenium webdriver:无法解析’child_pr

发布时间:2020-12-17 07:35:27 所属栏目:安全 来源:网络整理
导读:我这样做了: ng new typescript-selenium-examplenpm install selenium-webdriver --save (另外我已经将chromedriver复制到我的/ Application) 将app.component.ts更新为: import { Component } from '@angular/core';import { Builder,By,until } from 's
我这样做了:
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";

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读