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

Testing the Presence of an Element With Cypress

Testing-the-Presence-of-an-Element-With-Cypress

When you test an application with Cypress utility, it may sometimes be necessary to test the presence of an item. In this material, we’ll consider situations on how to properly test whether there is an element in the application and whether it is noticeable. We’ll analyze some of the features of such checks, as well.

As an example, we’ll take an application for a functional set similar to Trello. You can download it following this link – https://github.com/filiphric/trelloapp, and try to perform tests again, especially if you’re actively providing automated testing services.

Testing visibility

First of all, let’s look at the simplest and the most common script. So, there is a list of boards on a page under test. We’ll test the visibility of the board using the following program code:

it(‘has a board’, () => {

cy
.visit(‘/’);

cy
.get(‘[data-cy=board-item]’)
.should(‘be.visible’);

});

This test performs exactly the functions that we initially programmed. It tests the visibility of a specific element, and the running test will be executed correctly.

The curious thing about such a check is that, although this element is rendered based on network information, the internal system logic of Cypress contains built-in retries – the check will wait for the element to be rendered, and the user does not need to add additional commands. Simply speaking, even if the tested element hasn’t been displayed at the beginning of a test, Cypress will wait for it!

Testing invisibility

And now let’s test something opposite. For example, let’s try to delete the board and check if it really has become invisible:

it(‘has a board’, () => {

cy
.visit(‘/’);

cy
.get(‘[data-cy=board-item]’)
.should(‘not.be.visible’);

});

It’s remarkable, but the test doesn’t fail now. That’s because Cypress analyses if the element is hidden when testing CSS parameters like display: none. But in this case, the object under test is absent in that software. Instead of this, you need to ensure that there is no should (‘not.exist’).

Be careful with a group of negative statements. Sometimes the reason for non-existence may be the fact that the tested element hasn’t yet been rendered due to some defect. If you need to make sure that the element no longer exists, it is recommended to test first whether it was visible (or exists at the moment):

it(‘deletes a board’, () => {

cy
.visit(‘/’);

cy
.get(‘[data-cy=board-item]’)
.should(‘exist’);

cy
.request(‘DELETE’, ‘/boards/2626653025’);

cy
.get(‘[data-cy=board-item]’)
.should(‘not.exist’);

});

Testing visibility inside the viewport

Now it’s time to create a long list of test boards. Let’s try to test the display of these boards. So, we have something very unexpected happening – the tests pass but we get a warning for the added .get() command:

Testing visibility inside the viewport

Testing visibility inside the viewport

You should always keep that in mind when you test several elements at once. It is extremely important to understand what is considered a visible element from a perspective of a web browser. The tested software contains a special element container with the overflow: scroll function. But if this were not true, Cypress would declare all the items.

It’s overflow: scroll that makes a significant difference. Without this condition, the list would stretch as the user would like. And even if all the elements aren’t visible because of the web browser, the system will still consider them visible.

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.