TestProject Forum

Weblinks validation using iteration

Hi guys!

I just started with TestProject and wonder how can I realize the following: I need to test external links on different pages. I have many pages with different amount of links. Could you advise how can I iterate through all the links on the page, click on each link/button and check that link is not broken?
For example:

Page 1 with 3 buttons:
Click here <url link 1>
Click here <url link 2>
Click here <url link 3>

I need to find all these links and verify they are working.

I would appreciate for any advises, thank you.

Hi @media-troopers and welcome to our community :slight_smile: ,

Sure, one of many of the great things about the TestProject tool is that you can validate elements for example:

  1. You can hover your mouse on the link and then you can click double shift to freeze the element, it will open for you many options to do with this element, for your scenario click on “validations” :

  2. Let’s say you want to know if you can even click on it, so you can use “is clickable” action for this issue, run this step if it ran successfully the link is clickable.

  3. Add a new step and now freeze this element again and use the “click if visible” action, another great way, just to confirm that the element is visible and if is visible it will click on him and it will open the page of the link for you automatically, and you

Another way is if you know which text needs to be in each link, for example, you clicked on a link and you know that this link should have some title that you already know:

  1. After you click on the link, immediately add a step with the “get text” action and validate if the text is really there and if the text is not there it is broken, for example, I am clicking on this link:

  2. And then I am using this action “get text” with a validation inside the step:

  3. Run the test and you can see which links contain the text and which are not/broken.

Let me know if it helped you, and if you any further questions please feel free to ask :slight_smile:

Hi Alex! Thank you so much for the detailed info. However I would like to specily, if I can also check the url if its correct or not. In other words on each page I need to run something like this script:

Go on the page, grab all the urls from the links and check status code they respond.

Example from Cypress:

const urls = [‘https://mysampleproject.com’, ‘https://mysampleproject2.com’]

describe(‘Test Links’, () => {
urls.forEach((url) => {
it(‘can navigate and test the links’, () => {
cy.get(‘a’).each(link => {
cy.request(link.prop(‘href’), {failOnStatusCode: false}).then(response =>{