I am trying to run selenium test from git with Jenkins job on selenium grid in docker.
Job is supposed to get .js which is holding test and connection to grid. This file should be executed with build in jenkins. Since I am using nodeJS with selenium, I need Jenkins to get all requested npm packages.
In Jenkins, I downloaded nodeJS plugin and in Global Tool Configuration
I filled [email protected]
in column Global npm packages to install
(nodeJS version I chose 18.1.0)
Job successfully get git repo. In Build
I have simple command node login.js
.
Unfortunately when I am trying to build that job, I am still getting MODULE NOT FOUND
for selenium-webdriver.
In log from build there is different module error, because I tried to add node_modules/selenium-wedriver
directly to repo. But I guess that this is not the right way.
Anyone could point me the right direction please?
Running as SYSTEM
Building in workspace /var/jenkins_home/workspace/sele-login
The recommended git tool is: NONE
using credential 34b86306-efa8-432e-92fb-63b586339585
> git rev-parse --resolve-git-dir /var/jenkins_home/workspace/sele-login/.git # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url [email protected]:MrWolfcan/sele-test.git # timeout=10
Fetching upstream changes from [email protected]:MrWolfcan/sele-test.git
> git --version # timeout=10
> git --version # 'git version 2.30.2'
using GIT_SSH to set credentials test2
> git fetch --tags --force --progress -- [email protected]:MrWolfcan/sele-test.git refs/heads/*:refs/remotes/origin/* # timeout=10
Seen branch in repository origin/main
Seen 1 remote branch
> git show-ref --tags -d # timeout=10
Checking out Revision 4cb9f780e70818120c1128aad85b18c1f71ad4dd (origin/main)
> git config core.sparsecheckout # timeout=10
> git checkout -f 4cb9f780e70818120c1128aad85b18c1f71ad4dd # timeout=10
Commit message: "Add files via upload"
> git rev-list --no-walk 37e8fc5193006e5820cc66209c10a8f799478786 # timeout=10
[sele-login] $ /bin/sh -xe /tmp/jenkins11143974131067136179.sh
node login.js
node:internal/modules/cjs/loader:942
throw err;
^
Error: Cannot find module 'ws'
Require stack:
- /var/jenkins_home/workspace/sele-login/node_modules/selenium-webdriver/lib/webdriver.js
- /var/jenkins_home/workspace/sele-login/node_modules/selenium-webdriver/lib/http.js
- /var/jenkins_home/workspace/sele-login/node_modules/selenium-webdriver/http/index.js
- /var/jenkins_home/workspace/sele-login/node_modules/selenium-webdriver/index.js
- /var/jenkins_home/workspace/sele-login/login.js
at Module._resolveFilename (node:internal/modules/cjs/loader:939:15)
at Module._load (node:internal/modules/cjs/loader:780:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/var/jenkins_home/workspace/sele-login/node_modules/selenium-webdriver/lib/webdriver.js:33:19)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Module._load (node:internal/modules/cjs/loader:827:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/var/jenkins_home/workspace/sele-login/node_modules/selenium-webdriver/lib/webdriver.js',
'/var/jenkins_home/workspace/sele-login/node_modules/selenium-webdriver/lib/http.js',
'/var/jenkins_home/workspace/sele-login/node_modules/selenium-webdriver/http/index.js',
'/var/jenkins_home/workspace/sele-login/node_modules/selenium-webdriver/index.js',
'/var/jenkins_home/workspace/sele-login/login.js'
]
}
Node.js v18.1.0
Build step 'Execute shell' marked build as failure
Finished: FAILURE
CodePudding user response:
So I get this working.
Only thing I did was add another Build step
> Execute shell - npm install
before step executing node login.js
.
So what it is doing (I suppose) is that npm install
will try to install packages from package.json
every single build.
Now I am going to find out, how to cache this :)