How to use Response.clickLink( [params] ) on button onClick event

I have two forms, first is Login Form and the second is Purchase Form as below:

<form id="login-form">
        <label for="username">Username</label>
        <input type="text" name="username" required="true">
        <label for="password">Password</label>
        <input type="password" name="password" required="true">

In K6, the script I use to submit the form is as below and there is not issue in getting response for login form

        formSelector: '#login-form',
        fields: { username: 'myusername', password: 'mypassword' }

But I have problem submitting Purchase Form.

<form id="purchase-form" @submit.prevent="submit-form">
        <label for="product">Product Name</label>
        <input type="text" name="productName" required="true">
        <label for="price">Product Price</label>
        <input type="text" name="productPrice" required="true">
        <button type="button" @click="submit()" text="submit-button">Submit</button>
        <button type="button" @click="cancel()">Cancel</button>

Here in K6, what is the script or K6 code I should apply to submit the form on the button @click?

Hi @codermas, Welcome to the community forum!

k6 does not render the html or evaluate the js code of the page that was downloaded with http.get (or any other call) [^1]

The call you have just reads the html to find the form and get the internal inputs then makes request based on those in a way that mimics browsers, but is not the same. The most important part is that no buttons get clicked.

So In your second case there is no (not extermely complicated) way to run the code that is submit() within k6 [^1].

Given that the code likely just makes one of two different requests with some validation - you can just code those by hand in k6 and then execute them. This likely will take you some time, but I expect it will be less then 30 minutes given the example you have provided.

But I cannot give you any more guidance without the code for the on @click events.

Hope this helps you!

[^1]: that is unless you are using the browser functionality which you are not in this case. In that case it is running a full browser and telling it what to do

1 Like