Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@serenity-js/playwright-test
Advanced tools
Serenity/JS reporter and test APIs for Playwright Test
** This README is for Serenity/JS version 3.0-RC. Some links might not work yet as we're working on getting the new website and API docs ready. Thanks for your patience and support! **
Serenity/JS is a framework designed to make acceptance and regression testing of modern full-stack applications faster, more collaborative and easier to scale.
Visit serenity-js.org for the latest tutorials and API docs, and follow @SerenityJS and @JanMolak on Twitter for project updates.
To learn more about Serenity/JS, follow the tutorial, review the examples, and create your own test suite using the Serenity/JS template projects.
If you have any questions, join us on the Serenity/JS Community Chat.
@serenity-js/playwright-test
module offers a Serenity/JS reporter
and fixtures that integrate Playwright Test with Serenity/JS Screenplay Pattern APIs.
To install this module, use an existing Playwright project or generate a new one by running:
npm init playwright@latest
Next, run the following command in your Playwright project directory:
npm install --save-dev @serenity-js/{assertions,console-reporter,core,serenity-bdd,web,playwright,playwright-test}
To use Serenity/JS Screenplay Pattern APIs and benefit from the in-depth reporting capabilities, import Serenity/JS test fixtures instead of the default ones:
// example.spec.ts
+ import { test } from '@serenity-js/playwright-test'
- import { test } from '@playwright/test'
test.describe('Serenity Screenplay with Playwright', () => {
test.describe('New Todo', () => {
test('should allow me to add todo items', async ({ page }) => {
//...
})
})
})
If you prefer, Serenity/JS also offers the more concise BDD-style describe/it
syntax:
// example.spec.ts
import { describe, it, test } from '@serenity-js/playwright-test'
test.use({
headles: true,
})
describe('Serenity Screenplay with Playwright', () => {
describe('New Todo', () => {
it('should allow me to add todo items', async ({ page }) => {
//...
})
})
})
Serenity/JS test fixtures simplify how you instantiate and use Serenity/JS Screenplay Pattern Actors.
If your tests need only a single actor, you can inject it using the actor
fixture.
To configure the name of your default actor, use the defaultActorName
configuration property:
// example.spec.ts
import { describe, it, test } from '@serenity-js/playwright-test' // import fixtures
import { Navigate, Page } from '@serenity-js/playwright' // import Screenplay Pattern Web APIs
import { Ensure, equals } from '@serenity-js/assertions' // import Screenplay Pattern assertion APIs
test.use({
headles: true,
defaultActorName: 'Serena' // change default actor name
})
describe('Serenity Screenplay with Playwright', () => {
describe('New Todo', () => {
// inject default actor:
it('should allow me to add todo items', async ({ actor }) => {
// define test workflow
await actor.attemptsTo(
Navigate.to('https://todo-app.serenity-js.org/'),
Ensure.that(Page.current().title(), equals('Serenity/JS TodoApp')),
)
})
})
})
For multi-actor scenarios where you need each actor to use a separate browser, use the actorCalled
fixture.
You can also use this pattern to override the default actor name on a per-scenario basis:
// example.spec.ts
import { describe, it, test } from '@serenity-js/playwright-test' // import fixtures
describe('Serenity Screenplay with Playwright', () => {
describe('Chat app', () => {
it('should allow actors to send and receive messages', async ({ actorCalled }) => {
// define part of the workflow performed by the first actor:
await actorCalled('Alice').attemptsTo(
// navigate to a chat app
// post a message to Bob
)
// define parts of the workflow performed by the any other actors:
await actorCalled('Bob').attemptsTo(
// navigate to a chat app
// post a reply to Alice
)
// Note that invoking actorCalled(name) multiple times
// while using the same name and within the scope of a single test
// returns the same actor, so you don't need to cache them:
await actorCalled('Alice').attemptsTo(
// check if the reply from Bob is received
)
})
})
})
The default cast of actors is limited to using a single ability
to BrowseTheWebWithPlaywright
.
If you'd like to give your actors additional abilities, like to TakeNotes
,
CallAnApi
,
or ManageALocalServer
, you can install the relevant Serenity/JS module
and configure them as follows:
// example.spec.ts
import { Cast, TakeNotes } from '@serenity-js/core'
import { test } from '@serenity-js/playwright-test'
import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright'
import { CallAnApi } from '@serenity-js/rest'
test.use({
actors: async ({ browser, baseURL }, use) => {
await use(
Cast.where(actor => actor.whoCan(
BrowseTheWebWithPlaywright.using(browser),
TakeNotes.usingAnEmptyNotepad(),
CallAnApi.at(baseURL),
))
)
},
})
For scenarios where different actors need to be configured differently, you can also implement your own Cast
:
// example.spec.ts
import { Cast } from '@serenity-js/core'
import { BrowseTheWebWithPlaywright, PlaywrightOptions } from '@serenity-js/playwright'
import { test } from '@serenity-js/playwright-test'
import { CallAnApi } from '@serenity-js/rest'
import { Browser } from 'playwright'
class Actors implements Cast {
constructor(
private readonly browser: Browser,
private readonly options: PlaywrightOptions,
) {
}
prepare(actor: Actor) {
switch (actor.name) {
case 'James':
return actor.whoCan(BrowseTheWebWithPlaywright.using(this.browser, this.options))
default:
return actor.whoCan(CallAnApi.at(this.options.baseURL))
}
}
}
test.use({
actors: async ({ browser, config }) => {
await use(new Actors(browser, {
defaultNavigationWaitUntil: 'domcontentloaded'
}))
}
})
To use Serenity/JS reporting capabilities, register the @serenity-js/playwright-test
reporter in your
playwright.config.ts
and define the appropriate reporting services (a.k.a. your "stage crew").
For example, to enable Serenity/JS Console Reporter and Serenity BDD reporter, install the relevant modules:
npm install --save-dev @serenity-js/{console-reporter,serenity-bdd}
Next, configure your Playwright project as follows:
// playwright.conf.ts
import type { PlaywrightTestConfig } from '@playwright/test'
const config: PlaywrightTestConfig = {
reporter: [
[ '@serenity-js/playwright-test', {
crew: [
'@serenity-js/serenity-bdd',
'@serenity-js/console-reporter',
[ '@serenity-js/core:ArtifactArchiver', { outputDirectory: 'target/site/serenity' } ],
// '@serenity-js/core:StreamReporter',
]
}],
// optional
[ 'html', { open: 'never' } ], // built-in Playwright HTML reporter
],
// Other configuration omitted for brevity
// For details, see https://playwright.dev/docs/test-configuration
}
export default config
Note that Serenity/JS reporters work well with the built-in Playwright reporters.
You can find a reference implementation demonstrating how to integrate Serenity/JS with Playwright Test in the Serenity/JS GitHub repository.
New features, tutorials, and demos are coming soon, so follow us on LinkedIn and join the Serenity/JS Community Chat channel to stay up to date!
If you enjoy using Serenity/JS and would like to keep new features coming, become our GitHub Sponsor and donate as much or as little as you find appropriate.
3.0.0-rc.45 (2023-03-22)
FAQs
Serenity/JS test runner adapter for Playwright Test, combining Playwright's developer experience with the advanced reporting and automation capabilities of Serenity/JS
The npm package @serenity-js/playwright-test receives a total of 2,585 weekly downloads. As such, @serenity-js/playwright-test popularity was classified as popular.
We found that @serenity-js/playwright-test demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.