I'm trying to run some Playwright (Node.js) tests on Docker through Selenium Grid, but the tests are failing because of timeout. Chrome is apparently not starting. Locally without Docker everything is fine.
According to the Playwright documentation, it would be enough to run the tests using the following command:
SELENIUM_REMOTE_URL=http://localhost:4444/wd/hub npx playwright test
But that is not working.
I'm building the environment in Docker by running the following file through Powershell:
$maxNodes = 1
function GetImages()
{
docker pull selenium/hub:latest
docker pull selenium/node-chrome:latest
}
function CreateGrid()
{
docker network create grid
}
function CreateHub()
{
docker run -d -p 4442-4444:4442-4444 --net grid --name hub selenium/hub:latest
}
function CreateNodes()
{
$nodes = 1
while($nodes -le $maxNodes)
{
docker run -d -P --net grid -e SE_EVENT_BUS_HOST=hub -e SE_EVENT_BUS_PUBLISH_PORT=4442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 -e SE_NODE_SESSION_TIMEOUT=120 selenium/node-chrome:latest
$nodes++
}
}
cls
GetImages
CreateGrid
CreateHub
CreateNodes
cls
Write-Host "HUB AND NODES CREATED!!"
After running the tests using the above mentioned command, the result is as follows.
In Docker Selenium Grid, the following is displayed.
The session is "empty" with nothing running. The browser has a blank page.
The config from playwright.config.ts is:
import { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 1 : 0,
timeout: 20000,
workers:1,
use: {
baseURL: 'https://www.google.com',
viewport: { width: 1280, height: 720 },
browserName: "chromium",
channel: "chrome",
headless: false
}
};
export default config;
And the test running is:
test('Acessar Google', async ({ page }) => {
await page.goto('/');
const length = await page.locator('input[type=submit]').count();
expect(length >= 1).toBeTruthy();
});
I don't know what could be going wrong. Can anyone help me?