[英]How to work with Page Objects in laravel-dusk
I'm a new in a php and dusk, but I try to work with page object in dusk, and I'm stuck because when I try to add page object to test, phpstorm said me that "Method logInUserName not found in $this". 我是php和黄昏的新手,但是我尝试在黄昏使用页面对象,并且因为在尝试添加页面对象进行测试时,我被卡住了,phpstorm说“在此$ this中找不到方法logInUserName ”。 Can someone explain to me where i'm wrong? 有人可以向我解释我错了吗?
I have page class: 我有页面课程:
<?php
namespace Tests\Browser\Pages;
use Laravel\Dusk\Browser;
class LogInPage extends Page
{
/**
* Get the URL for the page.
*
* @return string
*/
public function url()
{
return '/login';
}
/**
*
* @return void
*/
public function logInUserName(Browser $browser)
{
$browser->type("#username", "lol");
}
} }
I have test class 我有考试课
use Tests\Browser\Pages\LogInPage;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use PHPUnit\Framework\Assert;
class ExampleTest extends DuskTestCase
{
/**
* A basic browser test example.
*
* @return void
*/
public function testLogInFail()
{
$this->browse(function (Browser $browser) {
$browser
->visit(new LogInPage)
->logInUserName()
->keys("#password","lol")
->click("button.btn-primary"));}
Agree this is annoying, there are 2 ways you could get around this 同意这很烦人,有2种方法可以解决这个问题
$browser
->visit(new LogInPage)
->logInUserName();
$browser
->keys("#password","lol")
->click("button.btn-primary"));
Or use this gist and create a file in the root of your project that your IDE will read - https://gist.github.com/slava-vishnyakov/5eb90352fc97702f53a41888e5bae27a 或使用此要点在IDE读取的项目根目录中创建一个文件-https: //gist.github.com/slava-vishnyakov/5eb90352fc97702f53a41888e5bae27a
Only issue is you may get a PHPSTORM warning about multiple definitions exist for class Browser...not sure how to get around that 唯一的问题是您可能会收到有关类Browser的多个定义的PHPSTORM警告...不确定如何解决该问题
Results in something like this 结果是这样的
<?php
namespace Laravel\Dusk {
class Browser
{
/**
* @return Browser
*/
public function logInUserName()
{
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.