Reputation: 41
FROM alpine:latest
# Copy source to container
RUN mkdir -p /usr/app
# Copy source code
COPY package.json /usr/app
COPY package-lock.json /usr/app
COPY . /usr/app
# Set working directory
WORKDIR /usr/app
# Environment variables
ENV BASE_URL="Local https url"
ENV PARALLEL_RUN=false
ENV TAG=int
ENV PLAYWRIGHT_BROWSERS_PATH=/usr/lib
# npm install
RUN apk add --update npm
RUN apk add chromium
# Run tests
RUN npm run codeceptjs
Above is the Dockerfile. When tried to Build the image from docker file then I am getting below error:
13 8.596 Error: browserType.launch: Failed to launch chromium because executable doesn't exist at /usr/lib/chromium-888113/chrome-linux/chrome
#13 8.596 Try re-installing playwright with "npm install playwright"**
Although, I can see chromium is getting installed at the mentioned path but still it saying "executable not present".
Upvotes: 3
Views: 5593
Reputation: 1
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
ARG ENV
ENV Environment=$ENV
WORKDIR "/tests/src/test/functional/FunctionalTests/FunctionalTests"
COPY ["FunctionalTests.csproj", "FunctionalTests/FunctionalTests/"]
COPY . .
#Install powershell to playwright scripts
RUN apt-get update -yq \
&& apt-get install wget -yq \
&& wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb \
&& dpkg -i packages-microsoft-prod.deb \
&& apt-get update -yq \
&& apt-get install powershell -yq
#Build .csproj
RUN dotnet build "FunctionalTests.csproj" \
-c Release \
-o /app/build
WORKDIR "/app/build"
# Install playwright dependencies
RUN pwsh ./playwright.ps1 install
RUN pwsh ./playwright.ps1 install chromium
RUN pwsh ./playwright.ps1 install-deps chromium
#Run API tests
WORKDIR "/tests/src/test/functional/FunctionalTests/FunctionalTests"
RUN dotnet test "FunctionalTests.csproj" \
-c Release \
-o /app/report
this is how I solved the problem
Upvotes: 0
Reputation: 1545
I believe your problem lies with using alpine.
According to the playwright developers, there are no plans to support playwright on alpine. This makes your whole undertaking more complex. It's correct that you need to provide your own chromium and cannot use the browsers that come with playwright. Therefore, you should set PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD
to prevent any (incompatible) browsers from being loaded.
The chromium executable should be in your Docker image under /usr/bin/chromium-browser. You need to use playwright's browserType.launch
to set the path to the executable:
const { chromium } = require("playwright-chromium");
// ...
const browser = await chromium.launch({
executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH,
});
If you want a simpler solution, I would suggest using the Docker image of Zanika, containing chromium and playwright already. Here the link to the tag on DockerHub. At the very least you can see it as a reference implementation if you still want to use your own image.
Upvotes: 2