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">
    <div>
        <label for="username">Username</label>
        <input type="text" name="username" required="true">
    </div>
    <div>
        <label for="password">Password</label>
        <input type="password" name="password" required="true">
    </div>
</form>

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

    response.submitForm({
        formSelector: '#login-form',
        fields: { username: 'myusername', password: 'mypassword' }
    })

But I have problem submitting Purchase Form.

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

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