代码之家  ›  专栏  ›  技术社区  ›  James.Alocard

Cypress给出“此浏览器或应用程序可能不安全”的谷歌身份验证

  •  0
  • James.Alocard  · 技术社区  · 5 月前

    Image

    柏树。在我输入登录电子邮件后提供此对话框。

        it('Login via Google', function() {
        cy.visit(website + 'login')
        cy.get('a[href="/connect/google"]').click()
        cy.origin('https://accounts.google.com/', { args: [email, password] }, ([email, password]) => {
          Cypress.on('uncaught:exception', (err) => {
              if (err.message.includes('RPC executor service threw an error') ||
                      err.message.includes('ResizeObserver loop completed with undelivered notifications')) {
                  return false
              }
              return true
          })
          function emailType() {
              cy.get('input[type="email"]').
                  should('be.visible').
                  type(email, { delay: 100 })
              cy.get('button')
                  .contains('Next', { timeout: 10000 })
                  .should('be.visible')
                  .click()
              cy.wait(3000)
              passwordType()
          }
          function passwordType() {
              cy.get('input[type="password"]', { timeout: 30000 })
              .should('be.visible')
              .type(password, { delay: 100 })
              cy.get('button').
                  contains('Next').
                  should('be.visible').
                  click()
          }
          emailType()
      })
      cy.url().should('include', website)
    

    })

    残疾人:

    • Webchrome安全。
    • 更改了chrome配置文件,没有阻止第三方Cookie。 问题依然存在。
    1 回复  |  直到 5 月前
        1
  •  1
  •   Dev I.A    5 月前

    尽量防止Chrome泄露它是由Cypress(index.js)等自动化工具控制的:

    --disable-blink-features=AutomationControlled

    还可以通过每次测试来禁用缓存,以保存缓存。

    --disable-cache

    里面 on('before:browser:launch', browser, launchOptions 具有 argus.push

    注意到原点内你没有打电话 clearLocalStorage 访问时清除您原籍地的存储。

    如果您需要保存登录缓存以调用另一个测试,请使用相同的文件 it() 登录googlesavesession后,您将需要检索它。示例。

      let Session= ''
    
      it('google login', function() {
          cy.getCookie('PHPSESSID').then((cookie) => {
          Session = cookie.value
          })
      }
    
      it('Check login', function() {
          cy.visit(website).then(() => {
              cy.clearCookie('PHPSESSID')
              cy.setCookie('PHPSESSID', Session).then(() => {
                  cy.getCookie('PHPSESSID').should('have.property', 'value', Session)
              })
            })
            cy.visit(website)
      })