Strategy for creating reusable test helpers


What is the strategy for reusing code inside tests?

E.g. I need a helper to run GraphQL queries and return the response. But want to keep it dry…

Is it possible to create a project trait for example? But somehow also inherit from the Test/ApiClient trait?


I made a simple repo to test GraphQL and on tests I just send query and variables using Test/ApiClient

test('login user', async ({ client, assert }) => {
  const query = `mutation($input: LoginUserInput) {
    loginUser (input: $input) {
  const variables = {
    input: {
      email: 'test',
      password: 'test',

  const response = await client
    .send({ query, variables })

  const { token, refreshToken } = JSON.parse(response.text).data.loginUser


Thanks, @vinicius-batista.

Yup, I know how to do it with just the client. I was using it more as a hypothetical scenario.

I still want to know the answer on how to make traits or helper methods for tests.


There are docs on traits already

Also creating helpers is like any other application. You can keep them in any folder and just require them inside your test file.

If you can come up with an example, I can share my thoughts on it.