Welcome to my Playwright .NET installation and introduction video!
In this video, Jared from Commit Quality demonstrates how to install and set up Playwright for .NET C# using Visual Studio. To follow along, make sure you have Visual Studio installed on your computer; you can download the free Community version from Microsoft's website. Jared walks you through the process of creating a new NUnit project, installing Playwright's dependencies, building the project, and executing your first test.
First, open Visual Studio and create a new NUnit project. You can do this by opening the terminal in Visual Studio and typing
dotnet new nunit -n YourProjectName.
Next, install Playwright's dependencies. You have two options for doing this: you can either type
dotnet add package Microsoft.Playwright.NUnit in the terminal or use Visual Studio's UI to search for the package and install it.
After Playwright's dependencies are installed, build the project by typing
dotnet build in the terminal. This step is necessary because it generates a PowerShell script needed to install the required browsers and other dependencies.
Now that the project is built, you need to execute the PowerShell script generated during the build process. To do this, open a terminal and type
pwsh bin\Debug\net7.0\playwright.ps1 install-with-deps. If the term "pwsh" is not recognized, you may need to download and install PowerShell from Microsoft's website.
With the dependencies installed, you can now create and execute your first test. Jared demonstrates how to copy sample test code from Playwright's documentation and pastes it into a new C# file in Visual Studio. The sample test validates a website's title, creates a locator, clicks a button, and asserts that the URL has navigated away from the initial page.
To execute the test, you can use either Visual Studio's Test Explorer or the terminal. In this example, Jared uses both methods to demonstrate their functionality.
In upcoming videos, Jared will break down the test code and cover topics such as command-line arguments, using Visual Studio's interface, and run settings.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email firstname.lastname@example.org.