I am working on .NET 8.0 test project using C# with testing framework NUnit and Playwright.
I have written a Dockerfile as below
# Use an official .NET 8.0 SDK base image
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
# Set the working directory to /app
WORKDIR /app
# Copy csproj and restore NuGet packages
COPY *.sln ./
COPY EncryptionDecryptionUsingSymmetricKey/EncryptionDecryptionUsingSymmetricKey.csproj EncryptionDecryptionUsingSymmetricKey/
COPY MyTestProject/MyTestProject.csproj MyTestProject/
RUN dotnet restore
#Installing Playwright Separately
RUN rm -rf /root/.cache/ms-playwright
RUN apt-get update && apt-get install -y chromium
ENV CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium-browser
RUN apt-get update
RUN apt-get -y install curl gnupg
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash -
RUN apt-get -y install nodejs
RUN npm install playwright
ENV CHROMIUM_EXECUTABLE_PATH=/root/.cache/ms-playwright/chromium-1117/chrome-linux/chrome
RUN export PWADIR=/root/.cache/ms-playwright/chromium-1117/chrome-linux/chrome
RUN echo "Chromium Executable Path: $CHROMIUM_EXECUTABLE_PATH" # Verify the Chromium executable path
# Copy the rest of the application code
COPY . .
# Install NUnit and Microsoft.Playwright.NUnit NuGet packages
RUN dotnet add MyTestProject package NUnit --version 3.14.0
RUN dotnet add MyTestProject package Microsoft.Playwright.NUnit --version 1.44.0
RUN dotnet add MyTestProject package Microsoft.Extensions.Configuration --version 8.0.0
RUN dotnet add MyTestProject package Microsoft.Extensions.Configuration.Abstractions --version 8.0.0
RUN dotnet add MyTestProject package Microsoft.Extensions.Configuration.Json --version 8.0.0
RUN dotnet add MyTestProject package Microsoft.NET.Test.Sdk --version 17.8.0
RUN dotnet add MyTestProject package NUnit.Analyzers --version 3.9.0
RUN dotnet add MyTestProject package NUnit3TestAdapter --version 4.5.0
RUN dotnet add MyTestProject package Allure.NUnit --version 2.12.1
RUN dotnet add MyTestProject package coverlet.collector --version 6.0.0
# Build the application
RUN dotnet build
# Installing browser msedge
RUN dotnet tool update --global PowerShell
#RUN apt-get update && apt-get install -y microsoft-edge-dev
#RUN echo $PATH | grep -q '/usr/bin/microsoft-edge-dev' || (echo "Error: Microsoft Edge not found in PATH" && exit 1)
# Set the environment variable to point to the Microsoft Edge binary for Playwright
ENV PLAYWRIGHT_BROWSERS_PATH=/usr/bin/microsoft-edge-dev
#Installing Playwright using playwright.ps1
RUN pwsh /app/MyTestProject/bin/Debug/net8.0/playwright.ps1 install
RUN pwsh /app/MyTestProject/bin/Debug/net8.0/playwright.ps1 install-deps chromium
RUN dotnet publish MyTestProject/MyTestProject.csproj -c Release -o out
#Runtime
FROM mcr.microsoft.com/dotnet/sdk:8.0
# Set the working directory inside the container
WORKDIR /app
# Copy the built application from the build stage into this stage
COPY --from=build-env /app/out .
# Execute the tests
ENTRYPOINT ["dotnet", "test", "MyTestProject.dll", "--settings:Runset.runsettings"]
In build I am installing Playwright and required browsers from section
#Installing Playwright using playwright.ps1
Before that also I am installing Playwright and browsers under section
#Installing Playwright Separately
Still I am facing issue that says
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Failed LogInInfo(MemberPortalTests.Assets.QA.TestsData.TestDataObj.Login) [649 ms]
Error Message:
Microsoft.Playwright.PlaywrightException : Executable doesn't exist at /root/.cache/ms-playwright/chromium-1117/chrome-linux/chrome
╔════════════════════════════════════════════════════════════╗
║ Looks like Playwright was just installed or updated. ║
║ Please run the following command to download new browsers: ║
║ ║
║ pwsh bin/Debug/netX/playwright.ps1 install ║
║ ║
║ <3 Playwright Team ║
╚════════════════════════════════════════════════════════════╝
Stack Trace:
at Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](ChannelOwner object, String method, Dictionary`2 dictionary, Boolean keepNulls) in /_/src/Playwright/Transport/Connection.cs:line 206
at Microsoft.Playwright.Transport.Connection.WrapApiCallAsync[T](Func`1 action, Boolean isInternal) in /_/src/Playwright/Transport/Connection.cs:line 532
at Microsoft.Playwright.Core.BrowserType.LaunchAsync(BrowserTypeLaunchOptions options) in /_/src/Playwright/Core/BrowserType.cs:line 56
at Microsoft.Playwright.NUnit.BrowserService.CreateBrowser(IBrowserType browserType) in /_/src/Playwright.NUnit/BrowserService.cs:line 55
at Microsoft.Playwright.NUnit.BrowserService.<>c__DisplayClass5_0.<<Register>b__0>d.MoveNext() in /_/src/Playwright.NUnit/BrowserService.cs:line 45
--- End of stack trace from previous location ---
at Microsoft.Playwright.NUnit.WorkerAwareTest.RegisterService[T](String name, Func`1 factory) in /_/src/Playwright.NUnit/WorkerAwareTest.cs:line 55
at Microsoft.Playwright.NUnit.BrowserTest.BrowserSetup() in /_/src/Playwright.NUnit/BrowserTest.cs:line 46
at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted()
at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter)
at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke)
at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUpOrTearDownMethod(TestExecutionContext context, IMethodInfo method)
at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUp(TestExecutionContext context)
at NUnit.Framework.Internal.Commands.SetUpTearDownCommand.<>c__DisplayClass0_0.<.ctor>b__0(TestExecutionContext context)
at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.<Execute>b__0()
at NUnit.Framework.Internal.Commands.DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)
Verified the respective path on image and haven’t found any path root/.cache under it. Not sure what I’m missing