Laravel Dusk on Docker does not login users

111 Views Asked by At

A Laravel application with Dusk works completely fine in Homestead, but when I moved it to docker, I got Dusk and Selenium running and what seems to happen is that the the tests hit the dusk authentication endpoints but then it just redirects to the login page because it fails to log the user in, on Homestead, the loginAs works fine.

Any ideas what it could be? An issue of session sharing between containers?

    volumes:
      vendor: ~
      node_modules: ~
      public: ~
    
    services:
      nginx:
        container_name: myapp-nginx-dev
        build:
          context: .
          dockerfile: ./dockerfiles/Dockerfile.dev.nginx
        ports:
          - "80:80"
        # mount server config for development and public volume to be served
        # (this will be edited by the webpack server)
        volumes:
          - ./build/nginx/conf.d/dev.conf:/etc/nginx/conf.d/default.conf
          - public:/var/www/html/public
        restart: unless-stopped
        # depends on php and npx mix watch module
        depends_on:
          php:
            condition: service_started
          node:
            condition: service_started
        networks:
          - my-app-net
    
      php:
        container_name: my-app-php-dev
        hostname: my-app-php-dev
        build:
          context: .
          dockerfile: ./dockerfiles/Dockerfile.dev.php
        # mount the src code and vendor volumne
        volumes:
          - vendor:/var/www/html/vendor
          - .:/var/www/html
          - ./build/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
        # provide .env file
        env_file:
          - .env
        environment:
          XDEBUG_CONFIG: remote_host=host.docker.internal remote_port=9001
        restart: unless-stopped
        # needs healthy database instance
        depends_on:
          mongodb:
            condition: service_healthy
          redis:
            condition: service_healthy
        networks:
          - my-app-net
    
      selenium:
        container_name: my-app-selenium-dev
        image: selenium/standalone-chrome:4.3
        volumes:
          - /dev/shm:/dev/shm
        ports:
          - "4444:4444"
          - "7900:7900"
        networks:
          - my-app-net
        depends_on:
          - php
    
    networks:
      my-app-net:
        external: true
public function testTheTest() {
        $this->browse(function (Browser $browser) {
            $browser->loginAs($this->administrator)
            ->visit(self::URL)
            ->screenshot('test')
            ->assertSee('Departments');
        });
    }
0

There are 0 best solutions below