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

Basics of Using XPath Selectors

Basics-of-Using-XPath-Selectors

To start using XPath selectors, you should install a special plugin.

We mean a licensed plugin from Cypress.

It is installed in a typical way — the command npm install D cypress-xpath is executed to install the required package.

Next, you need to add the cypress-xpath function to the cypress/support/index.js file.

If it’s not done, the plugin won’t be registered and a user will see a message saying that cy.xpath is not a function.

If users use TypeScript, they need to add cypress-xpath to tsconfig.jsonfile files.

This action will help add the xpath () command that works together with the .get command.

It helps return the HTML element that you may use in your further work.

Further, we’ll analyze some examples of XPath and try to analyze how they are used on the basis of Cypress commands (e.g. while offering security testing services).

An example of Cypress/XPath

Selecting the entire document:

cy.xpath(‘/html’)

cy.root()

Selecting an object by certain text:

cy.xpath(‘//*[text()[contains(.,”My Lists”)]]’)

cy.contains(‘My Lists’)

cy.xpath(‘//*[@data-cy=”create-board”]’)

cy.get(‘[data-cy=”create-board”]’)

Selecting an element that contains the required class:

cy.xpath(‘//*[contains(@class, “font-semibold”]’)

cy.get(‘.font-semibold’)

[highlight dark=”no”]Note![/highlight] This XPath selector completely corresponds to random settings inside the class attribute.

Therefore, if the X element contains the button_front-semibold class name, this XPath selector will also find it.

Selecting an element with a certain class by text:

cy.xpath(‘//*[contains(@class, “font-semibold”)][text()[contains(.,”My Lists”)]]’)

cy.contains(‘.font-semibold’, ‘My Lists’)

Filtering an object by index:

cy.xpath(‘(//div[contains(@class, “list”)])[1]’)

cy.get(‘.list’).eq(0)

Keep in mind that the XPath selector doesn’t start with 0 as in other languages but from 1.

Searching for a child element:

cy.xpath(‘//div[contains(@class, “list”)]//child::div[contains(@class, “card”)]’)

cy.get(‘.list’).find(‘.card’)

And finally, we’ll analyze a process of selecting an element that contains a certain set of child elements:

cy.xpath(‘//div[contains(@class, “list”)][.//div[contains(@class, “card”)]]’)

cy.get(‘.card’).parents(‘.list’)

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.