npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gikyoku

v1.3.0

Published

Implement the screenplay pattern for Playwright.

Downloads

7

Readme

GIKYOKU

MIT License BUILD npm version

Introduction

This repository is forked from testla-screenplay-playwright-js to extend it. This package uses the Testla screenplay core package to implement the screenplay pattern for Playwright. By the way, GIKYOKU means "screenplay" in Japanese.

'screenplay'
.toJapanese() // 戯曲
.toAlphabet() // GIKYOKU

How to use this package?

This package comes with abilities, question and actions to browse user interfaces and querying APIs.

Group Actions into a Task

Tasks group actions into logical entities. Here is a task that uses the actions Navigate, Fill and Click from the web capabilities and Get from api capabilities.

// file: ./task/Login.ts

import { Actor, Task } from 'gikyoku';
import { Click, Fill, Navigate } from 'gikyoku/web';
import { Get} from 'gikyoku/api';

export class Login extends Task {
    public async performAs(actor: Actor): Promise<void> {
        return actor.attemptsTo(
            Navigate.to('https://www.my-fancy-url.com'),
            Fill.with(page.locator('#username'), actor.states('username') || ''),
            Fill.with(page.locator('#password'), actor.states('password') || ''),
            Click.on(page.locator()'#login-button')),
            Get.from('https://www.my-fancy-url.com')
        );
    }

    public static toApp(): Login {
        return new Login();
    }
}

Initialize Actor with Abilities as Playwright Fixture

Initialize an actor with abilities as Playwright Fixture for later use in a test case.

import { Actor } from "gikyoku";
import { test as base } from "@playwright/test";

type MyActors = {
  actor: Actor;
};

const test = base.extend<MyActors>({
  actor: async ({ page, request }, use) => {
    const actor = Actor.named("TestActor")
      .with('username', 'John Doe')
      .with('password', 'MySecretPassword');
      .can(BrowseTheWeb.using(page))
      .can(UseAPI.using(request))
      .with("page", page);
    await use(actor);
  },
});

Test case example

The final step is to define a test case using the Task defined above.

import { Element } from 'gikyoku/web';
import { Login } from './task/Login';

// Example test case with Playwright
test.describe('My Test', () => {
  test('My first test', async ({ actor }) => {
    // Execute the task Login - as defined further above
    await actor.attemptsTo(Login.toApp());

    // Check if the login was successful - use the status question from the web package
    await actor.asks(
      Element.of(
        page.locator('#logged-in-indicator')
      ).visible()
    );
  });
});

Besides the existing actions, abilities and questions it is of course possible to define your own ones. How this is done, please refer to core package.

Since tasks, actions and questions return promises, we advise to make use of the require-await rule in case of using eslint. This will help to prevent unexpected behavior when forgetting to await tasks/actions or questions.

Logging

This feature is currently in experimental stage and might see bigger changes.

Testla comes with logging which helps you to debug your test code. When logging is enabled all activities an actor triggers are logged in a comprehensive way to stdout. To enable logging set the DEBUG environment variable as follows:

DEBUG=testla:sp

To understand how to enable logging in custom Actions and Questions please refer to the logging guide of Testla Screenplay Core.

API Specification

See API Specification.