hey sir. Do you get the solution please?
Dusk automation system on remote shared hosting => Connection refused
Hello!
I programmed some kind of "robot" using Laravel Dusk, to automate repetitive tasks that i do on a website. I'm not writing tests in the /tests/Browser section though. My Dusk code is in my controller, and I have a 'dashboard' view from which i can control which functions from the controller will be called. So, my Dusk automation system is controlled from the browser and not from a terminal. Note (probably not important) : my application requires authentication (i'm using Laravel Breeze).
Here is an example of a function in the controller:
public function dispatchJobs()
{
$user_email = auth()->user()->email;
$user_password = 'password';
$process = (new ChromeProcess)->toProcess();
$process->start();
$options = (new ChromeOptions)->addArguments(['--disable-gpu', '--no-sandbox']);
$capabilities = DesiredCapabilities::chrome()->setCapability(ChromeOptions::CAPABILITY, $options);
$driver = retry(5, function () use($capabilities) {
return RemoteWebDriver::create('http://localhost:9515', $capabilities);
}, 50);
$browser = new Browser($driver);
$browser->visit('http://my-website.com/login')
->type('login_form[username_email]', $user_email)
->type('login_form[password]', $user_password)
->press('Login');
// rest of the code
$browser->quit();
$process->stop();
return true;
}
As long as i was running my application locally, it worked well, even though i did more and more often get the message:
Facebook\WebDriver\Exception\WebDriverCurlException
Curl error thrown for http POST to /session with params: {"capabilities":{"firstMatch":[{"browserName":"chrome","goog:chromeOptions":{"args":["--disable-gpu","--no-sandbox"]}}]},"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"args":["--disable-gpu","--no-sandbox"]}}} Failed to connect to localhost port 9515: Connection refused
Now I uploaded the application to a shared hosting service on GoDaddy (i want to host it online because eventually it may have to be used from different computers... maybe different people). But i can't get past this same error. Everything else works fine, layout is fine, i can create, delete, display 'jobs' and it's all good. But Dusk won't work.
Should i modify my .env file when uploading my application to a remote server? This is what it contains.
.env
APP_URL=http://DuskDispatch.test
...
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
To be honest, i have no idea what those parameters really mean. I tried a few different values for APP_URL, without any better results, and without really understanding what i should put there. Could someone please explain what APP_URL is? I read about it but i don't understand what it means, where it comes from or anything. Should it be like this?
APP_URL=http://my-dispatcher-website.com/dashboard
Note : here, my-dispatcher-website.com (= my Laravel application) would be the website from which i automate certain actions on my-website.com
My /config/app.php contains this line:
'url' => env('APP_URL', 'http://localhost'),
Should i change it?
I read several times that a solution to my problem might be to:
sudo apt-get install libnss3-dev
sudo apt-get install chromium-browser
or something like this :
# makes sure all your repos are up to date
sudo apt-get update
# chrome dependencies I think
sudo apt-get -y install libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4
# chromium is what I had success with on Codeship, so seemed a good option
sudo apt-get install chromium-browser
# XVFB for headless applications
sudo apt-get -y install xvfb gtk2-engines-pixbuf
# fonts for the browser
sudo apt-get -y install xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable
# support for screenshot capturing
sudo apt-get -y install imagemagick x11-apps
# Once all this has run through, you need to fire up xvfb on your homestead box. If you’re planning to
# do this on a regular basis, you’ll want to get this setup on boot, but for the sake of testing things out:
Xvfb -ac :0 -screen 0 1280x1024x16 &
but i don't have access to sudo on GoDaddy shared hosting plan. I get this:
bash: sudo: command not found
and don't seem to be able to install it.
Is it not possible to use a "Dusk robot" hosted remotely on a shared server?
Thank you.
Please or to participate in this conversation.