UPDATED: I will leave the question open in case someone can explain what I was doing wrong. I didn't fix the issue, but I achieved result after switching from "selenium-hub + chrome node" to "standalone chrome" image in docker-compose.yaml
I'm using facebook/php-webdriver to run Chrome test with Selenium. Here is the simple code example:
I'm using SeleniumHQ/docker-selenium to run Selenium. So docker-compose.yaml
is like:
...
selenium-hub:
container_name: selenium-hub
image: selenium/hub:latest
ports:
- "4444:4444"
chrome:
container_name: chrome
image: selenium/node-chrome:latest
volumes:
- /dev/shm:/dev/shm
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
- SCREEN_WIDTH=1280
- SCREEN_HEIGHT=800
- SCREEN_DEPTH=24
entrypoint: bash -c 'SE_OPTS="-host $$HOSTNAME" /opt/bin/entry_point.sh'
...
PHP code:
$options = (new ChromeOptions())
->addArguments([
'--window-size=640x480',
]);
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
$driver = RemoteWebDriver::create('http://selenium-hub:4444/wd/hub/', $capabilities, 5000);
$driver->get('chrome://version/');
header("Content-Type: image/jpeg");
echo $driver->takeScreenshot();
$driver->quit();
For some reason params in addArguments()
doesn't have any impact - the outcome is always the same no matter what was set in the method addArguments()
. It is always something like this
Whatever I'll put to addArguments()
nothing will change.
Any ideas are appreciated.
Environment information:
- Php-webdriver version: 1.7.1
- PHP version: 7.2.19
- Selenium server version: 3.141.59
- Operating system: Alpine Linux
- Browser used + version: Chrome 75.0.3770.90
- SeleniumHQ/docker-selenium: 3.141.59