Dusk: Can i use assertTrue in Tests\Browser\Pages?

Created on 4 Jul 2019  路  3Comments  路  Source: laravel/dusk

I have write function with assertTrue in page file and i used that function on DuskTestCase.

class MyPage extends Page
{
   public function validation(Browser $browser){
       $browser ->clickLink('Sources') ;
       $this->assertTrue(count($browser->driver->findElements(WebDriverBy::xpath('//*[@id="home"]'))) > 0);
    }
}

class MyTest extends DuskTestCase
{
    public function test001()  {
        $this->browse(function (Browser $browser) {            
            $browser->visit(new MyPage)
                    ->validation();
     });    
    }
}

Error: Call to undefined method TestsBrowserPagesMyPage::assertTrue()

Can anyone help me?

Thank you.

Most helpful comment

Use static assertions:

use PHPUnit\Framework\Assert;

class MyPage extends Page
{
    public function validation(Browser $browser)
    {
        $browser ->clickLink('Sources');

        Assert::assertTrue(count($browser->driver->findElements(WebDriverBy::xpath('//*[@id="home"]'))) > 0);
     }
}

All 3 comments

Hi there,

Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.

Use static assertions:

use PHPUnit\Framework\Assert;

class MyPage extends Page
{
    public function validation(Browser $browser)
    {
        $browser ->clickLink('Sources');

        Assert::assertTrue(count($browser->driver->findElements(WebDriverBy::xpath('//*[@id="home"]'))) > 0);
     }
}

Thank you @staudenmeir. it is working now

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pdbreen picture pdbreen  路  4Comments

rauldeheer picture rauldeheer  路  4Comments

muswanto picture muswanto  路  3Comments

dmitryuk picture dmitryuk  路  5Comments

dellow picture dellow  路  4Comments