Running selenium test from GIT with Jenkins on remote Selenium grid - selenium

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 selenium-webdriver#4.1.2 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 git#github.com:MrWolfcan/sele-test.git # timeout=10
Fetching upstream changes from git#github.com: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 -- git#github.com: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

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 :)

Related

Get npm package latest version from a gitlab registry

I'm trying to put a package in a Gitlab registry using npm and .gitlab-ci.yml.
.gitlab-ci.yml
npm-package:
stage: build
image: node:buster
before_script:
- git config --global user.name "${GITLAB_USER_NAME}"
- git config --global user.email "${GITLAB_USER_EMAIL}"
script:
- npm config set #${CI_PROJECT_ROOT_NAMESPACE}:registry=https://${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/
- npm config set //${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}
- NPM_PACKAGE_NAME=$(node -p "require('.package.json').name")
- NPM_PACKAGE_VERSION=$(node -p "require('./package.json').version")
- echo $(npm view "${NPM_PACKAGE_NAME}" versions)
- echo ${NPM_PACKAGE_NAME}
- echo ${NPM_PACKAGE_VERSION}
- |
if [[ $(npm view "${NPM_PACKAGE_NAME}" versions) != *"'${NPM_PACKAGE_VERSION}'"* ]]; then
npm config set //${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}
npm publish
echo "Successfully published version ${NPM_PACKAGE_VERSION} of ${NPM_PACKAGE_NAME} to GitLab's NPM registry: ${CI_PROJECT_URL}/-/packages"
else
echo "Version ${NPM_PACKAGE_VERSION} of ${NPM_PACKAGE_NAME} has already been published, so no new version has been published."
fi
I tried my first time and the package was saved successfully in the repo. And now I'm trying to run it under the condition: if the version's package has changed then run an npm publish.
But the variable $(npm view "${NPM_PACKAGE_NAME}" versions) seems to be empty, and when I try to echo it I get the error:
npm ERR! code E401
npm ERR! 401 Unauthorized - GET https://gitlab.example.com/api/v4/projects/1/packages/npm/#my_scope/my_package
Any help?
Your CI does not have enough rights.
1- You need to generate an access token (automation type) from your npm registry via the npm UI (or via the command line).
The process with the UI:
https://docs.npmjs.com/creating-and-viewing-access-tokens
2- Assign the token to an environment variable (named NPM_TOKEN in this example) accessible to your CI
3- Then create (or update) a .npmrc file with this line at the top:
//registry.npmjs.org/:_authToken=${NPM_TOKEN}

npm version patch: clean working directory not clean

I hae a problem running npm version patch on Azure Pipelines. Initially, I discovered that SonarCloud scanner drops unwanted files in the repository. I git-ignored the directory
Consider the following fragment
- script: git checkout -f $(Build.SourceBranchName)
displayName: Force checkout of current branch
- script: git status
displayName: Git status
- script: git reset --hard
displayName: Git reset
- task: Npm#1
displayName: Tag repository and set release version
inputs:
command: custom
customCommand: version patch
- script: git push origin $(Build.SourceBranchName) --tags
displayName: Git push with tags
Required in order to push a subsequent commit
Displays a summary of the repository
Unhappy with git-status ok, I force cleaning the repo
Makes a commit and a tag out of the repository
Pushes branch and tag
git-status output
Starting: Git status
==============================================================================
Task : Command line
Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version : 2.201.1
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
git status
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/447a869a-56d7-4a29-a4c0-9a49b5ffce74.sh
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
Finishing: Git status
git-reset output
Starting: Git reset
==============================================================================
Task : Command line
Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version : 2.201.1
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
git reset --hard
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/85fedcd4-9756-4d38-aa3d-d41c03032565.sh
HEAD is now at ad6aebf Pipelines
Finishing: Git reset
npm-version output
Starting: Tag repository and set release version
==============================================================================
Task : npm
Description : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Azure Artifacts.
Version : 1.202.0
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/package/npm
==============================================================================
/opt/hostedtoolcache/node/16.15.0/x64/bin/npm --version
8.5.5
/opt/hostedtoolcache/node/16.15.0/x64/bin/npm config list
; "project" config from /home/vsts/work/1/s/.npmrc
message = ":[npm-autoversion]: %s"
; "env" config from environment
cache = "/home/vsts/work/1/.npm"
userconfig = "/home/vsts/work/1/npm/7212.npmrc"
; node bin location = /opt/hostedtoolcache/node/16.15.0/x64/bin/node
; cwd = /home/vsts/work/1/s
; HOME = /home/vsts
; Run `npm config ls -l` to show all defaults.
/opt/hostedtoolcache/node/16.15.0/x64/bin/npm version patch
npm ERR! Git working directory not clean.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vsts/work/1/.npm/_logs/2022-05-19T13_01_16_005Z-debug-0.log
##[warning]Couldn't find a debug log in the cache or working directory
##[error]Error: Npm failed with return code: 1
Finishing: Tag repository and set release version
Question: how is it possible that npm fails to make a version bump if I am triple-sure that the repository is clean?

Yarn Install Error: Package subpath error

I am currently working on a project following the documentation in this github repo.
github repo
I first clone the repo into a folder. I then cd into the folder and do a run yarn install to get all dependencies. I get the following error. I have node v17.2.0 installed.
(base) Eddys-MacBook-Pro:avalanche-wallet-sdk eddyarce$ yarn install
yarn install v1.22.17
warning ../../../../../package.json: No license field
[1/5] 🔍 Validating package.json...
[2/5] 🔍 Resolving packages...
success Already up-to-date.
$ husky install && yarn build:prod
husky - Git hooks installed
yarn run v1.22.17
warning ../../../../../package.json: No license field
$ rollup -c --environment BUILD:production
Error loading `tslib` helper library.
[!] Error: Package subpath './package.json' is not defined by "exports" in /Users/eddyalvarado_1/Documents/GitHub/plasma-wallet-web3/js/avalanche-wallet-sdk/node_modules/rollup-plugin-typescript2/node_modules/tslib/package.json
Error: Package subpath './package.json' is not defined by "exports" in /Users/eddyalvarado_1/Documents/GitHub/plasma-wallet-web3/js/avalanche-wallet-sdk/node_modules/rollup-plugin-typescript2/node_modules/tslib/package.json
at new NodeError (node:internal/errors:371:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:429:9)
at packageExportsResolve (node:internal/modules/esm/resolve:683:3)
at resolveExports (node:internal/modules/cjs/loader:482:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/eddyalvarado_1/Documents/GitHub/plasma-wallet-web3/js/avalanche-wallet-sdk/node_modules/rollup-plugin-typescript2/src/tslib.ts:11:23)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
https://github.com/ezolenko/rollup-plugin-typescript2/issues/286
Upgrade your tslib version (>=0.31.0) or downgrade your node version (<17.0.0)

Unable to run local version of testcafe via npm link

Whenever I try to run a locally installed version of testcafe, I get the error Cannot find module '../testcafe/lib/cli'. Steps I've taken:
git clone <testcafe>, then cd to testcafe
npm install
npm link
cd to repo where my automated tests reside
npm link testcafe
Run testcafe <browser>
Results in
internal/modules/cjs/loader.js:796
throw err;
^
Error: Cannot find module '/Users/rcooper/testcafe/lib/cli'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
at Function.Module._load (internal/modules/cjs/loader.js:686:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Is there something else I need to do, to run a local version of this library?
You need to build the TestCafe package. Run npx gulp build before the npm link command.

using Grunt with non-global installation

While attempting to build a custom version of jQuery without installing global dependencies, I ran into the following issue:
$ node --version
v0.10.4
$ npm --version
1.2.18
$ git clone git://github.com/jquery/jquery.git
$ cd jquery
$ git checkout `git describe --abbrev=0 --tags` # latest tag
$ npm install
$ npm install grunt-cli
# variant A
$ npm run-script grunt custom:-ajax # does nothing
# variant B
$ node_modules/.bin/grunt custom:-ajax
Running "custom:-ajax" (custom) task
Creating custom build...
Warning: Error: not found: grunt Use --force to continue.
Aborted due to warnings.
I haven't worked with Grunt or Node much before, so what am I missing here?
This is because of how the jQuery custom task spawns grunt. I've just sent a pull request which would fix this issue: https://github.com/jquery/jquery/pull/1255