In this session, we explored setting up Playwright, an end-to-end testing tool for simulating browser interactions and running TestBox tests. Participants learned to configure Playwright for applications, simulate user interactions to stress-test forms, and handle scenarios like taking screenshots, ...
In this session, we explored setting up Playwright, an end-to-end testing tool for simulating browser interactions and running TestBox tests. Participants learned to configure Playwright for applications, simulate user interactions to stress-test forms, and handle scenarios like taking screenshots, recording sessions, capturing Chrome dev tools traces, testing login failures, and managing broken JavaScript. The session also covered using Playwright with non-ColdBox sites, providing practical insights into enhancing testing capabilities.
Size: 636.8 KB
Language: en
Added: Jun 30, 2024
Slides: 26 pages
Slide Content
How to Break Your App
With Playwright Tests
1
What we will talk about today.
●What is cbPlaywright
●How to get cbPlaywright working on a Coldbox
and none Coldbox apps
●How to use cbPlaywrights basic features
●How to use some of cbPlaywrights more
advanced features
2
Who am I?
3
●Part time student at BC working toward a BS
in Industrial automation
●Favorite thing to do is go on Mission trips
●Learned basic C++ on YouTube
●Got hired to work for Scott at UTS
What is Playwright?
Playwright is a Java library made by Microsoft.
cbPlaywright is a ColdFusion wrapper for this Java library.
We can use it to do end-to-end testing!
4
Why not just use the Java library
Because it’s harder and I’m lazy
5
So what is end-to-end testing?
Normal Testing
End-to-end testing
6
Setting up cbPlaywright
Run the following in CommandBox
●install testbox
●install cbplaywright
7
Setting up cbPlaywright
Add the following to tests/Application.cfc
Setting up cbPlaywright
Run the following in CommandBox
●playwright-cli
●playwright install {{browser}}
Browsers that can be installed are:
chromium, firefox, webkit, msedge
9
Setting up cbPlaywright
Explicitly set the port
10
If cbPlaywright is not running
You may get this error on newer Macs:
bad CPU type in executable: node
To fix this run the following command:
softwareupdate --install-rosetta
11
Making a cbPlaywright test
component extends="cbPlaywright.models.ColdBoxPlaywrightTestCase" {
function run() {
describe( "Description", () => {
it( "can do something", () => {
Tests go here!
}
}
}
}
Go to tests/specs/integration and create a cfc
12
Creating a browser, context, and page
Browser
Context
Page
var browser = launchInteractiveBrowser (variables.playwright.chromium());
var context = browser.newContext();
var page = context.newPage();
var browser = launchBrowser(variables.playwright.chromium());
//This method is a shortcut for creating a browser and a context.
var page = browser.newPage();
Now that cbPlaywright is on the page
Their is three main things we will be doing
●Selecting elements
●Interacting with elements
●Getting the value from elements
15
Some of the methods for selecting are…
page.getByAltText("AltText")
page.getByLabel("Label")
page.getByPlaceholder("Placeholder")
page.getByText("Text")
page.getByTitle("Title")
page.getByTestId("TestID")
locateElement(page, "input[name=username]")
getByRole(page, "link", {name: "Hello"})
page.title()
.first()
.last()
.nth(3)//zero indexed
16
<div data-testid="TestID">Text</div>
Some of the methods for interacting are…
element.fill("Fill Text")
element.selectOption("Option")
element.click()
element.dblclick()
element.press("ArrowLeft")
element.setChecked(true)
17
Some of the methods for Getting values are…
element.innerText()
element.inputValue()
element.isChecked()
element.isVisible()
expect(page.getByTestId("title").innerText()).toBe("Hello World!");
expect(page.getByTestId("random_shmamdom").isVisible()).toBeTrue();
18