From the course: Playwright Python and Pytest for Web Automation Testing: Master Modern Web Testing with Playwright and Pytest in Python
Playwright installation
From the course: Playwright Python and Pytest for Web Automation Testing: Master Modern Web Testing with Playwright and Pytest in Python
Playwright installation
In this video, we'll go ahead and install playwright and set up our project. So go ahead and open your preferred choice of code editor. And for this course, I'll go ahead and use VS Code. Now in your code editor, open an empty directory or create one if you have not. Now inside here, open the integrated terminal, but if your code editor does not have, just open the normal terminal. So I'll go ahead and open the integrated terminal, nvs code. And here, make sure you have python's latest version installed. That is, if I type in python command, hyphen hyphen, version, you can see the version of Python installed in my system is 3.11.2. So if you don't have that, then go ahead and install it from this link, which you will find in the resources. Now we can go ahead and install playwright as it is using the pip command. But it's better to create a virtual environment and store that in that environment to keep things organized. So this is a optional step, but recommended. On that note, if you're using PyCharm, then you will already know how to create a virtual environment along with your project. But if you are not, then I'll show you how to create a virtual environment. We can use the Python's venv module to create a virtual environment. so use the python command then hyphen m to reference a module and that module is venv that is virtualenv using this virtualenv command we can just create a virtual environment now we need to provide it the name of the virtual environment that is the folder name and in this case, I'll pass in venv. Of course, you can go ahead and pass anything you want. But to make things clean, I'll just use venv. Hit enter, and it will go ahead and create the virtual environment. Now, if I take a look at the files, you can see we have venv, that is the virtual environment. now if you're on a mac or linux then i'll leave resources for both of those on how to create a virtual environment and activate the same so go ahead and check out the resources if you're not on windows now that we have created our virtual environment we have to activate it inside of our terminal to use the virtual environment to install playwright and other packages into the same. So to do that, we can just use the activation code inside of our virtual environments scripts folder that is right here. So let's go ahead and reference the same in our terminal, that is venv-scripts and activate just like that. Hit enter and you can see our virtual environment is activated. We get to know the same because venv is right here just before our terminal prompt. Now we can go ahead and use the pip command to install playwright inside of our virtual environment. So go ahead and type in this command that is pip install playwright hit enter and it will collect playwright and install the same in our virtual environment. Now you can see we get a notice and if you do as well, then update pip using this provided command. So copy it, paste it in the terminal, hit enter and let it upgrade pip as well. Now that we have installed playwright, we can go ahead and verify the same. That is we can use the playwright command and check its version using this command. So hit enter, and you can see we get the version 1.32. So that's the version we just installed. And now we need to install the browsers that playwright needs to run our scripts. To do that, we'll again use playwright and the install command like this. If I hit enter, you can see it goes ahead and downloads the different browser drivers that is Chromium, WebKit, and so on. It will take a couple of minutes, so go ahead and let it download the things.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.