如何在 Artillery 中动态设置变量以在我的 Playwright 函数中使用

问题描述 投票:0回答:0

我在我的 yml artillery 文件中创建了一个变量,然后我可以从我的 Playwright 函数中访问它。

variables:
    redirectUrl: "foo"

然后我动态地将我从 api 调用中获得的 url 分配给这个变量。

- post:
          url: "/ipgw/wrapper/v1/customer-token/{{guid}}/pay"
          form:
            amount: 10
            reference:  "{{uuid}}"
            return_url: "https://www.google.com/"
          capture:
            - json: "$.url"
              as: "redirectUrl"

但是我无法弄清楚如何通过使用我在调用该函数之前进行的 api 调用的响应来动态设置 redirectUrl 变量。

以下函数获取“foo”的占位符值,而不是我从 api 响应中动态分配的值。

async function ipgHostedPages(page, context) {
    await page.goto(context.vars['redirectUrl']);

    await page.getByPlaceholder('CVV').fill('***');
    await page.getByRole('button', { name: 'Pay' }).click();

    await page.getByLabel('Password:').fill('***');
    await page.getByRole('button', { name: 'Submit' }).click();
    await page.getByText('Redirect Now').click();
}
load-testing playwright artillery
© www.soinside.com 2019 - 2024. All rights reserved.