Behat with Selenium Hub and Firefox Error: Could not open connection: Payload received from webdriver is valid but unexpected json - selenium

I'm trying to run Behat on Docker using selenium/hub, selenium/node-chrome-debug and selenium/node-firefox-debug images.
Running Behat with the Chrome node is working, but the Firefox node gives me the following error:
Could not open connection: Payload received from webdriver is valid but unexpected json: {"value":{"sessionId":"244f4715-c59b-4bfc-aa17-8f6a867ead83","capabilities":{"moz:profile":"/tmp/rust_mozprofile.u3mB4xKf6nVD","rotatable":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"pageLoadStrategy":"normal","moz:headless":false,"moz:accessibilityChecks":false,"acceptInsecureCerts":false,"browserVersion":"57.0","platformVersion":"4.9.60-linuxkit-aufs","moz:processID":1005,"browserName":"firefox","platformName":"linux","moz:webdriverClick":false}}} (Behat\Mink\Exception\DriverException)
When I vnc to Firefox node, I see it opened Firefox, but nothing is happening.
My docker-compose.yml:
version: '3.2'
services:
site.local:
image: webdevops/php-apache-dev:7.1
ports:
- "8888:80"
volumes:
- ./public:/app
- .:/application
selenium-grid-hub.local:
image: selenium/hub
ports:
- "4445:4444"
selenium-node-chrome.local:
image: selenium/node-chrome-debug
environment:
- HUB_PORT_4444_TCP_ADDR=selenium-grid-hub.local
- HUB_PORT_4444_TCP_PORT=4444
ports:
- "5901:5900"
selenium-node-firefox.local:
image: selenium/node-firefox-debug
environment:
- HUB_PORT_4444_TCP_ADDR=selenium-grid-hub.local
- HUB_PORT_4444_TCP_PORT=4444
ports:
- "5902:5900"
My behat.yml:
default:
extensions:
Behat\MinkExtension:
base_url: "http://site.local"
goutte:
guzzle_parameters:
verify: false
suites:
mysuite:
paths: [ %paths.base%/features ]
contexts:
- Zstate\BehatSeleniumDockerSkeleton\Tests\Behat\Context\FeatureContext
chrome:
extensions:
Behat\MinkExtension:
selenium2:
browser: "chrome"
wd_host: http://selenium-grid-hub.local:4444/wd/hub
capabilities: {"browserName": "chrome", "browser": "chrome", 'chrome': {'switches':['--no-sandbox']}}
firefox:
extensions:
Behat\MinkExtension:
selenium2:
browser: "firefox"
wd_host: http://selenium-grid-hub.local:4444/wd/hub
capabilities: {"browserName": "firefox", "browser": "firefox"}
I created this small repo to replicate the issue.
I would greatly appreciate any help or advice. Please let me know if I miss something in my question so I can update it.

In case someone has the same error, this was what helped me.
In my case, the way to solve it was by establishing the following:
for chrome:
capabilities: {"extra_capabilities":{"chromeOptions":{"w3c":false}}}
More info here.

Related

How to configure Selenium Grid in docker-compose.yml (max session)

I couldn't find how to configure the Selenium Grid with Docker Compose.
How can I set for example the maxSessions in the docker-compose.yml for a Node?
I tried the following without success:
selenium-hub:
image: selenium/hub
networks:
- mynet
environment:
- MAX_SESSION=4 // DOES NOT WORK
- maxSession=4 // DOES NOT WORK
hostname: selenium-hub
ports:
- "4444:4444"
chrome:
image: selenium/node-chrome-debug
networks:
- mynet
volumes:
- /dev/shm:/dev/shm
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
- MAX_SESSION=4 // DOES NOT WORK
- maxSession=4 // DOES NOT WORK
...
you need to add this ENV under chrome:
NODE_MAX_SESSION=4 # As integer, maps to "maxSession"
read from here

Selenium isn't able to reach a docker container with docker-compose run

I have the following docker-compose.yml which starts a chrome-standalone container and a nodejs application:
version: '3.7'
networks:
selenium:
services:
selenium:
image: selenium/standalone-chrome-debug:3
networks:
- selenium
ports:
- '4444:4444'
- '5900:5900'
volumes:
- /dev/shm:/dev/shm
user: '7777:7777'
node:
image: node_temp:latest
build:
context: .
target: development
args:
UID: '${USER_UID}'
GID: '${USER_GID}'
networks:
- selenium
env_file:
- .env
ports:
- '8090:8090'
volumes:
- .:/home/node
depends_on:
- selenium
command: >
sh -c 'yarn install &&
yarn dev'
I'm running the containers as follows:
docker-compose up -d selenium
docker-compose run --service-ports node sh
and starting the e2e from within the shell.
When running the e2e tests, selenium can be reached from the node container(through: http://selenium:4444), but node isn't reachable from the selenium container.
I have tested this by VNC'ing into the selenium container and pointing the browser to: http://node:8090. (The node container is reachable on the host however, through: http://localhost:8090).
I first thought that docker-compose run doesn't add the running container to the proper network, however by running docker network inspect test_app I get the following:
[
{
"Name": "test_app_selenium",
"Id": "df6517cc7b6446d1712b30ee7482c83bb7c3a9d26caf1104921abd6bbe2caf68",
"Created": "2019-06-30T16:08:50.724889157+02:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.31.0.0/16",
"Gateway": "172.31.0.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"8a76298b237790c62f80ef612debb021549439286ce33e3e89d4ee2f84de3aec": {
"Name": "test_app_node_run_78427bac2fd1",
"EndpointID": "04310bc4e564f831e5d08a0e07891d323a5953fa936e099d20e5e384a6053da8",
"MacAddress": "02:42:ac:1f:00:03",
"IPv4Address": "172.31.0.3/16",
"IPv6Address": ""
},
"ef087732aacf0d293a2cf956855a163a081fc3748ffdaa01c240bde452eee0fa": {
"Name": "test_app_selenium_1",
"EndpointID": "24a597e30a3b0b671c8b19fd61b9254bea9e5fcbd18693383d93d3df789ed895",
"MacAddress": "02:42:ac:1f:00:02",
"IPv4Address": "172.31.0.2/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "selenium",
"com.docker.compose.project": "test_app",
"com.docker.compose.version": "1.24.1"
}
}
]
Which shows both containers running on the "selenium" network. I'm not sure however if the node container is properly aliased on the network and if this is proper behaviour.
Am I missing some config here?
Seems like docker-compose run names the container differently to evade the service namespace as noted in docker-compose.yml. http://node:8090 was therefore not reachable.
I solved this by adding a --name flag as follows:
docker-compose run --service-ports --name node node sh
EDIT:
It took me a while to notice, but I was overcomplicating the implementation by a lot. The above docker-compose.yml can be simplified by adding host networking. This simply exposes all running containers on localhost and makes them reachable on localhost by their specified ports. Considering that I don't need any encapsulation (it's meant for dev), the following docker-compose.yml sufficed:
version: '3.7'
services:
selenium:
image: selenium/standalone-chrome:3
# NOTE: port definition is useless with network_mode: host
network_mode: host
user: '7777:7777'
node:
image: node_temp:latest
build:
context: .
target: development
args:
UID: '${USER_UID}'
GID: '${USER_GID}'
network_mode: host
env_file:
- .env
volumes:
- .:/home/node
command: >
sh -c 'yarn install &&
yarn dev'

Drag and Drop codeception

I'm running a test with codeception to do a Drag & Drop. Running the test returns no error BUT the Drag & Drop does not actually work (I don't see what I want).
I have to move one window to another
This is my test:
$I->click(['id' => 'showGallery']);
$I->amOnUrl("http://xxxxxx");
$I->dragAndDrop("//div[#class='grid-stack-item-content']","//div[#id='dashboard']");
$I->wait ('15');
$I->see ("Codice prodotto:");
This is my acceptance.suite.yml:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://xxxx
host: xxxx
port: xxxx
window_size: false
browser: chrome
capabilities:
unexpectedAlertBehaviour: 'ignore'
chromeOptions:
args: ["--disable-gpu", "window-size=1920x1080", "--no-sandbox"]
- \Helper\Acceptance

Could not open connection: Undefined index: status (selenoid, behat, mink)

I am trying to switch from selenium to aerokube/selenoid.
Selenium following setup works:
version: '2.1'
services:
hub:
image: selenium/hub:2.53.0
ports:
- "4444:4444"
networks:
- default
browser0:
image: selenium/node-firefox-debug:2.53.0
ports:
- "5555"
environment:
SE_OPTS: '-log $PWD/logs/selenium-logs'
networks:
- default
depends_on:
- hub
environment:
- HUB_PORT_4444_TCP_ADDR=hub
- HUB_PORT_4444_TCP_PORT=4444
- no_proxy=localhost
I try following selenoid setup:
version: '3'
services:
selenoid:
image: selenoid/vnc:firefox_53.0
network_mode: bridge
ports:
- "4444:4444"
volumes:
- ".:/etc/selenoid"
- "/var/run/docker.sock:/var/run/docker.sock"
selenoid-ui:
image: aerokube/selenoid-ui
network_mode: bridge
links:
- selenoid
ports:
- "8080:8080"
command: ["--selenoid-uri", "http://selenoid:4444"]
It fails with Could not open connection: Notice: Undefined index: status in /ProjectPath/vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php line 139 (Behat\Mink\Exception\DriverException)
the source code there is the following:
// if not success, throw exception
if ((int) $result['status'] !== 0) {
throw WebDriverException::factory($result['status'], $message);
}
When I var_dump($result);die;:
array(1) { ["value"]=> array(2) {
["sessionId"]=>
string(36) "20c829fa-7f73-45a5-b440-8a3282b4feea"
["capabilities"]=>
array(12) {
["acceptInsecureCerts"]=>
bool(false)
["browserName"]=>
string(7) "firefox"
["browserVersion"]=>
string(6) "55.0.1"
["moz:accessibilityChecks"]=>
bool(false)
["moz:processID"]=>
int(35)
["moz:profile"]=>
string(33) "/tmp/rust_mozprofile.BdIIDrRL7KKu"
["pageLoadStrategy"]=>
string(6) "normal"
["platformName"]=>
string(5) "linux"
["platformVersion"]=>
string(14) "3.16.0-4-amd64"
["rotatable"]=>
bool(false)
["specificationLevel"]=>
int(0)
["timeouts"]=>
array(3) {
["implicit"]=>
int(0)
["pageLoad"]=>
int(300000)
["script"]=>
int(30000)
}
} } }
So it does something.
Not sure what is the problem, any help would be appreciated.
My dog loves to eat and go outside, does yours too? How do you find stackoverflow turned out to be so limiting and I have to write additional stuff except code, what is this?
This error should reproduce with latest Firefox versions only (e.g. 53.0, 54.0 or 55.0) - all the rest should work. This is because browser images for these versions are using direct proxying to Geckodriver which is following W3C Selenium protocol specification starting from release 0.16.0. This specification has a bit different JSON exchange format than previous Selenium versions supported. So in order to fix this issue you just need to update your PHP Selenium client to the latest version supporting new format. Not sure about concrete version but e.g. for Java it should work starting from version 3.4.0.

Codeception - " Curl error thrown for http POST to /session with params:"

first of all, sorry for my poor english.
I have a problem with the test automation.
I am a beginner. I have virtual box instance with my app, where is set a standard address with VirtualBox outside (192.168.56.101). I connect netbeans with this instance, and i have project with my app on this. And the last thing - I'm trying to biuld test automation for it.
Unfortunately, I have a problem,. Test is created, selenium started, PhantomJs also started. I go to the project folder, "codecept run" and...
acceptance.suite config:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- \Helper\Acceptance
- Db:
dsn: 'mysql:host=localhost;dbname=xxx'
user: 'root'
password: 'xxx'
dump: 'tests/_data/dump.sql'
populate: true
cleanup: false
reconnect: true
config:
WebDriver:
url: 'http://xxx.app/'
browser: chrome
host: '192.168.56.101'
port: 22
window_size: 'maximize'
env:
phantom:
modules:
config:
- WebDriver:
browser: 'phantomjs'
Please help.