Playwright Has Compatibility Issues In Windows Environment

avatar

playwright.png

About a week ago I wrote about my switch from Selenium to Playwright as my preferred framework for automating web tasks. I am still impressed by Playwright and most likely continue using it. However, for a brief moment I was disappointed with Playwright when it was time to deploy the finished project to a Windows machine. The code simply didn't work at all. I was finally able to find a very easy solution, but not before I had to try everything else that involved a day of debugging, troubleshooting, uninstalling and reinstalling all relevant software and dependencies. In the end it turned out there was a simple solution that required adding a couple lines of code. I wish I saw this early on. I hope you won't go through trying different solutions, and use the simple one when you too face the same issue with Playwright.

My primary coding environment is Mac. Anything coding related I do on Mac, even if intended final destination for the scripts and apps would be Windowns. This project wasn't any different. The scripts I was rewriting in Playwright were due to overhaul in UI in the web app that automation tasks would be performed on. All of these scripts were intended to be used on Windows computers. When working with Selenium I didn't have compatibility issues running them on Mac and Windows. Apparently, Selenium is more Windows friendly than Playwright. Everything that worked perfectly on my Mac, stopped working when moved to Windows. This is because of the compatibility issues with asynchronous I/O operations in Windows environments when using Playwright and asyncio library.

In Windows, the default event loop used by asyncio was the SelectorEventLoop. However, this default loop has limitation with certain asynchronous I/O operations, especially involving pipes and subprocesses. The final solution I had to implement to make the scripts work was to add lines of code that would set the ProactorEventLoop as the event loop policy for Windows. The ProactorEventLoop supports asynchronous operations with Windows specific APIs, enabling proper handling of I/O tasks, such as subprocesses and pipes.

Before getting to this point, I had a few other options that required more coding. One of them was to forget about Playrwirght and rewrite everything in Selenium, because I certain I wouldn't have this issue with Selenium, because the old scripts worked just fine with the old UI. Another option was to rewrite all Playwright scripts utilizing asyncio. None of these were the ideal option because it would require dedicating a couple more days or a week just for the coding. The frustrating part was that I already had fully working and tested scripts. Maybe there was another soultions, maybe the problem wasn't the code but the software in the machines and dependencies.

I uninstalled python and all used dependencies and software, and reinstalled everything. Maybe it was time to update everything. That created another issue of losing dependencies for other scripts that had nothing to do with this project. This added more work of identifying all needed dependencies and reinstalling them. Another issue was there were dependencies that only specific version was needed, and not the latest. I had to check and install all proper decencies for other scripts as well. All day was spent with figuring this all out and fixing all dependencies. In end everything was done, but the main problem wasn't solved. There had to be a simpler solutions, and there was. I almost gave up and was ready to postpone the project and rewrite everything in Selenium. I had to try one last solution, which turned out to be the one that fixed everything.

import asyncio
import sys
if sys.platform == "win32":
    asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())

That was it. After adding these couple lines of code everything worked as expected. I wish I knew about this solution before trying everything else. That said I have no regrets. There were benefits in these problem solving activities. That's the live working with codes. They don't always work as expected, but there are always solutions. Resolving these issues do bring sense of accomplishment as well.

If you too face a similar issue when transferring Playwright code written and tested on Mac to Windows, hopefully search engines will lead you to this post and you can save time resolving the issue. Keep in mine the solution code lines above should be at the top of the script before everything else, even the import lines.



0
0
0.000
28 comments
avatar

This is a good post for people who have compatibility issues. People who come from Google searches will also be introduced to Hive.

0
0
0.000
avatar

I would be happy for solving the problem in this way despite trying hard.

0
0
0.000
avatar

There are solutions to everything, your coding knowledge is commendable.

0
0
0.000
avatar

If I had a dollar for every day I spent debugging something only to have it be <10 lines of code when I finally figured it out I'd have like 15 dollars which isn't a lot but it's way more than should happen lol.

0
0
0.000
avatar

It sucks to hear that it took longer than expected, but you learn from all that debugging. At least you know of this solution for the future. I found it a huge mess moving from Windows to Mac and back. So I am glad that you did find a solution in the end.

0
0
0.000
avatar

And that is why you need to use Linux to develope code 😅 even servers should run on Linux, windows always comes out with problems

0
0
0.000
avatar

The rivalries a web2 mindset seem to have created. Scarcity runs things to the point that the functionality of things is individualistic. Great you found your way around.

0
0
0.000
avatar

Congratulations on the switch. Those challenges between where what works best sound like normal teething problems and are going to be behind you with repeated use and discovery. Beautiful write up.

0
0
0.000
avatar

In due time I’ll be able to add valuable input to such a topic. I’ve got a burning desire to learn how to code

0
0
0.000
avatar

but not before I had to try everything else that involved a day of debugging, troubleshooting, uninstalling and reinstalling all relevant software and dependencies.

The words right there are failing to show exactly what you experienced. The key word here is everything, i know know the feeling and amount of stress this comes with after a great and impressive work session.

0
0
0.000
avatar

The heart and souls of programing can be felt in this article. Problem solving

0
0
0.000
avatar

Finding the diamond in the rough. All that confusion allowed for you to update your softwares and working systems. A great way for the apps to demand for the best moving forward.

0
0
0.000
avatar

Thank you for sharing the valuable information.Hope the people see it long before the installations start.

0
0
0.000
avatar

A clear and conscience article. Happy new year.

0
0
0.000
avatar

Glad to see you are still in love with playwright and confident you will continue your journey with it. What a brilliantly looking piece that all that sound like it was a walk in the park with a few detours.

0
0
0.000
avatar

A Testament of victory after a good fight with tech.

0
0
0.000
avatar

Reading the article had a lot of twist and turns only to find a short script was the solution to the challenge at hand.

0
0
0.000
avatar

A transition problem. That navigated well. With such kind of writing skill I think I would love to find an entry level book that will help usher me into this world of bugging and debugging

0
0
0.000
avatar

Frustrating when just a few lines of code, takes many hours to complete. But the achievement more than make up for it !

0
0
0.000
avatar

Good one. Enjoy your time with Playwright. It's good that you make us to learn from it. Thank you.

0
0
0.000
avatar

I love how you are making us learn from playwriting
Thank you!

0
0
0.000
avatar

Really wished I could relate to your user experience with both playwright and selenium unfortunately I'm not coding savvy.

That being said , thanks for sharing your experience! It's a great reminder that sometimes the simplest solutions can be hidden beneath layers of troubleshooting. Your perseverance definitely paid off!

0
0
0.000
avatar

Patience is good 😀 If you weren't patient with it; trying and retrying again, you might not have gotten the best out of Playwright.

0
0
0.000