I'm trying to run the tests using Makefile. I'm using behave, Selenium and selenium webdrivers and the issue that I face when I try to run the tests trough following command in Makefile:
$(DOCKER_EXEC) bash -c "behave test.feature --junit -D driver=firefox
is that I receive an error that: SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary'. As if the firefox was not installed in this container.
I have even tried to run the tests on the selenium grid server, by specyfing those lines in docker-compose file:
selenium-hub:
image: selenium/hub:latest
container_name: selenium-hub
ports:
- "4442:4442"
- "4443:4443"
- "4444:4444"
firefox:
image: selenium/node-firefox:beta
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
And when I run the container I'm able to run the tests on my end on port 4444 trough visual studio using the very same command I use in Makefile but when I do the same trough the Makefile:
$(DOCKER_EXEC) bash -c "behave test.feature --junit -D driver=firefox -D remote="http://localhost:4444""
it says:
Failed to establish a new connection: [Errno 111] Connection refused.
I also tried to use the "jlesage/firefox" image instead but no luck here either.
Without it I'm unable to run my tests in Behave&Selenium using Makefile.
Related
I'm currently having this issue:
[Facebook\WebDriver\Exception\UnknownErrorException] unknown error: net::ERR_CONNECTION_REFUSED
(Session info: chrome=96.0.4664.45)
What I'm trying to do is for my dockerized webdriver which is on localhost:4444 access localhost:7070 which contains one of services that was port-forwarded thru OpenShift CLI and is accessible locally using any browsers.
``
I run the dockerized webdriver using this command:
docker run -d -p 4444:4444 --shm-size="2g" selenium/standalone-chrome:4.1.0-20211123
Here is the environment variable:
modules:
config:
WebDriver:
url: http://localhost:4444
browser: chrome
capabilities:
chromeOptions:
args: ["no-sandbox", "--disable-gpu"]
Here is the stepdefinition:
public function access7070Site() {
$this->acceptanceTester -> amOnUrl('http://localhost:7070');
}
When I try to access external sites, the webdriver can access it, however, when I access other localhost port its having the Connection Refused issue. Am I missing something else?
If you want to run it with docker, I suggest to use docker-compose to do so.
Here is a working docker-compose.yaml which is using your project in parallel to selenium and takes care of the networking between the containers:
---
version: '3.4'
services:
php:
build: .
depends_on:
- selenium
volumes:
- ./:/usr/src/app:rw,cached
selenium:
image: selenium/standalone-chrome:4
shm_size: 2gb
container_name: selenium
ports:
- "4444:4444"
- "7900:7900"
environment:
- VNC_NO_PASSWORD=1
- SCREEN_WIDTH=1920
- SCREEN_HEIGHT=1080
after you created this file, you can simply run docker-compose up -d to start the containers and type this to start your webdriver tests:
docker-compose exec php vendor/bin/codecept run
And one nice feature is, that you can connect the selenium container via VNC and see, what the test is actually doing: http://localhost:7900/
I'm having an issue trying to dockerize my webdriverIO testing framework and running the tests on the existing selenium/standalone-chrome image with docker-compose.
I have a simple dockerfile to build the app such as this:
FROM node:12
ADD . /app
WORKDIR /app
RUN npm install
Then I have a docker-compose.yaml to build the stack and run the tests:
version: "3"
services:
app:
build: .
command: npm test -- --host selenium
links:
- selenium
selenium:
network_mode: host
image: selenium/standalone-chrome
volumes:
- /dev/shm:/dev/shm
ports:
- "4444:4444"
My conf.js file sets the host and port like so:
exports.config = {
host: 'selenium',
port: 4444,
No matter what I try, I continue to get the following error after docker-compose build and docker-compose up:
[0-9] Error: Failed to create session.
app_1 | Unable to connect to "http://127.0.0.1:4444/", make sure browser driver is running on that address.
app_1 | If you use services like chromedriver see initialiseServices logs above or in wdio.log file as the service might had problems to start the driver.
Any helpful information on why I would see this type of error would be helpful. Thanks in advance.
Tl;dr I'm using Docker to run my Postman/Newman tests and my API tests hang when ran in Travis-CI but not when ran locally. Why am I encountering tests that run infinitely?
Howdy guys! I've recently started to learn Docker, Travis-CI and Newman for a full stack application. I started with developing the API and I'm taking a TDD approach. As such, I'm testing my API first. I setup my .travis.yml file to download a specific version of Docker-Compose and then use Docker-Compose to run my tests in a container I name api-test. The container has an image, dannydainton/htmlextra, which is built from the official postman/newman:alpine image like so:
language: node_js
node_js:
- "14.3.0"
env:
global:
- DOCKER_COMPOSE_VERSION: 1.26.2
- PGHOST: db
- PGD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s7C9z2604VLybdOmJ0+Y/7uIo6po388avGN4ZwZbWQ1xiiW+Ja8kkHZYEKo4m0AbKdX9pn8otcNO+1xlDtUU7CZey2QA8WrFlfHWqRapIgNfT5tTSTAul3yWAFCRw09PHYELuO7oQCqFZi7zu3HKWknbkzjf+Cz3TfIFTX/3saiqyquhieOPbnGC5xgTmTrA2ShfNxQ6nkDJPU0/qmaCNJt9CwpNS2ArqcK3xYijiNi+SHaKwEsYh0VqiUqSCWn05eYKNAe3MUQDsyKFEkykJW60yEkN7JsvO1WpI53VKmOnZlRHLzJyc5WkZw="
- PGPORT: 5432
services:
- docker
before_install:
- npm rebuild
- sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
jobs:
include:
- stage: api tests
script:
- docker --version
- docker-compose --version
- >
docker-compose run api-test
newman run battle-academia_placement-exam_api-test.postman-collection.json
-e battle-academia_placement-exam_docker.postman-environment.json
-r htmlextra,cli
And, my docker-compose.yml file has 4 containers:
client is the React front end,
api is the NodeJs/Express back end,
db is the database that the API pulls data from in the test environment,
api-test is the container with Newman/Postman and some reporters which I believe is built from NodeJs.
I hardcode in the environment variables when running locally, but the file is as follows:
version: '3.8'
services:
client:
build: ./client
ports:
- "80:80"
depends_on:
- api
api:
build: ./server
environment:
- PGHOST=${PGHOST}
- PGDATABASE=${PGDATABASE}
- PGUSER=${PGUSER}
- PGPASSWORD=${PGPASSWORD}
- PGPORT=${PGPORT}
ports:
- "3000:3000"
depends_on:
- db
db:
image: postgres:12.3-alpine
restart: always
environment:
- POSTGRES_DB=${PGDATABASE}
- POSTGRES_USER=${PGUSER}
- POSTGRES_PASSWORD=${PGPASSWORD}
ports:
- "5432:5432"
volumes:
- ./server/db/scripts:/docker-entrypoint-initdb.d
api-test:
image: dannydainton/htmlextra
entrypoint: [""]
command: newman run -v
volumes:
- ./server/api/postman-collections:/etc/newman
depends_on:
- api
Now that the setup is out of the way, my issue is that this config works locally when I cut out .travis.yml and run the commands myself, however, putting Travis-CI in the mix stirs up an issue where my first test just... runs.
I appreciate any advice or insight towards this issue that anyone provides. Thanks in advance!
The issue did not come from where I had expected. After debugging, I thought that the issue originally came from permission errors since I discovered that the /docker-entrypoint-initdb.d directory got ignored during container startup. After looking at the Postgres Dockerfile, I learned that the files are given permission for a user called postgres. The actual issue stemmed from me foolishly adding the database initialization scripts to my .gitignore.
Edit
Also the Newman tests were hanging because they were trying to access database tables that did not exist.
I am working on implementing selenium docker grid in my project. I am facing problem when connecting with a custom defined node-chrome docker node containers with updated browser version. Below are the details.
Environment:
Windows 10 base machine
Ubuntu 18.04/16.04 virtual machine.
Project:
Python Pytest Selenium
The test cases run fine when run with selenium/hub:3.11.0-dysprosium and selenium/node-chrome:3.11.0-dysprosium . The image was created with selenium-server-standalone-3.11.0.jar and chrome version 66 and those are downloaded from https://hub.docker.com/
Then, creating a custom docker image based on selenium-server-standalone-3.11.0.jar and with latest chrome/chormedriver version i.e. 81.
Steps to create docker image:
Please refer https://github.com/SeleniumHQ/docker-selenium/wiki/Building-your-own-images
• git clone https://github.com/SeleniumHQ/docker-selenium.git
• cd docker-selenium
• git checkout tags/3.11.0-dysprosium
• make generate_all
• sudo docker build -t selenium/node-chrome:1.2 --build-arg CHROME_DRIVER_VERSION=81.0.4044.69 --build-arg CHROME_VERSION=google-chrome-stable=81.0.4044.92-1 NodeChrome
Once the image is build, I am using this local image in the docker-compose file.
The hub and node are launched successfully, chrome session is also created, but the python+pytest test hangs.
[1586871890.350][SEVERE]: bind() failed: Cannot assign requested address (99) [Based on the googling, actually this error should not be a stopper to test run, but mentioning it here]
“13:44:50.256 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
Starting ChromeDriver 81.0.4044.69 (6813546031a4bc83f717a2ef7cd4ac6ec1199132-refs/branch-heads/4044#{#776}) on port 17653
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1586871890.350][SEVERE]: bind() failed: Cannot assign requested address (99)
13:44:50.850 INFO [ProtocolHandshake.createSession] - Detected dialect: W3C
13:44:50.927 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session 98b823ca35a6d3cc17e666b7911551c4 (org.openqa.selenium.chrome.ChromeDriverService)”
The same test pass when run through standalone server node and hub (w/o docker) and test were running on chrome browser version 80+.
Please note, the project code is yet is not updated to work with higher version of on selenium-server-standalone.
Docker-compose.yml
services:
selenium-hub:
image: selenium/hub:3.11.0-dysprosium
container_name: selenium-hub
ports:
- "4444:4444"
environment:
- GRID_DEBUG=true
chrome:
image: selenium/node-chrome:1.2
depends_on:
- selenium-hub
ports:
- 9901:9500
- 5555:5555
expose:
- "9515"
- "5555"
environment:
- GRID_DEBUG=true
- HUB_HOST=selenium-hub
- HUB_PORT=4444
- NODE_BROWSER_NAME=chrome
- NODE_SELENIUM_PROTOCOL=WebDriver
- DBUS_SESSION_BUS_ADDRESS=/dev/null
- NODE_MAX_INSTANCES=2
- NODE_MAX_SESSION=2
- VNC_NO_PASSWORD=1
volumes:
- /dev/shm:/dev/shm
links:
- selenium-hub
privileged: true
community,
I'm stuck with the running of protractor tests in docker. Please help me to resolve my problem. Thanks
Here is what I'm trying to do.
I'm packing Angular application with protractor e2e tests
baseUrl: 'http://localhost:4200/',
seleniumAddress: 'http://172.18.0.2:4444/wd/hub/',
to a docker image with help of Docker file
FROM node:12.8.1-alpine as build-step
WORKDIR /app
COPY package.json ./
RUN npm install
RUN npm install -g protractor#5.4.2
RUN apk add openjdk8
ENV PATH $PATH:/usr/lib/jvm/java-1.8-openjdk/bin
COPY . .
EXPOSE 4200 4444
CMD npm start
I'm running docker-compose contains running of selenium grid containers(hub and chrome) and dockerfile above
version: "3"
services:
hub:
container_name: hub
image: selenium/hub:3.141.59
privileged: true
ports:
- 4444:4444
environment:
- GRID_BROWSER_TIMEOUT=240000
- GRID_TIMEOUT=240000
chrome:
container_name: node-chrome
image: selenium/node-chrome:3.141.59
privileged: true
shm_size: 256M
depends_on:
- hub
environment:
- HUB_HOST=hub
- no_proxy=localhost
- HUB_PORT_4444_TCP_ADDR=hub
- HUB_PORT_4444_TCP_PORT=4444
testapp:
container_name: testapp
build: .
image: dneprokos/testapp
ports:
- "4200:4200"
depends_on:
- chrome
- hub
I'm trying to execute protractor conf file command in order to run e2e tests. (seleniumAddress: 'http://172.18.0.2:4444/wd/hub/')
docker container exec -it testapp sh // to attach
protractor ./e2e/protractor.conf.js // to run tests
Notes:
First I tried to run tests inside of the container with localhost, but than realized it contains another host inside of the container. But it hasn't resolved the problem even when I've changed the host.
Also, I tried do not run grid containers, but using "webdriver-manager update" and "webdriver-manager start" commands. Starting works fine, but the same problem happens during tests start.
As you may seem I've exposed ports, so I can easily check it works locally for both selenium grid and test application.
Only one thing, if I'm trying to connect locally to "http://localhost:4444/wd/hub/" it shows me the following exception:
"sessionId": null,
"status": 13,
"value": {
"class": "org.openqa.grid.common.exception.GridException",
"error": "unknown error",
"message": "Session [(null externalkey)] not available and is not among the last 1000 terminated sessions.\nActive sessions are[]",
Expected Result: Test run should be started
Actual Result:
[17:44:34] E/launcher - Error code: 135
[17:44:34] E/launcher - Error message: ECONNREFUSED connect ECONNREFUSED 172.18.0.2:4444
[17:44:34] E/launcher - Error: ECONNREFUSED connect ECONNREFUSED 172.18.0.2:4444
at ClientRequest.<anonymous> (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:238:15)
at ClientRequest.emit (events.js:203:13)
at Socket.socketErrorListener (_http_client.js:399:9)
at Socket.emit (events.js:203:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
From: Task: WebDriver.createSession()
at Function.createSession (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:769:24)
Thanks to a comment I've resolved my problem. Just need to use containers name for application base URL and Selenium Hub URL in protractor.conf, like this
'http://hub:4444/wd/hub'
'baseUrl=http://testapp:4200'
Also, I found I need to start an angular application with a following command "ng serve --host 0.0.0.0 --disable-host-check". In another case, there will be some troubles with opening application in the container.