Search code examples
codeceptionacceptance-testingparagraphs

Can I check for multiple paragraphs in Codeception?


I'm using Codeception + Selenium.

On my website and in emails sometimes I have a text consisting of multiple paragraphs. I want to check all or most of them in my acceptance tests. I know I can do

$I->canSee($par1, $locator); $I->canSee($par2, $locator);

however it becomes cumbersome to do this for many paragraphs.

If I try to check for more than one paragraph in canSee(), it fails.

Do you know how I can check for more than one paragraph of text?


Solution

  • I think the best way for you will be usage of "grabMultiple" ( PhpBrowser)

        $p = $I->grabMultiple('.article-body p');
        codecept_debug($p);
        >> [
              0 => "P1 text",
              1 => "P2 Text",
              2 => "P3 Text"
           ]
    

    will give you back array of matched elements, so you can test how much of them you have, and check what text they have.