Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Certain protractor API functions cause errors

Why am I receiving errors when I use Protractor API functions? I have scoured the internet for solutions to this problem and I found a couple similar answers, but they didnt work and so I'm asking the community.

I am trying to set up the simplest e2e test with Karma and Protractor. An empty block of test code like this will yield no error:

describe('Mapping Assistant State', () => {
   beforeEach(() => {
   });

   it('should display a table',() => {
      console.log('test');
   });

   it('should click the create Paste button',() => {

    });
});

The problem occurs once I add certain functions from protractor like expect() or browser():

it('should display a table',() => {
    browser.get('someUrl');
    expect(element(by.css('.map')).getText()).toContain('map');

});

Here are some of the contents of my package.json:

"protractor": "^5.3.0",
"karma": "^1.7.1",
"@angular/cli": "^1.6.6",
"typescript": "^2.5.2"
"@angular/core": "^4.3.6",
"rxjs": "^5.4.3",
"@types/selenium-webdriver": "^3.0.6",
"ts-node": "^4.0.1",
"@types/node": "^8.0.58",

Also:

import { browser, by, element } from 'protractor';
import {describe} from 'selenium-webdriver/testing';
import {beforeEach} from 'selenium-webdriver/testing';

Here is my protractor.conf.js file:

const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
    allScriptsTimeout: 11000,
    specs: [
        './e2e/**/*.e2e-spec.ts'
    ],
    capabilities: {
        'browserName': 'chrome'
    },
    directConnect: true,
    baseUrl: 'http://localhost:4200/',
    framework: 'jasmine',
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 30000,
        print: function() {}
    },
    onPrepare() {
        require('ts-node').register({
            project: 'e2e/tsconfig.e2e.json'
        });
        jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
    }
};

Once adding any of the Protractor functions and running 'ng test', these errors occur:

    ERROR in ./node_modules/saucelabs/index.js
Module not found: Error: Can't resolve './lib-cov/SauceLabs' in '/Users/moop/Work/frontend/web/node_modules/saucelabs'
 @ ./node_modules/saucelabs/index.js 2:2-32
 @ ./node_modules/protractor/built/driverProviders/sauce.js
 @ ./node_modules/protractor/built/driverProviders/index.js
 @ ./node_modules/protractor/built/runner.js
 @ ./node_modules/protractor/built/index.js
 @ ./e2e/sample.e2e-spec.ts
 @ ./src/test.ts

ERROR in ./node_modules/protractor/built/runner.js
Module not found: Error: Can't resolve 'child_process' in '/Users/moop/Work/frontend/web/node_modules/protractor/built'
 @ ./node_modules/protractor/built/runner.js 54:32-56
 @ ./node_modules/protractor/built/index.js
 @ ./e2e/sample.e2e-spec.ts
 @ ./src/test.ts

ERROR in ./node_modules/protractor/built/bpRunner.js
Module not found: Error: Can't resolve 'child_process' in '/Users/moop/Work/frontend/web/node_modules/protractor/built'
 @ ./node_modules/protractor/built/bpRunner.js 3:24-48
 @ ./node_modules/protractor/built/driverProviders/driverProvider.js
 @ ./node_modules/protractor/built/driverProviders/index.js
 @ ./node_modules/protractor/built/runner.js
 @ ./node_modules/protractor/built/index.js
 @ ./e2e/sample.e2e-spec.ts
 @ ./src/test.ts

ERROR in ./node_modules/protractor/built/debugger.js
Module not found: Error: Can't resolve 'child_process' in '/Users/moop/Work/frontend/web/node_modules/protractor/built'
 @ ./node_modules/protractor/built/debugger.js 67:32-56
 @ ./node_modules/protractor/built/browser.js
 @ ./node_modules/protractor/built/index.js
 @ ./e2e/sample.e2e-spec.ts
 @ ./src/test.ts

ERROR in ./node_modules/selenium-webdriver/firefox/binary.js
Module not found: Error: Can't resolve 'child_process' in '/Users/moop/Work/frontend/web/node_modules/selenium-webdriver/firefox'
 @ ./node_modules/selenium-webdriver/firefox/binary.js 25:14-38
 @ ./node_modules/selenium-webdriver/firefox/index.js
 @ ./node_modules/protractor/built/index.js
 @ ./e2e/sample.e2e-spec.ts
 @ ./src/test.ts

ERROR in ./node_modules/selenium-webdriver/io/exec.js
Module not found: Error: Can't resolve 'child_process' in '/Users/moop/Work/frontend/web/node_modules/selenium-webdriver/io'
 @ ./node_modules/selenium-webdriver/io/exec.js 20:21-45
 @ ./node_modules/selenium-webdriver/remote/index.js
 @ ./node_modules/protractor/built/index.js
 @ ./e2e/sample.e2e-spec.ts
 @ ./src/test.t

Does anyone have an idea about what is causing this and how I can fix it?

like image 872
Ian Steffy Avatar asked Feb 01 '18 08:02

Ian Steffy


5 Answers

Some time we add event emitter then visual studio automatic added event-emitter liabrary.

like : import { EventEmitter } from 'protractor'; then auto generate protecter error.

solution : Remove auto import from own code and added import { EventEmitter } from '@angular/core';

so error is wrong added liabrary for EventEmitter in our code.

like image 137
nagender pratap chauhan Avatar answered Oct 14 '22 03:10

nagender pratap chauhan


Check your logs carefully if it's saying

LOG -
ERROR in ./node_modules/saucelabs/index.js Module not found: Error: Can't resolve './lib-cov/SauceLabs' in 'N:\Angular Codes\billmanagement\node_modules\ saucelabs'
ERROR in ./node_modules/protractor/built/runner.js Module not found: Error: Can't resolve 'child_process' in 'N:\Angular Codes\billmanagement\node_modules\ protractor\built'


SOLUTION -
make sure in the app.module.ts you have imported correct version of Event Emitter
import { EventEmitter } from '@angular/core';

NOT THIS- (usually Visual Studio does it automatically) import { EventEmitter } from 'protractor';

like image 32
Naman Khurpia Avatar answered Oct 14 '22 05:10

Naman Khurpia


If you are using an Editor (such as VSCode) several automatic imports will create this problem. In addition to the above answers, namely showing that this:

import { EventEmitter } from 'protractor';

instead of this...

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

will give you said error. But even this:

import { error } from 'protractor';

instead of this...

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

will also give you the same result. In my case, I didn't need an import! I was trying to use the temporary variable name "error" in a catch statement and while typing that name, it automatically created an import from protractor. (I have now resolved to use more specific names like say "myfuncerr"). So anything that autocompletes could potentially import from the wrong library.

If you are getting this error, the first thing to do is to do a global find on the word "protractor". It is a fast fix (it would have saved me at least a couple of hours).

like image 22
Chiwda Avatar answered Oct 14 '22 04:10

Chiwda


install two more package: @types/node and ts-node

like image 28
yong Avatar answered Oct 14 '22 03:10

yong


In my case, imported $ accidentally from protector instead jquery

like image 39
user7944806 Avatar answered Oct 14 '22 04:10

user7944806