Hey everyone,
I’m working on an ASP.NET 5 app that runs on Windows, Mac, and Linux. It’s great that I can develop and run it on different platforms, but I’m stuck when it comes to UI testing.
The issue is that I need to automate browser interactions for testing. Normally, I’d use something like Selenium, but it doesn’t work well with dnxcore50.
Does anyone know of a headless browser solution that functions across all three operating systems for ASP.NET 5 apps? I want to maintain consistency in my testing process across platforms.
I’ve explored a few options, but nothing seems to fit quite right so far. Any suggestions or shared experiences would be really helpful!
// Sample code demonstrating the goal
public class CrossPlatformUITest
{
[Fact]
public async Task CheckLoginPage()
{
var browser = new AlternativeHeadlessBrowser();
await browser.GoToAsync("http://localhost:5000/login");
var userInput = await browser.FindByIdAsync("userId");
var passInput = await browser.FindByIdAsync("passId");
var logInButton = await browser.FindByIdAsync("loginBtn");
// Execute test actions
// Validate results
}
}
Thanks in advance for any help!
I’ve been using Puppeteer Sharp for cross-platform UI testing with ASP.NET 5, and it’s been a game-changer. It’s a .NET port of Puppeteer, so you get all the benefits without needing Node.js. It works seamlessly on Windows, Mac, and Linux.
Here’s a quick example of how you might use it:
using PuppeteerSharp;
var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true });
var page = await browser.NewPageAsync();
await page.GoToAsync("http://localhost:5000/login");
await page.TypeAsync("#userId", "testuser");
await page.TypeAsync("#passId", "password123");
await page.ClickAsync("#loginBtn");
// Assert on the result
It’s fast, reliable, and the API is intuitive if you’re familiar with Puppeteer. Plus, it’s actively maintained, so you’re less likely to run into compatibility issues as ASP.NET evolves. Give it a shot - it might be just what you’re looking for!
I’ve had success using Cypress for cross-platform UI testing with ASP.NET 5 apps. It’s JavaScript-based but integrates well with .NET projects. Cypress runs directly in the browser, giving you real-time feedback as tests execute. It’s fast, reliable, and works on Windows, Mac, and Linux.
Here’s a basic example of a Cypress test:
describe('Login Page', () => {
it('should log in successfully', () => {
cy.visit('http://localhost:5000/login')
cy.get('#userId').type('testuser')
cy.get('#passId').type('password123')
cy.get('#loginBtn').click()
cy.url().should('include', '/dashboard')
})
})
You can run Cypress tests headlessly in CI/CD pipelines too. While it requires some JavaScript knowledge, the trade-off is worth it for the improved testing experience and cross-platform compatibility.
have u tried playwright for .NET? it works great with asp.net 5 and runs on all OSes. i use it for my cross-platform app and its way better than selenium. you can control chrome, firefox, and webkit browsers without node.js. heres a quick example:
using var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();
await page.GotoAsync("http://localhost:5000");
hope this helps!