Skip to content

v8.31.7 — New global hooks and other improvements!

Choose a tag to compare

@shadowusr shadowusr released this 14 Oct 15:34
· 237 commits to master since this release

This release contains new built-in global hooks and bug fixes, important for component tests as well as minor improvements of isolation behavior and typings.

🚀 Improvements

We are happy to announce new beforeAll and afterAll hooks that you may use in the config. A neat use-case for them is to authenticate once, save cookies to a file and then re-use them in each test. A corresponding command will soon become available (keep an eye on this PR)!

Here's how you can use these new hooks:

// testplane.config.ts
import fs from "fs";
import {launchBrowser} from "testplane/unstable";

const COOKIE_PATH = "./cookies.json";

export default {
    browsers: {
        "chrome-desktop": {
            desiredCapabilities: { browserName: "chrome" }
        }
    },

    beforeAll: async ({config}) => {
        const browser = await launchBrowser(config.browsers["chrome-desktop"]);
        await browser.url("https://example.com/login");

        await browser.setValue("#username", "user");
        await browser.setValue("#password", "pass");
        await browser.click("#submit");

        const cookies = await browser.getCookies();
        fs.writeFileSync(COOKIE_PATH, JSON.stringify(cookies));

        await browser.deleteSession();
    },

    afterAll: async () => {
        if (fs.existsSync(COOKIE_PATH)) {
            fs.rmSync(COOKIE_PATH);
        }
    }
};

Note: as soon as #1139 merges, a more convenient browser.saveState() and browser.restoreState() will become available for saving and restoring cookies!

🐛 Bug fixes

  • With isolation turned on, there will be no longer an extra window when using BiDi protocol
  • Component tests now work just fine with Testing Library and Docker. If you need to customize vite server URL when using docker, you may do so using baseUrl in config:
    // testplane.config.ts
    export default {
        baseUrl: 'http://host.docker.internal:5723', // Port number should be identical to what you set in vite.config.ts
    };
  • The windowSize config option now has a bit better typings: now you can pass string like "1920x1080".