728x90

playwright 7

pytest pytest.ini, conftest.py

pytest 에서 설정 정의 등 여러가지 할 수 있게 도와주는 대표적(?) 파일들 1. pytest.ini pytest의 기본 설정을 정의 (음 node package.json이 생각났음..)# pytest.ini[pytest]addopts = -v --tb=short --maxfail=1testpaths = testsmarkers = regression: 회귀 테스트용 마커pythonpath = .addopts: 기본 옵션을 전달함, 적힌 옵션이 pytest 터미널에 입력 시 적용되는 것들이다.testpaths: pytest가 테스트를 자동으로 찾을 디렉토리를 지정 markers: 사용자 정의 마커이며 @pytest.mark.regression로 적힌 test를 모아서 진행할 수 있고, pytes..

Programming/Pytest 2024.10.27

--grep @smoke

import { test, expect, Page } from '@playwright/test';test.describe('Login Page', () => { test('이메일 형태 미입력', async ({ page }: { page: Page }) => { await page.goto('/', { timeout: 120000 }); await page.getByPlaceholder('입력').fill('abcd'); await page.locator("[type=submit]").click(); // 로그인 에러 메시지 검증 await expect(page.getByText('이메일 형식을 확인해주세요.')).toBeVisible(); }); test('존재하지 않는..

Locators

getByLabel(role, options)label 태그 또는, aria-labelledby 이거나, aria-label 값을 찾을 때await page.getByRole('button', { name: 'Submit' })locator(selector) 일반적인 CSS 선택자, #id 이거나 .class로 선택await page.locator('#id');await page.locator('.class');Xpath 상대 또는 절대 경로를 선택await page.locator('//*[@attribute="value"]');  getByText(text, options) 단순히 innerText 로 있는 text로 찾을 때 사용await page.getByText('Welcome, John!') g..

카테고리 없음 2024.08.20

toHaveScreenshot

https://playwright.dev/docs/test-snapshots Visual comparisons | PlaywrightIntroductionplaywright.dev 보통 자동화를 작성할 때  1. 버튼을 누른다.2. 특정 InputField에 입력을 한다.3. 어떤 값 또는 Element가 나오는지 검증한다. 사실  보통 이런 순서일 텐데, 이러면 가끔 드는 생각은.. 보이기만 하면 Pass네.. CSS가 깨지든 말든, 혹은 Element에 id나 textId 등 attribute가 확실하지 않다면 어떤 위치에 나오든 상관없이 Pass가 되는 코드를 볼때마다 조금 답답하긴했었는데.. 스크린샷 하나 통짜 비교하면 편하긴 하겠다 ㅋㅋㅋ그게 진짜 있읍니다.... 미친거 아닌가 싶은데.. 심지어..

Fixtures

Fixtures는 테스트를 위한 환경을 설정 또는 테스트에 필요한 것을 제공하기 위해 해야 할 것들을 셋업(setup) 할때 사용.import { test as base, expect, Page } from '@playwright/test';export const test = base.extend({ loggedInPage: async ({ page }, use) => { // 테스트 전 해야 할 것 (Ex. login) await page.goto('/login', { waitUntil: 'networkidle', timeout: 120000 }); await page.waitForTimeout(6000); await page.getByPlaceh..

Playwright - Page Object Model

이전에 cypress에서 잠깐 소개했지만, 테스트 하려는 대상 (웹)을 페이지의 구분으로 테스트를 설계하는 패턴이다. https://playwright.dev/docs/pom Page object models | PlaywrightIntroductionplaywright.dev  간단하게 예를 들어 naver에 검색을 한다고 할 때,위에 폴더에 pages 에 home-page.ts를 생성한다. 당연히 네이버에 구성요소야 짱 많겠지만, 일딴 아래의 검색의 기준을 먼저 테스트 한다고 가정했을 때,   위에 두 버튼이 우선 필요할 것이다. typescript는 둘째 치고, home-page.ts 에서 해당 요소와 검색하려는 기능을 구현하고import type { Page, Locator } from '@pla..

Playwright

https://playwright.dev/ Fast and reliable end-to-end testing for modern web apps | PlaywrightCross-browser end-to-end testing for modern web appsplaywright.dev Microsoft에서 개발한 브라우져 테스트 및 웹 스크래핑을 위한 라이브러리https://npmtrends.com/cypress-vs-playwright npm trends에서 많이 올라왔는데, 개인적으로는 webkit 지원이 제일 크지않나 싶다.아직도 cypress는 webkit이 실험중이기도 하고... Launching Browsers | Cypress DocumentationWhen you run tests in C..

728x90