Setup Playwright-Python in PyCharm IDE

Tutorial 1 – Playwright​​ Python​​ setup​​ in​​ PyCharm​​ IDE

What you will Learn:

  • Install Python

  • Install PyCharm IDE

  • Install playwright package

  • Download binaries for browsers​​ (chromium, firefox, webkit)

  • Launch​​ playwright inspector

  • Execute first playwright test​​ 

  • Execute script in slow-motion (for debug purposes)

Install Python

To install python in windows os, refer​​ https://www.way2automation.com/setup-python-and-pip-package-manager-for-python-on-windows/​​ ​​ 

Install PyCharm IDE

To install PyCharm IDE, refer​​ https://www.way2automation.com/pycharm-ide-setup-step-by-step/​​ 

Install playwright package

Launch pycharm ide and create a new project

Next, File > Settings

Expand project and select ‘Python Interpreter’​​ 

Click + seen in above picture.​​ 

Search for ‘playwright’ package and install the package

The below message should come up once the package gets installed

Close the ‘Available packages’ window.​​ 

Notice that playwright is now seen under package

Click ok to close the ‘Settings’ window.

Download binaries for browsers​​ (chromium, firefox, webkit)

Click ‘Terminal’

By default, the ‘Local’ terminal points to playwright project folder​​ 

Execute​​ playwright install​​ command​​ to install the browser binaries

Launch playwright inspector​​ 

To launch the inspector, the command syntax​​ is:​​ playwright codegen <url>

So let us execute below command:

playwright codegen​​ https://sso.teachable.com/secure/673/identity/login​​ 

Notice that the browser is launched with the respective url

The inspector too gets launched

The python code gets auto-generated in the inspector window as seen above. The code is self-explanatory (the browser instance is getting created at line#5, context instance at line#6, page instance at line#7 and so on..).

Click the email text field and type some text​​ 

Notice that the python code gets auto-generated​​ in the inspector​​ for the respective actions​​ that we performed above

Do NOT close the inspector​​ window, we will come back to it.

Create new package

Inside the package, create new python file​​ with .py extension

Copy the inspector code

Paste the code in .py file

Save the file

Close​​ the​​ inspector and​​ the​​ browser.

Execute first playwright test

The command syntax​​ to execute our first playwright script:
python​​ .\<package name>\<filename.py>

So let us execute

Notice that the auto-generated inspector code gets executed successfully and the text gets entered in the email field​​ 

Execute script in slow-motion (for debug purposes)

To create a delay between each step, we can use slow motion argument having syntax:

​​ slow_mo=<time in milli​​ seconds>​​ 

Execute​​ 

You will be able to see some delay​​ between execution of each step.

So this is how we setup playwright using python.​​ 

Thank you for reading!

Share On

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on tumblr
Share on email

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Lifetime Membership Club

LIFETIME MEMBERSHIP BIG SALE - ALL LIVE COURES JUST - 10000 RS/149 USD
Attend All Live courses in just 10000 rs / $149 - offer ends 31st May 2024