BehatPageObjectExtension icon indicating copy to clipboard operation
BehatPageObjectExtension copied to clipboard

getDriver method is not available in Page class

Open RebOOter opened this issue 8 years ago • 13 comments

When I trying to use open() function then I see error message:

"getDriver" method is not available on the LoginPage (BadMethodCallException)

I noticed that it's true, Page class doesn't have this method. I use $this->getSession()->getDriver(); instead of $this->getDriver(); and it's works.

Maybe this is a simple mistake?

RebOOter avatar Jul 05 '17 07:07 RebOOter

Umh, getDriver should be there as of

Page -- extends --> DocumentElement --> TraversableElement --> Element (here's the method).

Are you sure you're extending right Page class?

DonCallisto avatar Jul 05 '17 08:07 DonCallisto

I extended class use SensioLabs\Behat\PageObjectExtension\PageObject\Page;

I look through the all extends and I think it's problem in Mink version 1.5. In this version Element class really doesn't have a getDriver() method when in 1.7 this method implemented.

Probably it would be better to add minimal stability version to documentation or to composer if it possible?

RebOOter avatar Jul 05 '17 11:07 RebOOter

@RebOOter Take a look to https://github.com/sensiolabs/BehatPageObjectExtension/tree/v2.1.0

It has mink 1.6 https://github.com/sensiolabs/BehatPageObjectExtension/blob/v2.1.0/composer.json#L11

Alternatively master has 1.7

Don't know if older versions need to be fixed /cc @jakzal

DonCallisto avatar Jul 05 '17 12:07 DonCallisto

Yes, I see, but this requirement doesn't work if in your project will be requirement of another version. Composer doesn't tell you to use another version of Mink when it's needed.

RebOOter avatar Jul 05 '17 13:07 RebOOter

@RebOOter that's not true because if a dependency like BehatPageObjectExtension has ^1.7 for Mink and you have specified in composer.json of your project a version of Mink <1.7, composer itself will prevent you from installing the bundle, warning about the necessity of a newer version of Mink or a lower version of this bundle.

DonCallisto avatar Jul 05 '17 13:07 DonCallisto

Maybe I'm mistaken but

but this requirement doesn't work if in your project will be requirement of another version.

Another version of what? Of this bundle or of Mink?

DonCallisto avatar Jul 05 '17 13:07 DonCallisto

@RebOOter can you paste relevant bits of composer show | grep behat command please? I'm mainly after behat/* and sensiolabs/behat-page-object-extension packages.

jakzal avatar Jul 05 '17 13:07 jakzal

composer show | grep behat command log:

behat/behat                            v3.3.0             Scenario-orient...
behat/gherkin                          dev-master 5c14cff Gherkin DSL par...
behat/mink                             v1.5.0             Web acceptance ...
behat/mink-browserkit-driver           v1.1.0             Symfony2 Browse...
behat/mink-extension                   v2.2               Mink extension ...
behat/mink-goutte-driver               v1.0.9             Goutte driver f...
behat/mink-selenium2-driver            v1.1.1             Selenium2 (WebD...
behat/transliterator                   dev-master 826ce7e String translit...
sensiolabs/behat-page-object-extension v2.0.0             Page object ext...

In composer file I have: "behat/mink": "1.5@stable",

As you can see composer not prevent me from installing old version of Mink that doesn't have getDriver() function. PageObject extension shouldn't installed while you have version of Mink that not supported.

For now I trying to use "behat/mink": "^1.7", and this version of Mink have the getDriver() but I have another problem with 1.7 (this problem is no appeared in 1.5@stable): Fatal error: Call to a member function open() on null (Behat\Testwork\Call\Exception\FatalThrowableError)

The same code. Changes are only in composer.json. That the reason why I use 1.5@stable version. Maybe I have some mistakes somewhere, but this behavior is still strange for me.

RebOOter avatar Jul 05 '17 19:07 RebOOter

As I told you, v2.0.0 of this bundle doesn't take into account this whereas 2.0.1 and 2.1.0 does.

My suggestion is to upgrade to 2.0.1 at least.

DonCallisto avatar Jul 06 '17 07:07 DonCallisto

Indeed, mink dependency wasn't explicit in v2.0.0. It only became apparent it's needed in v2.0.1 when we started running tests against low versions of dependencies.

I recommend updating the page object extension to the latest version.

For now I trying to use "behat/mink": "^1.7", and this version of Mink have the getDriver() but I have another problem with 1.7 (this problem is no appeared in 1.5@stable): Fatal error: Call to a member function open() on null (Behat\Testwork\Call\Exception\FatalThrowableError)

If you prepared a project to reproduce this problem I could have a look.

jakzal avatar Jul 06 '17 08:07 jakzal

Here the project with this issue https://github.com/RebOOter/page-object-bug

But, I notice that in my composer file was the line with "minimum-stability": "dev". Without this option everything fine from every sides. I leave this option in the test project that you can look. I don't know where I found this, but this is the reason of my mistake. You can check the error with open() function, maybe some changes in some other library broke your library and this would help you.

Sorry for misunderstanding and thanks for advices.

RebOOter avatar Jul 06 '17 17:07 RebOOter

I managed to pin point the problem to behat/mink. It works with the stable version, but not with the latest master. It might have something to do with https://github.com/minkphp/Mink/commit/acf5fb1ec70b7de4902daf75301356702a26e6da but I haven't looked deeper yet.

jakzal avatar Jul 07 '17 15:07 jakzal

By the way, you should create page objects/elements with the factory rather than calling their constructors directly.

jakzal avatar Jul 07 '17 15:07 jakzal