0

This has definitely been answered more then once. But I don't get it for my case.

So I am writing browser-test for a part of our projekt.

The function is, that there are users, that can login and other that are not allowed. So I wrote a 2 tests. TestA. tries to login without permissions and I check if the pop-up "there went something wrong" is visible. The other TestB is a registrated user. I check if he can reach the "shop" page.

So I wrote a Method in the Class LoginPage.php

class LoginPage.php

 public function guiLoginUser(Browser $browser)
    {
        $browser->type('#email', 'normal.user______@hey.ch')
            ->type('#password', 'ThisCanBeWhatever2')
            ->click('#login');

    }

    public function guiLoginNoUser(Browser $browser)
    {
        $browser->type('#email', 'not.a.user______@nouser')
            ->type('#password', 'ThisCanBeWhatever')
            ->click('#login');

As of now our project dose not check the password, as we do not have access to the Database.

This class contains the testA and testB. I will only be showing test B as the testA is the more or less the same, just using another emai.

    public function testB(){
    $this->browse(function ($browser) {
        $browser
            // URL:
            ->visit('/login');
            // Login:
        $browser->visit(new LoginPage()){
        $this->guiLoginNormalUser($browser)
        }
        // Action:
            ->assertSee("Shop");
    });


}

I know the code dose not work but I am new to OOP and I don't understand how to call the method of the other class.

I hope someone can help me.

thanks in advance

Janick

1 Answers1

0

Instead of

 new LoginPage()){
    $this->guiLoginNormalUser($browser)
    }

do that:

(new LoginPage())->guiLoginNormalUser($browser)

the brackets around new LoginPage() are neccessary to be able refer to that new object later with ->

It's basicly the same as doing

$loginPage = new LoginPage();
$loginPage->guiLoginNormalUser($browser);

But since you can't pass in two statements we need to shrink it down to a oneliner.

Jeff
  • 6,895
  • 1
  • 15
  • 33