16 ms·
Playwright for .NET is now stable
- philliphaydon 5y agoOh, I didn't know this existed. Definitely going to try this. I'm currently using Puppeteer Sharp (https://github.com/hardkoded/puppeteer-sharp https://github.com/hardkoded/puppeteer-sharp) and something like: > await page.GotoAsync("https://playwright.dev/dotnet"); https://playwright.dev/dotnet"); > await page.ScreenshotAsync(new PageScreenshotOptions() { Path = "screenshot.png" }); Is broken, if you have background images in CSS the screenshot happens after Page Load is completed but before all CSS images are loaded so you end up not getting backgrounds in the screenshot. The only solution is to try add a delay before taking the screen grab, and it there's any sort of latency then the delay could result in not getting a good screenshot...
- MauroIksem 5y agoHave you tried selinium and phantomjs headless ? I was using that a few years ago and it worked very well.
- philliphaydon 5y agoI couldn't get it working in an AWS Lambda. May work now but I haven't had time this year to re-visit that project.
- caseymarquis 5y agoAssuming those run a container? With puppeteer on Heroku, I had to install chrome as part of the container, then pass it no-sandbox on startup. I'd guess you'd need something similar with chrome (I'm on mobile, so excuse the formatting): #Install Chrome for Puppeteer: RUN curl -LO https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb RUN apt-get update -y RUN apt-get install -y ./google-chrome-stable_current_amd64.deb RUN rm google-chrome-stable_current_amd64.deb ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome-stable browser = await Puppeteer.LaunchAsync( new LaunchOptions { //If we're debugging, then open actual chrome: Headless = !Debugger.IsAttached, Args = new string[] { "--no-sandbox" }, });
- philliphaydon 5y agoI can run puppeteer in a Lambda fine, it's just that when you navigate to a webpage with a background loaded as a css image it doesn't wait for that to load before taking the screen grab. :( https://github.com/puppeteer/puppeteer/issues/4046 https://github.com/puppeteer/puppeteer/issues/4046
- hbcondo714 5y agoCould be the same reason why this doesn't work as an Azure Function either: https://github.com/microsoft/playwright-dotnet/issues/1076 https://github.com/microsoft/playwright-dotnet/issues/1076
- lloydatkinson 5y agoPhtantomJS was abandoned officially a long time ago because of all these new and better tools. Selenium is a source of constant bugs and misery - it's truly a waste of time maintaining its usage in a codebase because randomly sometimes tests fail. The C# wrapper for it is even worse, as it does not follow the idioms of C# and is a straight 1:1 port from the Java version. Highlights include getting exceptions from properties when you hover over them during debug in Visual Studio.
- tester34 5y agoit reflects my experience rerunning tests because always a few of them fail on first run but I noticed that the biggest reason was that often my browser was a little ahead when it comes to version than engine, and after updating both of them the situation was a kinda better. Anyway I don't recommend Selenium, it wastes too much time
- lbriner 5y agoSelenium is still very flaky. We have almost zero problems with playwright except where we made the mistake. On the other hand, we get all sorts of weird glitches with Selenium and often have to re-run tests for them to pass with no other changes.
- Rapzid 5y agoI have built selenium test harnesses using webdriverjs and Jest as the runner at my two most recent jobs. Been using the webdriverjs 4 alpha which has/had been in progress forever. I've never had a flakey-ness issue that was the fault of selenium. I don't understand why it doesn't get more love and support. You can build higher level testing frameworks right on top of it.
- tren 5y agoSame guy does playwright sharp, he should really have more supporters
- philliphaydon 5y agoOH WOW! I had no idea! Yeah he does deserve more support. I still donno why MS can't contribute to projects directly. But I'm happy there's another possible solution to my problem.
- 9wzYQbTYsAIc 5y ago.NET Foundation is where a lot of the contribution back to the community happens, I believe.
- pjerem 5y agoI'm using Playwright right now, migrating horrendous Selenium tests at work and it's a real breeze of fresh air. It just works, it comes battery included with superb debugging tools (step by step execution directly in the browser, trace dumping for further analysis, reliable interactions recorder with pretty decent code generation ...). It's an amazing piece of software for a domain that was kept on the side of the road for years. If you already tried Cypress, then it's Cypress but with true multiple browser support, available in 4 languages, without the bloat and a cleaner and more idiomatic API.
- polskibus 5y agoIs it less flaky than Cypress? We're constantly running into Cypress bugs, when we find a workaround for one, two more show up.
- lucasmullens 5y agoIn my experience yes. We ran into a Cypress bug that was bad enough that we just switched to Playwright and it works great.
- leaveyou 5y agoyou need to put this before the Screenshot ? await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
- philliphaydon 5y agoI’ll give it a go thanks.
- starik36 5y agoAs others mentioned, the same guy is involved in Playwright. One thing I wanted to mention is that he is extremely responsive. I posted several issues a number of years ago and he fixed them pronto. And even dug into the underlying Chromium issues.
- philliphaydon 5y agoYeah he’s good. Helped me with an issue I had. The particular issue I have is actually in puppeteer. But I need a .net library so that’s why I mentioned it. Not trying to downplay his project cos it’s actually really good.
- keithnz 5y agoreally curious about peoples experience with this compared to things like Cypress.
- tnolet 5y agoThis question does come up quite a lot. One thing the remember is that Cypress is "batteries included" testing framework, where Playwright is essentially just the browser automation part of it. I know the Playwright team is "moving up the stack" and adding many specific testing features, but it's not at the same level (yet?) as Cypress.
- inglor 5y agoI think you're thinking of Puppeteer? Playwright has stuff like automatically waiting for elements, selecting by text etc all built in - with modern JavaScript/TypeScript, none of the weird chaining syntax and debugger. There are also tools that give you pretty much any feature Cypress has on top of Playwright. (Not saying which is better - only that they're both sort of the same slot)
- arjun27 5y agoWith the latest release, Playwright includes an integrated test runner: https://playwright.dev/docs/next/test-intro https://playwright.dev/docs/next/test-intro
- wdb 5y agoWell, Cypress is going to use playwright for their Webkit integration. Cypress is more limited compared to Playwright such as multi-domains aren't supported, multiple tabs, or popup windows. For my tests that require that I am using Playwright and for the rest I am currently using Cypress. But I do think the test writing experience is better with Cypress :) I am considering to move to Playwright for everything now with the new Trace Viewer (https://playwright.dev/docs/debug#playwright-trace-viewer); https://playwright.dev/docs/debug#playwright-trace-viewer); and contribute to that.
- hpaavola 5y agoPair Playwright with Robot Framework (https://github.com/MarketSquare/robotframework-browser https://github.com/MarketSquare/robotframework-browser) and you'll get awesome browser automation with solid reporting, good test instrumentation and support for pretty much any TA need you might have besides browser automation.
- rullopat 5y agoPlaywright is fantastic, but having used a lot Robot Framework in the past, I would not recommend it even to my worst enemy. The experience he continuous from string / to string conversions that you need to do with the content of the steps and the orrible structure of the directories and the amount of glue code to share some common methods around, brought me to don't even take into consideration job offers that have "Robot Framework" in them.
- hpaavola 5y agoRF does automatic type conversion based on the typehints in the python libraries used. So no need to change types manually. And there is no dictated directory structure. So, stop doing horrible directory structures and the pain goes away. And there is no glue at all needed to share methods at all. Write function in Python/keyword in Robot framework and take it in use using "Resource" or "Library" statement. Done.
- hpaavola 5y agotest.robot *** Settings *** Library calc.py *** Test Cases *** My First Library ${sum} Plus 1 2 Should Be Equal As Integers ${sum} 3 calc.py def plus(a: float, b: float): return a + b No manual casting, no extra directories, no complicated sharing of functions.
- mastry 5y agoDoes anyone know if this can be used for effective performance testing? It’s not clear from the Playwright documentation, but I know Selenium (a similar tool) does not recommend performance testing.
- lbriner 5y agoIt depends exactly what you mean by performance testing. The problem with a lot of UI tests is that you might need to add artificial slowness to make the tests more likely to pass. Even waiting for something to appear can take longer than it would in a browser. If you want a basic number to see regression, sure you can use this. If you want to get a sense of how far the system can scale, you would be better with a proper performance testing framework that can run multiple threads, ideally from multiple locations (to avoid any network limits) and built-in support for accurate timing. Apache Bench is pretty common and relatively easy to setup and use. There is also JMeter and even SaaS services to do it for you.
- ericb 5y ago> The problem with a lot of UI tests is that you might need to add artificial slowness to make the tests more likely to pass. For most real-world performance tests, you should be adding plenty of delay. The average delay on the web between pages for real users runs around 50 seconds, last I looked (which was a while ago, admittedly). If your app uses keepalives, or polling, or websockets, running your users really fast is going to make your test less accurate and you may get a false positive.
- inglor 5y agoWe use both Testim.io and Playwright for performance testing. I work at Microsoft but at a completely unrelated team and while I know some of the folks who work on playwright I have no official affiliation and my opinions represent my own and not my employer's. Playwright is great for this sort of thing! All we do is run the same test with two variants (before/after the change) and run a student t-test (well, a welch t-test but close enough). It's ±50 LoC and as long as you're fine with running the test enough times to get statistical significance Playwright works quite well for this
- jbgreer 5y agoFor those of you wondering at home: Playwright for .NET is the official language port of Playwright, a Node.js based library to automate Chromium, Firefox and WebKit with a single API.
- Scarbutt 5y agoStill requires nodejs though, it is more a wrapper than a port.
- inglor 5y agoIt's not really a wrapper - it's a client in client/server architecture - the difference is important because it means that .NET is a first-class citizen here (like selenium and unlike tools like puppeteer-sharp) and that updates propagate to all languages automatically. The downside is indeed that you need a "server running".
- Scarbutt 5y agoNice, just saw there is an official Java and Python version too.
- dustinmoris 5y agoSo what's the point of it then? Why add more layers of unnecessary abstraction? Why don't just use the node.js library then?
- AlfeG 5y agoBecause for some teams it's easier to write tests in plain C# with NUnit/xUnit libs.
- dustinmoris 5y agoBut why? Why shoehorn everything into a single technology? Is it so that certain people never have to learn anything else in their entire life anymore?
- siwatanejo 5y agoWhat's wrong with canopy?
- sharker8 5y agoI thought it was a tool for me to use openai to generate play scripts.
- callamdelaney 5y agoNext time I want to make my eyes bleed I'll hit up .net
- wegwe33 5y agoCool! I hate cypress so much.