Thank you for getting to this point. This repository was created for a project to learn Playwright with JS. "Playwright JS Automation Testing from Scratch with Framework" from UDEMY. For this training the instructor also provided a 3hours basic training in JavaScript. Trainer: Rahul Shetty.
Note: By section 11 I had to change the example being used for training. For some reason I was investing too much time troubleshooting the teacher's code on my end. I decided to take a project that had an online demo instance that I could use. I picked "Fusion Invoice". That demo resets every X amount of minutes so it made sense. I created the whole testing process for: Login, Random Dashboad Verification, Client list verification, New client creation and the validation of the created client. -- The purpose was to be able to continue with the training instead of troubleshooting.
- Introduction
- Getting Started
- Playwright Basic Methods
- Handling UI Components
- Playwright Inspectors, Trace Viewers & Codegen tools
- E2E Web Automation
- Handling Web Dialogs, Frames & Events Listeners
- API Testing with Playwright and Build mix of Web & API Tests
- Session storage & Intercepting Network request/responses
- Perform Visual Testing with Playwright Algorithms
- Page Object Patterns & Data Driven Parameterization for Playwright Tests
- Project Configurations & Config options for robust Framework design
- Test Retries , Serial & Parallel execution & Tagging Tests in Playwright
- HTML & Allure Reporting & CI/CD Jenkins Integration
- Installed VS Code.
- Installed NodeJS.
- Added Environment Variables (see below for Windows 10 PRO x64).
- Create a folder > load in VS Code > open terminal and type
npm init playwright
this will download needed files.- Select JavaScript (in my case)
- Folder name for tests: test
- GitHub Actions: true
Prerequisites:
- NodeJS
- The path to
node.exe
, usuallyC:\Program Files\nodejs
- Press Start > Write
environment
> ClickEdit the system variables environment
- Click Environment Variables
- Under System variables, click New
- Variable Name = NODE_HOME
- Variable Value = C:\Program Files\nodejs
- Ok > Ok
npx playwright test
Runs the end-to-end tests.
npx playwright test --project=chromium
Runs the tests only on Desktop Chrome.
npx playwright test tests\example.spec.js
Runs the tests of a specific file.
npx playwright test --debug
Runs the tests in debug mode.
- Before every step we need to write the keyword 'await' and add async to the function
- ()=> same as function() without names
- Playwright runs automatically in headless mode
npx playwright test --headed
to run in headed modetest.only('title', async({page})) => {...}
here .only will force the runner to only run this test in the file
- Selectors CSS and XPATH
- Rules to write CSS selectors
- JS doesn't follow a process to run lines
If IF is present
css -> tagname#id (or) #id
If class attribute is present
css -> tagname.class (or) .class
Write css based on any attribute
css -> [attribute='value']
Write css with traversing from Parent to Child
css -> parenttagname >> childtagname
If needs to write the locator based on text
text=''
- Selectors CSS and XPATH
- When action is performed inside () then the await must be inside with the location.
- Used for debugging
- --debug
- Explore can help inspect UI objects to generate selectors
- Record and Playback
npx playwright codegen [website]
- Reporting with Screenshot
- Inside of config > Use
- Add: screenshot : 'on', trace : 'on',
- trace.playwright.dev
- Inside of config > Use
await page.locator("h3:has-text(productName)")
another method to find elements
- API will get the response, front will render the data and present
- End points
- Apps are driven by session cookies
- Use token for multiple test cases instead of login
- One test case will store the token
- Method: storage state ==> JSON File
- Login, save JSON, inject JSON on all test
- New instance (context) pass the json
- Storage happens at the context level, not at the page level
- to Debug - package.json, under Debug, "Scripts" > "test" and pass the command
- Debug npm script mode (Shift Ctrl + P)
- when debugging increase timeout time
- Keep in mind each Endpoint and responses
- Intercept response instead of deleting all data
- Interception basically is using .route(). Url you want to intercept and continue to the url you want to redirect
- page.route('**/*.css', route => route.abort()); any url
- page.route('**/*.{css,jpg,png,jpeg}', route => route.abort());
- page.on('request', request => console.log(request.url()));
- page.on('response', request => console.log(response.url(), response.status()));
- File to File comparison - Test to compare 2 screenshots
- Test case should be wrapped in its own logic file
- Login should be go in its own JS File
- When using a JSON File to send test data: JSON -> String -> JS Object
- Driving the data test from external files
- Parameterization w/ different data set
- Make JSON as an array
- For data set (multiple test data) encapsule inside for-loop
- ${data.userType} is no differentiate the test data from the Json... ` this quote type is important
- Fixture -> crate
- Run multiple configurtion files
- Single file with Project array
- Have to specify the project to run
- Running in serial - Default
- For parallel - workers 5 by default.
- for tests inside one single file, pass the following parameter
- test.describe.configure({mode:'parallel}) -- inside the test file, at the top
- serial mode, upon fail of a test, it will stop the rest of the test
- Tagging:
- example test('@Web .... @API....
- npx playwright test --grep="@Web"
- Install Allue Playwright > npm i -D allure
- Run partial test using allure: npx playwright test --grep="@Web" --reporter=line,allure-playwright
- Generate Report: allure generate .\allure-results\ --clean
- Open the report: allure open .\allure-report\
- Issue related to "allure: The term 'allure' is not recognized as the name of a cmdlet
- Solution: https://www.npmjs.com/package/allure-commandline
- Command: npm install -g allure-commandline --save-dev
- Issue related to scripts is disabled on this system...
- Solution: Delete File C:\Users\Ivan\AppData\Roaming\npm\allure.ps1
- Start Jenkins: java -jar jenkins.war -httpPort=9090
- New
- Title, Freestyle
- Description
- This project is parameterized (add Name and choices)
- Custom Path
- Build: Windows batch --> npm run "%Script%"
- Shell: npm run "$Script" (Shell)