bjowes / cypress-ntlm-auth

Windows authentication plugin for Cypress
MIT License
55 stars 10 forks source link

combine npx ntlm-proxy & cypress-cloud #235

Closed RuslanAisin closed 1 year ago

RuslanAisin commented 1 year ago

Hello, I tryed run command in CI npx ntlm-proxy & with command cypress-cloud for parallel testing, but I get Error: The cypress-ntlm-auth plugin must be loaded before using this method On the one hand I sussesful run tests with command npx cypress-ntlm run but cant use parallel run on the other hand cypress-cloud cant get ntlm auth. Can we solve it? my Dockerfile

ARG CHROME_VERSION='113.0.5672.92-1'
ARG NODE_VERSION='16.17.0'
ARG CYPRESS_VERSION='12.12.0'

FROM cypress/factory:2.3.0

# Update the dependencies to get the latest and greatest (and safest!) packages.
RUN apt update && apt upgrade -y

RUN whoami

RUN id
RUN ls -la /root/
RUN chmod 755 /root
# ENV CYPRESS_CACHE_FOLDER=/root/.cache/Cypress

ENV CI=1
ENV QT_X11_NO_MITSHM=1
ENV _X11_NO_MITSHM=1
ENV _MITSHM=0

RUN npm i -g yarn@latest \
  && npm i -g cypress-ntlm-auth@4.1.2 \
  && npm i -g cypress-cloud@1.7.4 \
  && cypress verify \
  && cypress version \
  && echo  " node version:    $(node -v) \n" \
    "npm version:     $(npm -v) \n" \
    "yarn version:    $(yarn -v) \n" \
    "debian version:  $(cat /etc/debian_version) \n" \
    "user:            $(whoami) \n" \
    "chrome:          $(google-chrome --version || true) \n"

RUN yarn add -D cypress-file-upload@5.0.8 \
&& yarn add -D cypress-iframe@1.0.1 \
&& yarn add -D dayjs@1.10.7 \
&& yarn add -D cypress-sql-server@1.0.0 \
&& yarn add -D pdf-parse@1.1.1 \
&& yarn add -D uuid@8.3.2 \
&& yarn add -D cypress-log-to-output@1.1.2 \
&& yarn add -D cypress-mongodb@5.1.4

RUN mv /root/.cache /home/node/.cache

ENV CYPRESS_CACHE_FOLDER=/home/node/.cache/Cypress

RUN cypress verify
RUN cypress info
RUN npm list -g
RUN npm list

USER node

RUN id

run command - npx ntlm-proxy & cypress-cloud --record --parallel --ci-build-id Staging-test --key test

 { 13:34:43    configApiUrl: 'http://127.0.0.1:44835', 13:34:43    ntlmProxyUrl: 'http://127.0.0.1:39229' 13:34:43   } 13:34:43    13:34:43   ==================================================================================================== 13:34:43    13:34:43   Discovered 111 spec files 13:34:43   Tags: false; Group: false; Parallel: true; Batch Size: 3 13:34:43   Connecting to cloud orchestration service... 13:34:44    Run URL: http://sorry-cypress.************su:80/run/ 13:34:44    13:34:44   ==================================================================================================== 13:34:44    13:34:44   Running: cypress/e2e/test_positive.spec.js (1/111) 13:34:45   [330:0523/133445.065580:ERROR:zygote_host_impl_linux.cc(263)] Failed to adjust OOM score of renderer with pid 494: Permission denied (13) 13:34:45    13:34:45   DevTools listening on ws://127.0.0.1:43687/devtools/browser/1f2e995a-f7ea-49de-b85e-6d939df4e77c 13:34:45   [494:0523/133445.105270:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported. 13:34:49    13:34:49   ==================================================================================================== 13:34:49    13:34:49    (Run Starting) 13:34:49    13:34:49    ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ 13:34:49    │ Cypress: 12.12.0 │ 13:34:49    │ Browser: Electron 106 (headless) │ 13:34:49    │ Node Version: v16.17.0 (/usr/local/bin/node) │ 13:34:49    │ Specs: 1 found (test_positive.spec.js) │ 13:34:49    │ Searched: cypress/e2e/test_positive.spec.js │ 13:34:49    └────────────────────────────────────────────────────────────────────────────────────────────────┘ 13:34:49    13:34:49    13:34:49   ──────────────────────────────────────────────────────────────────────────────────────────────────── 13:34:49    13:34:49    Running: test_positive.spec.js (1 of 1) 13:34:49   setting the browser window size to 2000 1450 13:34:49   [330:0523/133449.897514:ERROR:zygote_host_impl_linux.cc(263)] Failed to adjust OOM score of renderer with pid 599: Permission denied (13) 13:34:50   [530:0523/133450.014377:ERROR:socket_posix.cc(93)] CreatePlatformSocket() failed: Address family not supported by protocol (97) 13:34:50   [530:0523/133450.195004:ERROR:socket_posix.cc(93)] CreatePlatformSocket() failed: Address family not supported by protocol (97) 13:34:50   [530:0523/133450.352178:ERROR:socket_posix.cc(93)] CreatePlatformSocket() failed: Address family not supported by protocol (97) 13:34:50   [530:0523/133450.358167:ERROR:socket_posix.cc(93)] CreatePlatformSocket() failed: Address family not supported by protocol (97) 13:34:50   [530:0523/133450.872632:ERROR:socket_posix.cc(93)] CreatePlatformSocket() failed: Address family not supported by protocol (97) 13:34:51   [530:0523/133450.997916:ERROR:socket_posix.cc(93)] CreatePlatformSocket() failed: Address family not supported by protocol (97) 13:34:51   [530:0523/133451.008799:ERROR:socket_posix.cc(93)] CreatePlatformSocket() failed: Address family not supported by protocol (97) 13:34:51   [530:0523/133451.017283:ERROR:socket_posix.cc(93)] CreatePlatformSocket() failed: Address family not supported by protocol (97) 13:34:51   [530:0523/133451.214635:ERROR:socket_posix.cc(93)] CreatePlatformSocket() failed: Address family not supported by protocol (97) 13:34:59    13:34:59    13:34:59    Test 13:35:00    13:35:00    0 passing (867ms) 13:35:00    1 failing 13:35:00    13:35:00    1) Test 13:35:00    Positive case: 13:35:00    Error: The cypress-ntlm-auth plugin must be loaded before using this method 13:35:00    at Context.ntlm (webpack:////usr/local/lib/node_modules/cypress-ntlm-auth/dist/commands/index.js:35:0) 13:35:00   

checked docker image node@cypress-run-tests-staging-test-b2w8d:/usr/local/lib/node_modules/cypress-ntlm-auth/dist/commands$ cat index.js file is present

in cypress/support/e2e.js import "/usr/local/lib/node_modules/cypress-ntlm-auth/dist/commands";

bjowes commented 1 year ago

When using the cy.ntlm, cy.ntlmSso or cy.ntlmReset commands, they look for the environment variable CYPRESS_NTLM_AUTH_API, which is set automatically when you can use cypress-ntlm. It is not set when starting ntlm-proxy.

Likely, the easiest way for you to get this working is to set CYPRESS_NTLM_AUTH_API to some port that is free in your docker instance, for instance set it to http://localhost:54800. This forces ntlm-proxy to use that port (it will crash if it is occupied) and cy.ntlm etc will know how to reach ntlm-proxy.

RuslanAisin commented 1 year ago

Thank you for response, I add ENV in Dockerfile ENV CYPRESS_NTLM_AUTH_API="http://localhost:54800" and run command npx ntlm-proxy & cypress-cloud --browser chrome --record --parallel --ci-build-id manual-Staging-test-993 --key key but have the same error { 12:16:23    configApiUrl: 'http://127.0.0.1:54800', 12:16:23    ntlmProxyUrl: 'http://127.0.0.1:35205' 12:16:23   } 12:16:23    12:16:23   ==================================================================================================== 12:16:23    12:16:23   Discovered 111 spec files 12:16:23   Tags: false; Group: false; Parallel: true; Batch Size: 3 12:16:23   Connecting to cloud orchestration service... 12:16:23    Run URL: http://sorry-cypress.*******/run/3f69084b05f6c612f303eff6c83dfd8a 12:16:23    12:16:23   ==================================================================================================== 12:16:23    12:16:23   Running: cypress/e2e/Positive case.spec.js (1/111) 12:16:23   [337:0525/121622.795775:ERROR:zygote_host_impl_linux.cc(263)] Failed to adjust OOM score of renderer with pid 504: Permission denied (13) 12:16:23    12:16:23   DevTools listening on ws://127.0.0.1:34047/devtools/browser/e3cab2d7-7d88-4944-8c0e-a341d86805f4 12:16:23   [504:0525/121622.852296:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported. 12:16:24    12:16:24   ==================================================================================================== 12:16:24    12:16:24    (Run Starting) 12:16:24    12:16:24    ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ 12:16:24    │ Cypress: 12.13.0 │ 12:16:24    │ Browser: Chrome 113 (headless) │ 12:16:24    │ Node Version: v16.17.0 (/usr/local/bin/node) │ 12:16:24    │ Specs: 1 found (Positive case.spec.js) │ 12:16:24    │ Searched: cypress/e2e/Positive case.spec.js │ 12:16:24    └────────────────────────────────────────────────────────────────────────────────────────────────┘ 12:16:24    12:16:24    12:16:24   ──────────────────────────────────────────────────────────────────────────────────────────────────── 12:16:24    12:16:24    Running: Positive case.spec.js (1 of 1) 12:16:24   setting the browser window size to 2000 1450 12:16:31    12:16:31    12:16:31    Positive case 12:16:32    (Attempt 1 of 2) Positive case 12:16:32    1) Positive case 12:16:32    12:16:32    12:16:32    0 passing (993ms) 12:16:32    1 failing 12:16:32    12:16:32    1) Positive case 12:16:32    Positive case 12:16:32    Error: The cypress-ntlm-auth plugin must be loaded before using this method

bjowes commented 1 year ago

Sorry, I missed a few additional variables that must be set. The complete list:

# set before starting ntlm-proxy
CYPRESS_NTLM_AUTH_API="http://localhost:54800"
CYPRESS_NTLM_AUTH_PROXY="http://localhost:54801"
# set after ntlm-proxy but before calling cypress
HTTP_PROXY="http://localhost:54801"
HTTPS_PROXY="http://localhost:54801"
NO_PROXY="<-loopback>"

The last three affects how several apps/tools communicate with HTTP servers, in particular if they are built in Node.js. Ideally those three should only be in effect during the execution of cypress, if you need to run any cleanup tasks after the tests you might unset them first. In theory other apps can communicate through the NTLM proxy too, but just to rule out potential issues you can avoid that.

RuslanAisin commented 1 year ago

Amazing! Thats good working. Thanks a lot! 👍