Ukraine Office: +38 (063) 50 74 707

USA Office: +1 (212) 203-8264

contact@testmatick.com

Manual Testing

Ensure the highest quality for your software with our manual testing services.

Mobile Testing

Optimize your mobile apps for flawless performance across all devices and platforms with our comprehensive mobile testing services.

Automated Testing

Enhance your software development with our automated testing services, designed to boost efficiency.

Functional Testing

Refine your application’s core functionality with our functional testing services

VIEW ALL SERVICES 

Discussion – 

0

Discussion – 

0

How to Quickly Create a Random User in Cypress

How to Quickly Create a Random User in Cypress

A lot of web products under test require some level of authentication. When QA engineers test such software, they have to be able to operate a particular testing user. As a rule, it’s generated randomly and then is used in most tests. Further, in the article, we’ll talk about the most popular types of user generation in Cypress tests.

This material is of a technical nature. Therefore, it is understandable to those who are experienced in this product (for example, those who perform e-commerce testing).

cypress.io

cypress.io

Working with Hooks

We can take a support/index.js file and put before() or beforeEach() hook there.

As a result, we’ll get the following:

const { internet } = require(‘faker’);
const email = internet.exampleEmail()
const password = internet.password()

beforeEach(() => {
cy
.request(‘POST’, ‘/signup’, { email, password })
.then(({ body }) => {
cy
.setCookie(‘trello_token’, body.accessToken);
});
});

Faker, an auxiliary tool, allows generating different parameters of testing emails for each user test.

The authorization process can create a lot of test data before each test. On the one hand, this procedure allows tests to be independent of each other. And that’s great! But creating a new user for each test is a hard and time-consuming process.

Creating a Test Script

Usually, before starting the test through Cypress run, it’s possible to run scripts that automatically create a user and then save it to a particular file. After, QA specialists use this file during testing to authorize a virtual user.

The content of testing signup.js:

const axios = require(‘axios’)
const { internet } = require(‘faker’);
const email = internet.exampleEmail()
const password = internet.password()
const fs = require(‘fs’)

const signupUser = async () => {

const user = await axios
.post(‘http://localhost:3000/signup’, { email, password })

fs.writeFileSync(“./cypress/data.json”, JSON.stringify(user.data))

}

signupUser()

You can run it as a separate test script that is defined in the package.json file.

package.json

“scripts”: {
“start”: “cd trelloapp && npm start”,
“cy:run”: “cypress run”,
“createUser”: “node signupUser.js”
}

Also, you can run this script through npm run createUser, and then run the following tests: npm run cy:run.

cypress/plugins/index.js

const signupUser = require(‘../../signupUser.js’)

module.exports = async (on, config) => {

config.env = await signupUser()

return config;

}

Cypress will have to wait till the signupUser() function is executed, and then save the data that was returned by the parameter to the config object. In that case, the information is generated during test performance and will be available only when Cypress runs. If a user runs tests in parallel (for example, on 15 local machines), then this script will be called 15 times. Perhaps, it’s for the best, as in that case, users won’t interfere with each other.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like

Encapsulation as One of the Fundamental Principles of Object-Oriented Programming

Encapsulation as One of the Fundamental Principles of Object-Oriented Programming

Knowing the basics of object-oriented programming is necessary not only for programmers, but also, of course, for testers who interact with program code, study it, or write it. Insight into programming fundamentals enables QA experts to better understand the program behavior, give effective recommendations on how to improve the structure of program code, and, more efficiently create autotest code.

Test Automation Strategies That Really Work

Test Automation Strategies That Really Work

An approach to the development and implementation of automated tests for an application-in-test depends on numerous factors. A size and complexity of an application, a structure of a project team, instantly appearing deadlines, requirements for security, and many other details define the most suitable strategy. Further, we will describe some working strategies that can be helpful for any project that requires automation.

Using Test Retries as a Method to Hide Bugs

Using Test Retries as a Method to Hide Bugs

Every tester is in some way familiar with the concept of randomly failing automated tests. An analysis of the results of these tests can be really time-consuming and some teams prefer running tests once again if they fail. But is this efficient? The answer is not as obvious and clear as it seems.