如何在使用柏树时模仿真实的购买会话?

问题描述 投票:-1回答:1

请帮忙!我真的需要快点学习我的学士论文,我不熟悉javascript或cypress,但我必须将这个程序用于我的学士论文:'(

这就是我的问题:我想在页面dev.capitalpioneers.de上模拟购买/投资过程。我用命令cy.visit,cy.get,cy.contains()启动了cypress。click()a.s.o.

通过赛普拉斯:我登录了,没关系,我可以下载所有nessecary文件,但是我选择了一个产品并想通过点击“立即投资”按钮启动投资流程,出现了一个错误消息,即CSFR令牌无效。

因此,当我通过cypress浏览器直接与该网站进行交互时,它会将我带到日志页面。

我在文档中读到了我应该使用它:

cy.request('POST', 'https://sso.corp.com/auth', { username: 'foo', password: 'bar' })
  .then((response) => {
    // pull out the location redirect
    const loc = response.headers['Location']

    // parse out the token from the url (assuming its in there)
    const token = parseOutMyToken(loc)

    // do something with the token that your web application expects
    // likely the same behavior as what your SSO does under the hood
    // assuming it handles query string tokens like this
    cy.visit('http://localhost:8080?token=' + token)

    // if you don't need to work with the token you can sometimes
    // just visit the location header directly
    cy.visit(loc)
  })

我无法在登录之前或登录时解析令牌。令牌出现在正文中。

首先,当我到达产品网站时,我可以从身体获得此令牌

'#product_filter__token[name=product_filter[_token]]'

在这个网址:https://dev.capitalpioneers.de/produkte/

第二,当我选择产品并想投资时

'#user_profile__token[name=user_profile[_token]]'

在这个网址:https://dev.capitalpioneers.de/investor/investment/N01-134225/investieren/(有趣的一面信息:每当我开始一个真正的新投资过程时,这个数字N01-134225会发生变化)

我在这个github页面找到了https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/logging-in__csrf-tokens/cypress/integration/logging-in-csrf-tokens-spec.js

如何解析一个令牌,但我想保留它并模仿一个真实的会话,这样我就不会得到401错误消息,我的请求未被授权,而且github解决方案没有解决。

我真的需要帮助,希望任何人都有正确的解决方案。谢谢!克里斯蒂

PS:我是否必须将cy.getCookies()命令与cy.request()相结合?我如何构建它?

parsing session-cookies cypress gui-testing csrf-token
1个回答
0
投票

PS:我是否必须将cy.getCookies()命令与cy.request()相结合?我如何构建它?

这不是柏树的工作原理。赛普拉斯从一个完全干净的环境开始,删除所有缓存,cookie和其他存储。所以每次跑步都是从同一个起点开始的。

© www.soinside.com 2019 - 2024. All rights reserved.