我尝试用dash测试我的登录表单。在前端我使用vue组件。当我尝试访问电子邮件输入并设置值时,我收到错误:
1) Tests\Browser\LoginTest::testExample
Facebook\WebDriver\Exception\NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"body [dusk="login-email"]"}
(Session info: headless chrome=84.0.4147.105)
登录表单:
<form @submit.prevent="submitForm" class="q-mt-lg">
<div class="col q-mb-md">
<q-input
v-model="formData.email"
outlined
type="email"
dusk="login-email"
class="col"
data-email
label="Email"
ref="email"
stack-label
:rules="[ val => validateEmail(val) || 'Please enter a valid email address']"
lazy-rules />
</div>
<div class="col q-mb-md">
<q-input
v-model="formData.password"
type="password"
dusk="login-password"
outlined
class="col"
label="Password"
ref="password"
stack-label
:rules="[ val => val.length >= 8 || 'Password must be at least 8 characters']"
lazy-rules />
</div>
<div class="row">
<q-btn
type="submit"
dusk="login-btn"
name="login"
class="login"
color="primary"
label="Login" />
</div>
</form>
我的测试:
<?php
namespace Tests\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
use App\User;
class LoginTest extends DuskTestCase
{
/**
* A Dusk test example.
*
* @return void
*/
public function testExample()
{
$this->browse(function ($browser) {
$browser->visit('/login')
->type('@login-email', 'test@test.com')
->type('@login-password', '12345678')
->press('@login-btn')
->assertPathIs('/');
});
}
}
我的项目在http://localhost:3002上工作
在.env文件中- APP_URL=http://本地主机
在黄昏测试案例.php中
protected function driver()
{
$options = (new ChromeOptions)->addArguments([
'--disable-gpu',
'--headless',
'--window-size=1920,1080',
'--no-sandbox'
]);
return RemoteWebDriver::create(
'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)
);
}
如果我将APP_URL更改为http://localhost:3002,错误还是一样。您能帮助我解决这个问题吗?谢谢!
1条答案
按热度按时间wgx48brx1#
我对黄昏也有同样的问题,还有很多很多。
您可以执行一些操作来修复此错误,但要找到适合您的特定版本的修复程序可能会很困难。
APP_URL
变量在你的**.env**文件中。确保这是实时应用程序正在运行的正确URL。IE参数必须与实际匹配。例如: