Yaml 如何使用cy.Visit()从Docker容器内的KeyClope访问重定向url?

Yaml 如何使用cy.Visit()从Docker容器内的KeyClope访问重定向url?,yaml,cypress,drone,Yaml,Cypress,Drone,状态: 我有一个应用程序,它是用Angular(作为前端)和Quarkus作为(后端)构建的。 成功登录后,应用程序首先将用户重定向到keydape,然后重定向回应用程序(无论是在线还是本地托管) 对于CI/CD,我使用无人机CI。Drone首先构建应用程序并在容器中运行应用程序,但是它有一个定制的url,而不是localhost,我们称之为app url 对于端到端测试,我使用Cypress。我想做的测试是登录测试。本项目中没有其他npm包,只有cypress和newman。本地测试可以成功执

状态:

我有一个应用程序,它是用Angular(作为前端)和Quarkus作为(后端)构建的。 成功登录后,应用程序首先将用户重定向到keydape,然后重定向回应用程序(无论是在线还是本地托管)

对于CI/CD,我使用无人机CI。Drone首先构建应用程序并在容器中运行应用程序,但是它有一个定制的url,而不是localhost,我们称之为app url

对于端到端测试,我使用Cypress。我想做的测试是登录测试。本项目中没有其他npm包,只有cypress和newman。本地测试可以成功执行,它发出2个请求,1个用于身份验证,1个用于获取访问应用程序内部内容所需的重定向url

以下是在localhost上工作的测试代码:

describe('simple login test', () => {
    beforeEach(() => {
        cy.clearCookies();
        cy.clearLocalStorage();

    });

    it('login', () => {

        cy.log('login start')

        function createUUID() {
            const s = [];
            const hexDigits = '0123456789abcdef';

            for (let i = 0; i < 36; i++) {
                s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
            }

            s[14] = '4';
            s[19] = hexDigits.substr((parseInt(s[19]) & 0x3) | 0x8, 1);
            s[8] = s[13] = s[18] = s[23] = '-';

            return s.join('');
        }

        cy.request({
            url: '{keycloak-url}',
            qs: {
                client_id: '{clientid}',
                redirect_uri: 'http://localhost:8360',
                scope: 'openid',
                state: createUUID(),
                nonce: createUUID(),
                response_type: 'code',
                response_mode: 'fragment',
            }
        })
        .then((response) => {
            cy.log('login first request')

            const _el = document.createElement('html');
            _el.innerHTML = response.body;

            const loginForm = _el.getElementsByTagName('form');
            const isAlreadyLoggedIn = !loginForm.length;
            if (isAlreadyLoggedIn) {
                return;
            }

            cy.wait(1000)
            cy.request({
                form: true,
                method: 'POST',
                url: loginForm[0].action,
                followRedirect: false,
                body: {
                    username: "user",
                    password: "pwd"
                }
            })
                .then((res) => {
                    cy.log('login second request')
                    cy.log(res);
                    cy.wait(1000)
                    cy.log("RedirectToUrl ist " + res.redirectedToUrl)
                    cy.visit(res.redirectedToUrl);
                    cy.log('Login Redirect complete')
                })
          })
     });
})
尝试解决问题:

  • 检查端口,甚至更改端口以匹配它们
  • 已删除导致通行证的cy.visit()
  • 检查Cypress版本是否正确
  • 已签入重定向url的密钥斗篷
  • 使用CLI在本地测试项目。测试也可以成功执行
  • 已通过docker compose中的网桥建立Internet连接
  • 已检查网站的可用性。在yml文件中,您可以看到bash文件的标记,该标记使无人机等待网站建立
  • 问题: 有什么解决办法吗?如果是,会是什么?这与容器本身有关吗

    https://app-url:8360/
    
    We attempted to make an http request to this URL but the request failed without a response.
    
    We received this error at the network level:
      &gt; Error: connect ECONNREFUSED {ip for app-url}:8443
    
    Common situations why this would fail:
    
      - you don&apos;t have internet access
          - you forgot to run / boot your web server
          - your web server isn&apos;t accessible
          - you have weird network configuration settings on your computer" type="CypressError"><![CDATA[CypressError: `cy.visit()` failed trying to load:
        
        https://app-url:8443/
        We attempted to make an http request to this URL but the request failed without a response.
        We received this error at the network level:
          > Error: connect ECONNREFUSED 192.168.208.6:8443
        Common situations why this would fail:
          - you don't have internet access
          - you forgot to run / boot your web server
          - your web server isn't accessible
          - you have weird network configuration settings on your computer
            at http://app-url:8080/__cypress/runner/cypress_runner.js:138876:23
            at visitFailedByErr (http://app-url:8080/__cypress/runner/cypress_runner.js:138235:12)
            at http://app-url:8080/__cypress/runner/cypress_runner.js:138875:11
            at tryCatcher (http://app-url:8080/__cypress/runner/cypress_runner.js:10791:23)
            at Promise._settlePromiseFromHandler (http://app-url:8080/__cypress/runner/cypress_runner.js:8726:31)
            at Promise._settlePromise (http://app-url:8080/__cypress/runner/cypress_runner.js:8783:18)
            at Promise._settlePromise0 (http://app-url:8080/__cypress/runner/cypress_runner.js:8828:10)
            at Promise._settlePromises (http://app-url:8080/__cypress/runner/cypress_runner.js:8904:18)
            at _drainQueueStep (http://app-url:8080/__cypress/runner/cypress_runner.js:5498:12)
            at _drainQueue (http://app-url:8080/__cypress/runner/cypress_runner.js:5491:9)
            at Async.../../node_modules/bluebird/js/release/async.js.Async._drainQueues (http://app-url:8080/__cypress/runner/cypress_runner.js:5507:5)
            at Async.drainQueues (http://app-url:8080/__cypress/runner/cypress_runner.js:5377:14)
        From Your Spec Code:
            at Context.eval (http://app-url:8080/__cypress/tests?p=cypress/integration/tests/simple-login.spec.js:162:12)   
        From Node.js Internals:
          Error: connect ECONNREFUSED 192.168.208.6:8443
              at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
          ]]></failure>
            </testcase>
          </testsuite>
        </testsuites>
    
    - name: test ui
        image: image for test ui
        volumes:
          - name: cypress_results
            path: app/cypress/results
          - name: cypress_screenshots
            path: app/cypress/screenshots
          - name: cypress_videos
            path: app/cypress/videos
        commands:
          - ./docker/app/wait-for.sh http://app-url:8360/ --> Bash file that makes drone wait until that url can be reached
          - cd test
          - npm install
          - npx cypress run --config baseUrl=http://app-url:8360/ --spec "cypress/integration/**/*" --env testuser=user,testuserpw=pwd