angular / protractor

E2E test framework for Angular apps
http://www.protractortest.org
MIT License
8.75k stars 2.31k forks source link

Protractor doesn't find webdriver's firefox driver automatically when running local tests. #4689

Open costescuandrei opened 6 years ago

costescuandrei commented 6 years ago

Description: protractor doesn't find firefox driver automatically when running local tests. The file https://github.com/angular/protractor/blob/5.3.0/lib/config.ts does say for "geckoDriver" the following:

geckoDriver location is used to help find the gecko binary. This will be passed to the Selenium jar as the system property webdriver.gecko.driver. If the value is not set when launchinglocally, it will use the default values downloaded from webdriver-manager.

So I think my small/basic example should work on firefox as well; in chrome (see output below) it does work automatically and both browser drivers are present in (...)\node_modules\protractor\node_modules\webdriver-manager\selenium

If it is not supposed to work like that then the https://github.com/angular/protractor/blob/5.3.0/lib/config.ts comment needs to be fixed/enhanced for firefox.


};


- A relevant example test; file "geckoDriverBug_spec.js":

describe('geckoDriverBug', function() { it('should execute test case without errors', function() { browser.get("http://www.protractortest.org/testapp/ng1");

    browser.wait(function() {
        return browser.isElementPresent(element(by.xpath("//*[@id='animals']")));
    }, 8000);

    expect(element(by.xpath("//*[@id='animals']")).isPresent()).toBe(true);
});

});


- Output

(node:18632) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead. [10:09:51] I/launcher - Running 1 instances of WebDriver [10:09:54] I/testLogger -

[10:09:54] I/testLogger - [firefox #01] PID: 4344 [firefox #01] Specs: e:\GitHome_master\git\servoy_test\E2E_tests\geckoDriverBug_spec.js [firefox #01] [firefox #01] (node:4344) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead. [firefox #01] [10:09:52] I/local - Starting selenium standalone server... [firefox #01] [10:09:54] I/local - Selenium standalone server started at http://192.168.1.5:51226/wd/hub [firefox #01] [firefox #01] e:\GitHome_master\git\servoy_test\E2E_tests\node_modules\selenium-webdriver\lib\error.js:546 [firefox #01] throw new ctor(message); [firefox #01] ^ [firefox #01] SessionNotCreatedError: Unable to create new service: GeckoDriverService [firefox #01] Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z' [firefox #01] System info: host: 'DEEPGRAY', ip: '192.168.1.5', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_162' [firefox #01] Driver info: driver.version: unknown [firefox #01] at Object.checkLegacyResponse (e:\GitHome_master\git\servoy_test\E2E_tests\node_modules\selenium-webdriver\lib\error.js:546:15) [firefox #01] at parseHttpResponse (e:\GitHome_master\git\servoy_test\E2E_tests\node_modules\selenium-webdriver\lib\http.js:509:13) [firefox #01] at doSend.then.response (e:\GitHome_master\git\servoy_test\E2E_tests\node_modules\selenium-webdriver\lib\http.js:441:30) [firefox #01] at [firefox #01] at process._tickCallback (internal/process/next_tick.js:188:7) [firefox #01] From: Task: WebDriver.createSession() [firefox #01] at Function.createSession (e:\GitHome_master\git\servoy_test\E2E_tests\node_modules\selenium-webdriver\lib\webdriver.js:769:24) [firefox #01] at Function.createSession (e:\GitHome_master\git\servoy_test\E2E_tests\node_modules\selenium-webdriver\firefox\index.js:521:41) [firefox #01] at createDriver (e:\GitHome_master\git\servoy_test\E2E_tests\node_modules\selenium-webdriver\index.js:170:33) [firefox #01] at Builder.build (e:\GitHome_master\git\servoy_test\E2E_tests\node_modules\selenium-webdriver\index.js:632:16) [firefox #01] at Local.getNewDriver (e:\GitHome_master\git\servoy_test\E2E_tests\node_modules\protractor\built\driverProviders\driverProvider.js:53:33) [firefox #01] at Runner.createBrowser (e:\GitHome_master\git\servoy_test\E2E_tests\node_modules\protractor\built\runner.js:195:43) [firefox #01] at q.then.then (e:\GitHome_master\git\servoy_test\E2E_tests\node_modules\protractor\built\runner.js:339:29) [firefox #01] at _fulfilled (e:\GitHome_master\git\servoy_test\E2E_tests\node_modules\q\q.js:834:54) [firefox #01] at self.promiseDispatch.done (e:\GitHome_master\git\servoy_test\E2E_tests\node_modules\q\q.js:863:30) [firefox #01] at Promise.promise.promiseDispatch (e:\GitHome_master\git\servoy_test\E2E_tests\node_modules\q\q.js:796:13)

[10:09:54] I/testLogger -

[10:09:54] E/launcher - Runner process exited unexpectedly with error code: 1 [10:09:54] I/launcher - 1 instance(s) of WebDriver still running .[10:10:00] I/testLogger -

[10:10:00] I/testLogger - [chrome #11] PID: 19952 [chrome #11] Specs: e:\GitHome_master\git\servoy_test\E2E_tests\geckoDriverBug_spec.js [chrome #11] [chrome #11] (node:19952) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead. [chrome #11] [10:09:55] I/local - Starting selenium standalone server... [chrome #11] [10:09:56] I/local - Selenium standalone server started at http://192.168.1.5:55207/wd/hub [chrome #11] Started [chrome #11] . [chrome #11] [chrome #11] [chrome #11] 1 spec, 0 failures [chrome #11] Finished in 1.43 seconds [chrome #11] [chrome #11] [10:10:00] I/local - Shutting down selenium standalone server.

[10:10:00] I/testLogger -

[10:10:00] I/launcher - 0 instance(s) of WebDriver still running [10:10:00] I/launcher - firefox #01 failed with exit code: 1 [10:10:00] I/launcher - chrome #11 passed [10:10:00] I/launcher - overall: 1 process(es) failed to complete [10:10:00] E/launcher - Process exited with error code 100


- Steps to reproduce the bug: just run the given protractor config and test spec.
- The URL tests run against (provided by you): http://www.protractortest.org/testapp/ng1
costescuandrei commented 6 years ago

I also tried adding "geckoDriver" to protractor config - that pointed to "node_modules/protractor/node_modules/webdriver-manager/selenium/geckodriver-v0.19.1.exe". The file is there on disk... Also tried it with the absolute path to the driver.

It still gives the same error.

costescuandrei commented 6 years ago

I wonder if this is related to #4502 and #4602. It sounds similar to #4501.

IgorSasovets commented 6 years ago

Hi, @costescuandrei ! I've faced with similar problem, but on Mac OS. In my case, solution was to update drivers directly from project node_modules and from general node_modules/webdriver-manager folders. You can try to run webdriver-manager update command from \node_modules\protractor\node_modules\webdriver-manager\bin or ()\node_modules\webdriver-manager\bin.

costescuandrei commented 6 years ago

Hi. I don't have it installed as a general package. And I did execute [folder_with_package.json_in_it] > "node_modules\.bin\webdriver-manager.cmd" update

Is it wrong to do it via .cmd or is the current dir wrong? It did execute successfully and I do have contents in "(...)\node_modules\protractor\node_modules\webdriver-manager\selenium":

costescuandrei commented 6 years ago

I tried it as well running the scripts directly via node (from main dir and also from node_modules\protractor dir) but there is no difference in outcome. node node_modules\protractor\node_modules\webdriver-manager\bin\webdriver-manager update node node_modules\webdriver-manager\bin\webdriver-manager update

costescuandrei commented 6 years ago

No. That is what I was trying to avoid. (this should work just like it works for chrome right? - I didn't manually start webdriver-manager and chrome tests ran ok)

IgorSasovets commented 6 years ago

I tried to use such approach but tests don't run at all.

IgorSasovets commented 6 years ago

I solved this issue using directConnect option. Please take a look at https://github.com/IgorSasovets/geckodriver-windows-error. after before

costescuandrei commented 6 years ago

Thanks Igor. I can confirm that directConnect true does work for both chrome and firefox directly.

Then should the comments in https://github.com/angular/protractor/blob/5.3.0/lib/config.ts be changed to say that firefox default driver location only works this way with directConnect set? But then why do chrome tests run in such a configuration without directConnect?

(I initially wanted it to go through selenium to be closer to how tests are running remotely to saucelabs - I am trying to diagnose why after a protractor upgrade tests are running twice as slow as before there...)

Of course I can use webdriver-manager manual start + selenium address but I liked the simplicity of current conf.

IgorSasovets commented 6 years ago

I agree with you that current conf is more simple and easier to use. So I hope that https://github.com/angular/protractor/pull/4502 will be merged in the short term and it'll fix this issue.

surfjedi commented 6 years ago

+1

bdellegrazie commented 6 years ago

Just FYI, #4502 is now merged so this should solve this problem too.

alrf commented 6 years ago

I have the original issue in docker container.

[firefox #01-10] [14:21:17] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[firefox #01-10]
[firefox #01-10] /tests/node_modules/selenium-webdriver/lib/error.js:546
[firefox #01-10]         throw new ctor(message);
[firefox #01-10]               ^
[firefox #01-10] WebDriverError: Process unexpectedly closed with status 255
[firefox #01-10] Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:32:19.891Z'
[firefox #01-10] System info: host: 'ip-172-31-0-34.us-east-2.compute.internal', ip: '172.31.0.34', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-693.17.1.el7.x86_64', java.version: '1.8.0_171'
[firefox #01-10] Driver info: driver.version: unknown
[firefox #01-10] remote stacktrace:
[firefox #01-10]     at Object.checkLegacyResponse (/tests/node_modules/selenium-webdriver/lib/error.js:546:15)
[firefox #01-10]     at parseHttpResponse (/tests/node_modules/selenium-webdriver/lib/http.js:509:13)
[firefox #01-10]     at doSend.then.response (/tests/node_modules/selenium-webdriver/lib/http.js:441:30)
[firefox #01-10]     at <anonymous>
[firefox #01-10]     at process._tickCallback (internal/process/next_tick.js:118:7)
[firefox #01-10] From: Task: WebDriver.createSession()
[firefox #01-10]     at Function.createSession (/tests/node_modules/selenium-webdriver/lib/webdriver.js:769:24)
[firefox #01-10]     at Function.createSession (/tests/node_modules/selenium-webdriver/firefox/index.js:521:41)
[firefox #01-10]     at createDriver (/tests/node_modules/selenium-webdriver/index.js:170:33)
[firefox #01-10]     at Builder.build (/tests/node_modules/selenium-webdriver/index.js:632:16)
[firefox #01-10]     at Hosted.getNewDriver (/tests/node_modules/protractor/built/driverProviders/driverProvider.js:53:33)
[firefox #01-10]     at Runner.createBrowser (/tests/node_modules/protractor/built/runner.js:195:43)
[firefox #01-10]     at q.then.then (/tests/node_modules/protractor/built/runner.js:339:29)
[firefox #01-10]     at _fulfilled (/tests/node_modules/protractor/node_modules/q/q.js:834:54)
[firefox #01-10]     at self.promiseDispatch.done (/tests/node_modules/protractor/node_modules/q/q.js:863:30)
[firefox #01-10]     at Promise.promise.promiseDispatch (/tests/node_modules/protractor/node_modules/q/q.js:796:13)

I tried to run webdriver-manager update

node@ip-172-31-0-34:/tests$ node_modules/protractor/node_modules/webdriver-manager/bin/webdriver-manager update
webdriver-manager: using global installed version 12.1.0
[14:20:30] I/update - chromedriver: file exists /tests/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.40.zip
[14:20:30] I/update - chromedriver: unzipping chromedriver_2.40.zip
[14:20:31] I/update - chromedriver: setting permissions to 0755 for /tests/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.40
[14:20:31] I/update - chromedriver: chromedriver_2.40 up to date
[14:20:31] I/update - selenium standalone: file exists /tests/node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.13.0.jar
[14:20:31] I/update - selenium standalone: selenium-server-standalone-3.13.0.jar up to date
[14:20:31] I/update - geckodriver: file exists /tests/node_modules/protractor/node_modules/webdriver-manager/selenium/geckodriver-v0.21.0.tar.gz
[14:20:31] I/update - geckodriver: unzipping geckodriver-v0.21.0.tar.gz
[14:20:31] I/update - geckodriver: setting permissions to 0755 for /tests/node_modules/protractor/node_modules/webdriver-manager/selenium/geckodriver-v0.21.0
[14:20:31] I/update - geckodriver: geckodriver-v0.21.0 up to date

It didn't help.

feiyingplus commented 6 years ago

in your config.js file, add below one line: directConnect: true

and then retry. this works for me using firefox

vikassarkar commented 5 years ago

you can set path of chrome and gecko in config chromeDriver : '../../drivers/manager/selenium/chromedriver_2.43.exe', geckoDriver : '../../drivers/manager/selenium/geckodriver-v0.23.0.exe',

cooleiwhistles commented 5 years ago

I am also facing a similar issue. Have tried using directConnect and specifying the geckoDriver path, but no luck.

If I have directConnect = true (without specifying geckoDriver path) - I am getting issues like: Failed: POST /session/f836d4a1-b6d5-436f-bb02-631140333e51/element/95ac89df-5937-433d-bcb9-e00ba59a8c4c/submit did not match a known command

When set to false, it works locally, but am presented with error trying to run in Jenkins:

[16:51:46] E/launcher - WebDriverError: WebDriver:NewSession
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'ip-10-23-4-52.ec2.internal', ip: '10.23.4.52', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.77-81.59.amzn2.x86_64', java.version: '1.8.0_191'
Driver info: driver.version: unknown
remote stacktrace: WebDriverError@chrome://marionette/content/error.js:222:5
UnknownCommandError@chrome://marionette/content/error.js:493:5
execute/req<@chrome://marionette/content/server.js:513:15
TaskImpl_run@resource://gre/modules/Task.jsm:321:42
TaskImpl@resource://gre/modules/Task.jsm:279:3
asyncFunction@resource://gre/modules/Task.jsm:254:14
Task_spawn@resource://gre/modules/Task.jsm:168:12
execute@chrome://marionette/content/server.js:510:15
onPacket@chrome://marionette/content/server.js:481:7
_onJSONObjectReady/<@chrome://marionette/content/transport.js:480:9

    at Object.checkLegacyResponse

Here is my protractor.conf.js setup for that part:

capabilities: {
        browserName: 'firefox',
        marionette: true,
        firefoxOptions: {
            args: ['--headless']
        },
        'moz:firefoxOptions': {
            args: ['--headless']
        }
    },
    geckoDriver: './node_modules/protractor/node_modules/webdriver-manager/selenium/geckodriver-v0.23.0.exe',
    directConnect: true,
CrispusDH commented 5 years ago

if you set directConnect: true then you don't need geckoDriver path. Try to remove it and run again.

cooleiwhistles commented 5 years ago

So that works locally, but when I try to run our suite in Jenkins, I am still getting similar errors: (not exactly sure why it is giving chromedriver info when running with firefox/geckodriver either)

[18:59:01] I/update - chromedriver: file exists /home/jenkins/workspace/project/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.45.zip
[18:59:01] I/update - chromedriver: unzipping chromedriver_2.45.zip
[18:59:01] I/update - chromedriver: setting permissions to 0755 for /home/jenkins/workspace/project/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.45
[18:59:01] I/update - chromedriver: chromedriver_2.45 up to date
[18:59:01] I/launcher - Running 1 instances of WebDriver
[18:59:01] I/direct - Using FirefoxDriver directly...
[19:00:15] E/launcher - WebDriver:NewSession
[19:00:15] E/launcher - WebDriverError: WebDriver:NewSession
    at Object.throwDecodedError
CrispusDH commented 5 years ago
  1. I suggest to create two config files: one for local run and one for CI. Manage what to run by script commands in a package.json for example.
  2. You see chromedriver in a logs because it runs command webdriver-manager update, it's ok. Using FirefoxDriver directly... it line shows that system tries to run Firefox browser directly. The first command to driver is create a new session and it fails. So you don't understand how to run e2e UI tests in browser on CI (server machine). It would be useful to read a tone of information in internet about it. Remote server should have the same as your local system: OS with UI, installed browser, node and npm. It might be better to search or create question on Stack Overflow
cooleiwhistles commented 5 years ago

Thanks @CrispusDH, will do that.