【问题标题】:How to apply iterations condition for function in K6如何在 K6 中为函数应用迭代条件
【发布时间】:2020-10-06 09:21:39
【问题描述】:

我想执行一次注销功能和多次迭代的下拉功能。我需要在下面的代码中进行哪些更改。

        executors: {
            logout: {
                type: 'per-vu-iterations',
                exec: 'logout',
                vus: 1,
                iterations: 1,
                startTime: '30s',
                maxDuration: '1m',
                tags: { my_tag: 'LOGOUT'},
            },
       }};
    export function logout() {
        group('Logout API', () => {
            loginFunctions.logout_api();
        })
    }
    export function dropDown() {
        group('Drop Down API', () => {
        loginFunctions.dropDown_api();
        })
    }
    export default function () {
        logout();
        dropDown();
    }

也没有默认功能,它不起作用。获取 executor default: function 'default' not found in exports 这个错误

【问题讨论】:

    标签: javascript automation performance-testing load-testing k6


    【解决方案1】:

    不确定您在哪里看到executors,这是选项的旧名称,在#1007 被合并和发布之前。新的正确名称是scenarios:https://k6.io/docs/using-k6/scenarios

    所以,为了回答你的问题,代码应该看起来像这样:

    import http from 'k6/http';
    import { sleep } from 'k6';
    
    export let options = {
        scenarios: {
            logout: {
                executor: 'per-vu-iterations',
                exec: 'logout',
                vus: 1, iterations: 1,
                maxDuration: '1m',
                tags: { my_tag: 'LOGOUT' },
            },
            dropDown: {
                executor: 'per-vu-iterations',
                exec: 'dropDown',
                vus: 10, iterations: 10, // or whatever
                maxDuration: '1m',
                tags: { my_tag: 'LOGOUT' },
            },
        }
    };
    
    export function logout() {
        console.log("logout()");
        sleep(1);
        // ...
    }
    export function dropDown() {
        console.log("dropDown()");
        sleep(1);
        // ...
    }
    
    

    不过,根据您的用例,logout() 代码的最佳位置实际上可能是在teardown() 生命周期函数中?详情请见https://k6.io/docs/using-k6/test-life-cycle

    【讨论】:

    • 谢谢。它工作正常。还尝试了 test-data-cycle 。
    猜你喜欢
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    • 2021-06-13
    • 2018-03-16
    • 1970-01-01
    • 1970-01-01
    • 2019-02-25
    • 1970-01-01
    相关资源
    最近更新 更多