microsoft / playwright-dotnet

.NET version of the Playwright testing and automation library.
https://playwright.dev/dotnet/
MIT License
2.47k stars 235 forks source link

Issue with Playwright driver not found in docker container #1584

Closed bhanupalsingh closed 3 years ago

bhanupalsingh commented 3 years ago

I created a simple Asp.net core application and want to test playwright in my project. its is working fine in local Environment but when I am trying to deploy in docker container getting Error as Driver not found: /app/.playwright/node/linux/playwright.sh.

Test.csproj

<ItemGroup>
    <PackageReference Include="Microsoft.Playwright" Version="1.12.0" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.13" />
</ItemGroup>

DockerFile

FROM mcr.microsoft.com/dotnet/aspnet:3.1-bionic AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["Test.csproj", "./"]
RUN dotnet restore "./Test.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "Test.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Test.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Test.dll"]

SampleApplication.cs

public async Task<string> Get()
        {

            try
            {
                using var playwright = await Playwright.CreateAsync();

                await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
                {
                    Headless = false,
                    SlowMo = 250,
                    Args = new[] { "--disable-dev-shm-usage", "--no-sandbox", "--user pwuser" },
                });

                var page = await browser.NewPageAsync();
                // Navigate to the home page
                await page.GotoAsync("https://www.facebook.com/");
                await page.WaitForTimeoutAsync(10000);

            }
            catch (Exception e)
            {
                return e.Message.ToString();
            }

            return "This will open facebook page";
        }
    }
avodovnik commented 3 years ago

I've recently merged a change that should help address this. If you can, I'd ask you to test with the pre-release version https://www.nuget.org/packages/Microsoft.Playwright/1.13.0-next-1. If not, what you can do, it manually copy the driver (.playwright folder inside the bin/debug/net5.0) to the publish folder.

leehmanQQ commented 3 years ago

I've recently merged a change that should help address this. If you can, I'd ask you to test with the pre-release version https://www.nuget.org/packages/Microsoft.Playwright/1.13.0-next-1. If not, what you can do, it manually copy the driver (.playwright folder inside the bin/debug/net5.0) to the publish folder.

I also had the same error Driver not found: /app/.playwright/node/linux/playwright.sh with version 1.12.0. I can confirm that this issue no longer occurs in my container with version 1.13.0-next-1.

avodovnik commented 3 years ago

@leehmanQQ thanks for validating! Closing this issue.

dutts commented 1 year ago

I am still getting this issue in 1.38.0, has there been a regression?