Acceptance tests failed in docker container

hi
i configured selenium but when i run acceptance tests inside app container i got this error:

  [Facebook\WebDriver\Exception\UnknownErrorException] unknown error: net::ERR_CONNECTION_CLOSED
  (Session info: chrome=85.0.4183.83)  

and in the app log i got this error:

app_1         | [Fri Oct  2 21:08:53 2020] 172.31.0.2:37898 Invalid request (Unsupported SSL request)
app_1         | [Fri Oct  2 21:08:53 2020] 172.31.0.2:37900 Invalid request (Unsupported SSL request)
app_1         | [Fri Oct  2 21:08:53 2020] 172.31.0.2:37902 Invalid request (Unsupported SSL request)
app_1         | [Fri Oct  2 21:08:53 2020] 172.31.0.2:37904 Invalid request (Unsupported SSL request)
app_1         | [Fri Oct  2 21:08:53 2020] 172.31.0.2:37906 Invalid request (Unsupported SSL request)
app_1         | [Fri Oct  2 21:08:53 2020] 172.31.0.2:37908 Invalid request (Unsupported SSL request)
app_1         | [Fri Oct  2 21:08:53 2020] 172.31.0.2:37910 Invalid request (Unsupported SSL request)
app_1         | [Fri Oct  2 21:08:53 2020] 172.31.0.2:37912 Invalid request (Unsupported SSL request)
app_1         | [Fri Oct  2 21:08:53 2020] 172.31.0.2:37914 Invalid request (Unsupported SSL request)

my acceptance.suite.yml config:

        - WebDriver:
            url: http://app:8001
            browser: chrome
            host: webdriver
            port: 4444

and docker-compose.yml

  app:
    image: yiisoftware/yii2-php:7.2-fpm
    volumes:
      - .:/app/
    ports:
      - 8001:8001
    depends_on:
      - mysql
      - webdriver
    command: bash -c "php -S 0.0.0.0:8001 -t /web"
    networks:
      - yii
  webdriver:
    image: selenium/standalone-chrome
    restart: always
    hostname: webdriver
    privileged: true
    shm_size: 2g
    ports:
      - 4444:4444
      - 5900:5900
    volumes:
#      # Mount shm, see https://github.com/SeleniumHQ/docker-selenium#running-the-images
      - /dev/shm:/dev/shm
    networks:
      - yii

i know it is relate to ssl but dont know how to solve it, this configuration is for local development.
would you please help me?

Show the test method code source.

1 Like

the tests example code:
<?php
use yii\helpers\Url;

    class ApiTestConnectionCest {

        public function testSuccessfullConnection(AcceptanceTester $I) {
            $I->amOnPage(Url::toRoute('/apis/update?id=1'));
            $I->fillField('input[name="LoginForm[username]"]', 'admin');
            $I->fillField('input[name="LoginForm[password]"]', 'asdassad');
            $I->click('login-button');
            $I->wait(1); // wait for button to be clicked        
            $I->see('Update Hotel Apis: The May Fair Hotel','h1');
            $I->amGoingTo('Test successful api connection!');
            $I->click('#connection-test');
            $I->wait(6);
            $I->see('Connection information is correct');
        }

    }

/tests/acceptance.suite.yml

class_name: AcceptanceTester
modules:
    enabled:
        - WebDriver:
            url: http://app:8001
            browser: chrome
            host: webdriver
            port: 4444
            capabilities:
                goog:chromeOptions:
                    args: ["allow-insecure-localhost","headless","start-maximized"]
        - Yii2:
            part: orm
            entryScript: index-test.php
            cleanup: false

i added goog:chromeOptions but it dosen’t work and tests failed again running in docker.

Show pls full message of error please, on which case it dose on line $I->amOnPage(Url::toRoute('/apis/update?id=1')); or $I->click('login-button');

Make testSuccessfullConnection method protected. Other tests are done or not?

1 Like

when i run in the docker acceptance tests failed but in the local computer; tests works correctly

E ApiTestConnectionCest: Test successfull connection (0.05s)                                                                                                         
------------------------------------------------------------------------
1) ApiTestConnectionCest: Test successfull connection                                                                                                                
 Test  tests/acceptance/ApiTestConnectionCest.php:testSuccessfullConnection                                                                                          
                                                                                                                                                                     
  [Facebook\WebDriver\Exception\UnknownErrorException] unknown error: net::ERR_CONNECTION_CLOSED                                                                     
  (Session info: headless chrome=85.0.4183.83)               

and application log:

app_1         | [Sat Oct  3 10:38:50 2020] 172.31.0.4:44068 Invalid request (Unsupported SSL request)
app_1         | [Sat Oct  3 10:38:50 2020] 172.31.0.4:44070 Invalid request (Unsupported SSL request)
app_1         | [Sat Oct  3 10:38:50 2020] 172.31.0.4:44072 Invalid request (Unsupported SSL request)
app_1         | [Sat Oct  3 10:38:50 2020] 172.31.0.4:44074 Invalid request (Unsupported SSL request)
app_1         | [Sat Oct  3 10:38:50 2020] 172.31.0.4:44076 Invalid request (Unsupported SSL request)
app_1         | [Sat Oct  3 10:38:50 2020] 172.31.0.4:44078 Invalid request (Unsupported SSL request)
app_1         | [Sat Oct  3 10:38:50 2020] 172.31.0.4:44080 Invalid request (Unsupported SSL request)
app_1         | [Sat Oct  3 10:38:50 2020] 172.31.0.4:44082 Invalid request (Unsupported SSL request)
app_1         | [Sat Oct  3 10:38:50 2020] 172.31.0.4:44084 Invalid request (Unsupported SSL request)
app_1         | [Sat Oct  3 10:38:50 2020] 172.31.0.4:44086 Invalid request (Unsupported SSL request)
app_1         | [Sat Oct  3 10:38:50 2020] 172.31.0.4:44088 Invalid request (Unsupported SSL request)
app_1         | [Sat Oct  3 10:38:50 2020] 172.31.0.4:44090 Invalid request (Unsupported SSL request)

Make this changes:

public function testSuccessfullConnection(AcceptanceTester $I) {
        echo Url::toRoute('/apis/update?id=1') . "\r\n"; 
        echo Url::toRoute('/apis/update?id=1', true); exit;
        $I->amOnPage(Url::toRoute('/apis/update?id=1'));

What output?

Maybe in config difference?

1 Like

output:
./apis/update?id=1
http://localhost./apis/update?id=1

i just changed tests/acceptance.suite.yml to
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://app:8001
browser: chrome
host: webdriver
port: 4444
capabilities:
goog:chromeOptions:
args: [“allow-insecure-localhost”,“headless”,“start-maximized”]
i dont why codeception try acceptance tests with ssl; the error show failing with ssl

Maybe try

suite_namespace: tests\acceptance
actor: AcceptanceTester

instead of

class_name: AcceptanceTester

in tests/acceptance.suite.yml

Has no more any ideas :tipping_hand_man:

1 Like

Thank you for taking the time :hugs:
but error not changed
i think error relate to ssl, i didn’t add https anywhere but codeception in docker selenium chrome try with ssl and it failed.

finally i solved the problem, change the container name from app to tools and problem solved.
it seems the app name is reserved by the browser and redirect to https.
my new docker-compose.yml file:
tools:
image: yiisoftware/yii2-php:7.2-fpm
volumes:
- .:/app/
ports:
- 8001:8001
depends_on:
- mysql
- webdriver
command: bash -c “php -S 0.0.0.0:8001 -t /web”
networks:
- yii
webdriver:
image: selenium/standalone-chrome
restart: always
hostname: webdriver
privileged: true
shm_size: 2g
ports:
- 4444:4444
- 5900:5900
volumes:
- /dev/shm:/dev/shm
networks:
- yii
and acceptance.suite.yml config:
WebDriver:
url: ‘http://tools:8001/’
browser: chrome
host: webdriver
port: 4444

2 Likes

Congratulations, this is incredible)

1 Like