Laravel Dusk-无法连接到本地主机端口9515:连接被拒绝 [英] Laravel Dusk - Failed to connect to localhost port 9515: Connection refused

查看:301
本文介绍了Laravel Dusk-无法连接到本地主机端口9515:连接被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个要在Controller中使用的测试,所以我写:

I want to create a test which I will use from Controller so I write:

<?php

namespace App\Http\Controllers\Modules;
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Laravel\Dusk\ElementResolver;
use Exception;

use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Laravel\Dusk\Browser;
use Laravel\Dusk\Chrome\ChromeProcess;

class TestController extends Controller {



  public function test() {

    $process = (new ChromeProcess)->toProcess();
    if ($process->isStarted()) {
      $process->stop();
    }
    $process->start();

    $options      = (new ChromeOptions)->addArguments(['--disable-gpu', '--headless', '--no-sandbox']);
    $capabilities = DesiredCapabilities::chrome()
      ->setCapability(ChromeOptions::CAPABILITY, $options);

          $driver = retry(1, function () use ($capabilities) {
      return RemoteWebDriver::create('http://localhost:9515', $capabilities, 60000, 60000);
    }, 50);

    $browser = new Browser($driver, new ElementResolver($driver, ''));
    $browser->resize(1920, 1080);
    $browser->visit('https://example.com/login')->click('#.btn > form > div.auth-form-body.mt-3 > input.btn.btn-primary.btn-block');
    $browser->driver->takeScreenshot(base_path('tests/Browser/screenshots/logged.png'));

  }


}

当我使用localhost:8000/test运行此脚本时,收到以下消息:

When I run this script using localhost:8000/test I got this message:

Facebook \ WebDriver \异常\ WebDriverCurlException卷曲错误 使用参数将http POST抛出到/session: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"binary":","args":[-disable-gpu",-无头,"-无沙箱]}}} 无法连接到本地主机端口9515:连接被拒绝

Facebook \ WebDriver \ Exception \ WebDriverCurlException Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"binary":"","args":["--disable-gpu","--headless","--no-sandbox"]}}} Failed to connect to localhost port 9515: Connection refused

我该如何解决这个问题?

How I can solve this problem?

当前,我在Win10上使用WAMP服务器进行本地测试,但随后我将在Linux Ubuntu 18上移动代码.

Current I use WAMP server on Win10 for local testing but then I will move the code on Linux Ubuntu 18.

推荐答案

我无法完全解释它,但这在Windows上对我有用:

I can't fully explain it, but this works for me on Windows:

$process = (new ChromeProcess)->toProcess();
if ($process->isStarted()) {
  $process->stop();
}

$process->start(null, [
    'SystemRoot' => 'C:\\WINDOWS',
    'TEMP' => 'C:\Users\<User>\AppData\Local\Temp',
]);

[...]

用您的用户目录名称替换<User>.

Replace <User> with the name of your user directory.

这篇关于Laravel Dusk-无法连接到本地主机端口9515:连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆