angular2 with selenium webdriver: Issue with resolving 'child_process' conflict

I followed these steps:

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

I also made sure to copy chromedriver to my /Application.

I updated the app.component.ts file as shown below:

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!';
}

However, I encountered the following errors:

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/selenium-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/selenium-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/selenium-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

Answer №1

I encountered a similar issue when one of my tests had a flawed beforeEach method. The function was attempting to access a global variable before it was properly initialized. Perhaps this insight will assist you?

Additionally, as noted in the comments, this issue can also arise from incorrect imports, such as:

import {describe} from 'selenium-webdriver';

or

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

Answer №2

One issue I encountered was mistakenly importing the incorrect library in a component.

Here is what needed to be corrected:

import { EventEmitter } from 'selenium-webdriver';

The fix involved changing it to:

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

After making this adjustment, everything started working as expected.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular Material Table displaying real-time information

Recently, I've delved into Angular and have been experimenting with creating a dynamic table to showcase data. Currently, I have managed to get it partially working with static data. I drew inspiration from this particular example: https://stackblit ...

Initializing ngOnInit and saving the value to an array variable

Currently, I am developing a function that retrieves data from an API. However, the function needs to be called within ngOnInit and the value should be stored in an array variable. MyValue: any; MyValue = MyLocation(); Unfortunately, the MyValue ends up ...

Tips for customizing the appearance of Ionic's navigation bar

I attempted to customize the background-color of an ion-nav-bar by using the following code: <ion-nav-bar class="backarrow-bar" ng-style="{'background-color': rgba(255, 0, 0, 0.5)}" style="background-color:rgba(255, 0, 0, 0.5)"> <io ...

typeorm migration:generate - Oops! Could not access the file

When attempting to create a Type ORM migration file using the typeorm migration:generate InitialSetup -d ormconfig.ts command, I encountered an error: Error: Unable to open file: "C:\_work\template-db\ormconfig.ts". Cannot use impo ...

What is the process for configuring a TimePicker object in antd to send a Date with UTC+3 applied?

I have Form.Item and a TimePicker defined inside it. I am using this form to send a POST request, but when I try to post 16:35, it gets sent as 13:35. The UTC offset is not being considered. However, the CreationTime works fine because it utilizes the Da ...

Typescript: require generic types to include specific keys at all times

Is there a way to ensure that the function below only accepts a data object if it contains an id key, and then allows us to access the id from the data object? function someFuntion<T>(data : T){ const id = data['id'] //Error : Element imp ...

The NoSuchMethodError is thrown when trying to open Selenide

Can someone help me with this issue I'm facing while trying to navigate to the Google page? String url = "https://www.google.com"; Selenide.open(url); The specific exception that is being thrown is: java.util.stream.Collector com.google ...

Tips for displaying real-time data and potentially selecting alternative options from the dropdown menu

Is there a way to display the currently selected option from a dropdown list, and then have the rest of the options appear when the list is expanded? Currently, my dropdown list only shows the available elements that I can choose from. HTML: < ...

Ways to ensure that when changes occur in one component, another component is also updated

How can I update the cart badge value in the navbar component every time a user clicks the "Add to Cart" button in the product-list component? The navbar component contains a cart button with a badge displaying the number of products added to the cart. n ...

Retrieve fresh information every 30 seconds utilizing the useQuery hook in React

I am utilizing '@tanstack/react-query' to retrieve data in my React + Typescript application. Below is a snippet of my code, where I aim to fetch metric data every 30 seconds import { useQuery } from '@tanstack/react-query'; import ...

Navigate to a different state with ui-router upon entering the page

I am implementing two wizard flows, flow A and flow B, each collecting different sets of information. states["wizard"] = { abstract: true, url: "^/wizard", controller: "wizardController", templateUrl: "wizard.html" ...

Creating a GlobalVariable dynamically in Katalon during runtime using script mode

I am a beginner with the Katalon Studio tool and trying to dynamically add GlobalVariables by inputting both the variable name and value. I have found a piece of code that should help me achieve this, but I am struggling to understand it as it utilizes met ...

Selecting the destination for saving an image using Urllib

I am currently utilizing a combination of selenium and urllib for downloading images. However, I have noticed that urllib saves the images into the same folder where the python script is located. Is there a method to alter the destination of where the imag ...

Integration of Mocha with WebStorm

WebStorm offers a useful feature that adds a small arrow next to describe() and it() keywords when writing tests with Mocha, allowing for easy manual execution. However, there is a challenge: I require additional setup before each test, leading me to use ...

Is it possible to utilize C# Selenium for uploading a file?

I encountered an issue with the following code: [FindsBy(How = How.CssSelector, Using = "#openDocumentsSelector")] private IWebElement BTNOpenDocumentsSelector { get; set; } public void AddNewFile(DocumentsTestValues new_upload) { th ...

Showcasing diverse content with an Angular Dropdown Menu

I'm currently developing an angular application, and I've encountered a difficulty in displaying the user's selection from a dropdown menu. To elaborate, when a user selects a state like Texas, I want to show information such as the period, ...

Step-by-step guide for setting up automatic Tslint in IntelliJ

When working on an Angular project in Intellij, I often encounter numerous tslint errors while coding. Is there a command within Intellij that can automatically fix all of these lint errors? ...

Extract information from a website and input it into a spreadsheet

Is there a method to extract data from a specific column in an Excel file, manipulate the input value using a HTTPS URL, retrieve information from a webpage, and store the corresponding output in another column for use in a Shell script? I have researche ...

Continuously extract information by filtering through the array

Currently, I am in the process of developing an idle RPG game using Angular. One of the features I have implemented is a console log that displays events such as Damage Dealt and Experience Earned. In order to manage messages efficiently, I have created a ...

When coding in JavaScript, the value of "this" becomes undefined within a class function

I'm facing an issue with my TypeScript class that contains all my Express page functions. When I try to access the class member variable using this, I get an 'undefined' error: class CPages { private Version: string; constructor(ver ...