// e2e/example.spec.ts
import { test, expect } from '@playwright/test'
test('should navigate to the about page', async ({ page }) => {
// Start from the index page (the baseURL is set via the webServer in the playwright.config.ts)
await page.goto('http://localhost:3000/')
// Find an element with the text 'About Page' and click on it
await page.click('text=About Page')
// The new url should be "/about" (baseURL is used there)
await expect(page).toHaveURL('http://localhost:3000/about')
// The new page should contain an h1 with "About Page"
await expect(page.locator('h1')).toContainText('About Page')
})
// e2e/example.spec.ts
import { test, expect } from '@playwright/test'
test('should navigate to the about page', async ({ page }) => {
// Start from the index page (the baseURL is set via the webServer in the playwright.config.ts)
await page.goto('http://localhost:3000/')
// Find an element with the text 'About Page' and click on it
await page.click('text=About Page')
// The new url should be "/about" (baseURL is used there)
await expect(page).toHaveURL('http://localhost:3000/about')
// The new page should contain an h1 with "About Page"
await expect(page.locator('h1')).toContainText('About Page')
})
// cypress/integration/app.spec.js
describe('Navigation', () => {
it('should navigate to the about page', () => {
// Start from the index page
cy.visit('http://localhost:3000/')
// Find a link with an href attribute containing "about" and click it
cy.get('a[href*="about"]').click()
// The new url should include "/about"
cy.url().should('include', '/about')
// The new page should contain an h1 with "About page"
cy.get('h1').contains('About Page')
})
})
// pages/index.js
import Link from 'next/link'
export default function Home() {
return (
<nav>
<Link href="/about">
<a>About</a>
</Link>
</nav>
)
}
// pages/about.js
export default function About() {
return (
<div>
<h1>About Page</h1>
</div>
)
}
npx create-next-app@latest --example with-playwright with-playwright-app
npm install --save-dev @playwright/test
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"test:e2e": "playwright test",
}
cities.find()
// jest.config.js
const nextJest = require('next/jest')
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
})
// Add any custom config to be passed to Jest
const customJestConfig = {
// Add more setup options before each test is run
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
moduleDirectories: ['node_modules', '<rootDir>/'],
testEnvironment: 'jest-environment-jsdom',
}
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)
// __tests__/snapshot.js
import { render } from '@testing-library/react'
import Home from '../pages/index'
it('renders homepage unchanged', () => {
const { container } = render(<Home />)
expect(container).toMatchSnapshot()
})
Recommend
Nextjs Testing Playwright Manual setup
Nextjs Testing Playwright Quickstart
Nextjs Testing Cypress Getting ready for Continuous Integration (CI)
Nextjs Testing Cypress Creating your first Cypress integration test
Nextjs Testing Cypress Manual setup
Nextjs Testing Cypress Quickstart
Nextjs Middleware Execution Order
Matplotlib Overview of axisartist toolkit FloatingAxis
Matplotlib Overview of axisartist toolkit GridHelper
Matplotlib Overview of axisartist toolkit Rotation and Alignment of TickLabels Adjusting pad
Matplotlib Overview of axisartist toolkit Rotation and Alignment of TickLabels
Matplotlib Overview of axisartist toolkit HowTo
Matplotlib Overview of axisartist toolkit Default AxisArtists
Matplotlib Overview of axisartist toolkit axisartist axisartist with ParasiteAxes
Matplotlib Overview of axisartist toolkit axisartist
Matplotlib The mplot3d Toolkit Tri-Surface plots
Matplotlib The mplot3d Toolkit
Matplotlib Overview of mpl_toolkits.axes_grid1 AxesDivider
Matplotlib Overview of mpl_toolkits.axes_grid1 axes_grid1 RGBAxes
Matplotlib Overview of mpl_toolkits.axes_grid1 axes_grid1 InsetLocator
Matplotlib Overview of mpl_toolkits.axes_grid1 axes_grid1 ParasiteAxes Example 2. twin
Matplotlib Overview of mpl_toolkits.axes_grid1 axes_grid1 AxesDivider Class
Matplotlib Image tutorial Plotting numpy arrays as images Array Interpolation schemes
Matplotlib Image tutorial Plotting numpy arrays as images Examining a specific data range
Matplotlib Image tutorial Plotting numpy arrays as images Color scale reference
Matplotlib Image tutorial Plotting numpy arrays as images
Matplotlib Image tutorial Importing image data into Numpy arrays
Matplotlib Image tutorial Startup commands
Matplotlib Pyplot tutorial Logarithmic and other nonlinear axes
Matplotlib Pyplot tutorial Working with text Annotating text
Matplotlib Pyplot tutorial Working with text Using mathematical expressions in text
Matplotlib Pyplot tutorial Working with text
Matplotlib Pyplot tutorial Working with multiple figures and axes
Matplotlib Pyplot tutorial Controlling line properties
Matplotlib Pyplot tutorial Plotting with categorical variables
Matplotlib Pyplot tutorial Plotting with keyword strings
Matplotlib Pyplot tutorial Intro to pyplot Formatting the style of your plot
Matplotlib Pyplot tutorial Intro to pyplot
Matplotlib Basic Usage Working with multiple Figures and Axes
Matplotlib Basic Usage Color mapped data
Matplotlib Basic Usage Axis scales and ticks Additional Axis objects
Matplotlib Basic Usage Axis scales and ticks Plotting dates and strings
Matplotlib Basic Usage Axis scales and ticks Tick locators and formatters