简体   繁体   English

如何通过 Google 帐户使用 Cypress Origin?

[英]How do I use Cypress Origin with google accounts?

I am attempting to access a google service embedded into my website which uses accounts.google.com for the login.我正在尝试访问嵌入到我的网站中的谷歌服务,该服务使用 accounts.google.com 进行登录。

I'm trying to use the session/origin commands to do this, but it's failing as if I'm doing nothing at all.我正在尝试使用 session/origin 命令来执行此操作,但它失败了,就好像我什么都不做一样。 I use this with success to login to my application (non google login), but google seems to require something more.我成功地使用它登录到我的应用程序(非谷歌登录),但谷歌似乎需要更多的东西。 I have spent a great deal of time browsing for answers with no luck我花了很多时间浏览没有运气的答案

Code leading up to login:导致登录的代码:

cy.get('div [class="active carousel-item"]').find('button').first().click()
cy.loginGoogle(Cypress.env("GoogleUsername"),Cypress.env("GooglePassword"))

Login code:登录代码:

Cypress.Commands.add('loginGoogle', (username, password) => {
const args = { username, password }

cy.session(args, () =>

{
 cy.origin('https://accounts.google.com', { args }, ({ username, password }) => {
  cy.visit('https://accounts.google.com/')
  cy.get('input[type="email"]').type(username)
  cy.get('div[id="identifierNext"]').find('button').click()
  cy.get('#login-password').type(password)
  cy.get('#btn-login').click()
})
cy.visit('/')
cy.url().should('contain', 'mydomain.com')
})
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 cypress 与预取或预加载 webpack 的组件一起使用? - How do I use cypress with components that are prefetched or preloaded with webpack? 如何在单个程序中使用两个 AWS IAM 账户? - How do I use two AWS IAM accounts in a single program? 如何修改我的删除帐户 function 以适用于 Google 帐户? - How do I modify my delete account function to work for Google accounts? 如何将Google跟踪代码管理器与多个Google Analytics帐户配合使用 - How to use Google Tag Manager with multiple Google Analytics accounts 我怎样才能在柏树中做一个 if else ? - How can I do an if else in cypress? 如何在 Cypress 中运行 beforeEach? - How do I run a beforeEach in Cypress? 如何解决 - 赛普拉斯检测到跨源错误? - How to resolve - Cypress detected a cross origin error? 如何使用赛普拉斯在HTML5表单验证上检测setCustomValidity的输出 - How do I use Cypress to detect output of setCustomValidity on HTML5 Form Validation 如何将原点和目标坐标传递到Google Maps指令API? - How do I pass origin and destination co-ordinates to the Google Maps directions API? 如何动态地为多个账户使用一个谷歌数据工作室模板? - How to use one template of google data studio for multiple accounts dynamically?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM