Visiting multiple links on a page. [codeception]

414 views Asked by At

I am a complete newbie with automatized testing software. (Codeception and PHP7 are installed on a Centos 7 environment.)
Conditions:
1. My Index.html page includes x number of links
2. When (a href) links are visited, Page displays 'You have Selected Item i'.
3. Within the links, y number of faulty links may exist. When faulty links are visited, it displays an alert pop up saying the item selected does not exist.

What I am trying to do:
Build a test checking existence of faulty links. If exist, then returns the anchor text of the link.


Here is what I did: (obviously wrong..)

<?php <br>
$I = new AcceptanceTester($scenario);<br>
$I->wantTo('browse items');<br>
$I->amOnPage('/index.html');<br>
$I->click('a');<br>
$I->see('You have Selected Item i');<br>

Problem
Above code it enters the first link, then it checks the given text. After checking the first one, no matter with the result, I want it to check the next link on the index.html until all the links are visited. However it remains at the visited page and stops there.

I hope it is clear enough. Thanks in advance!

1

There are 1 answers

0
Sewoong Sol Oh On

So I got this answer, with the help from '@Alx101' and '@Naktibalda'. Really Appreciated.

Here I share my answer:

$I = new AcceptanceTester($scenario);
$I->wantTo('browse items');
$I->amOnPage('/index.html');
$aLinks = $I->grabMultiple('a','href');

foreach($aLinks as $link) {
    $I->amOnPage('/'.$link);
    $I->see('Selected Item');
    $I->moveback();
    echo $link;
}

Any answers shared with other or improved methods will be appreciated! :)