Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/testdriverai/goodlooks

Visually Validate Playwright Tests Without Flaky Selectors
https://github.com/testdriverai/goodlooks

ai api cypress cypress-io gpt-3 gpt-4 openai-api openai-chatgpt playwright playwright-javascript regression-testing ui-testing

Last synced: 22 days ago
JSON representation

Visually Validate Playwright Tests Without Flaky Selectors

Awesome Lists containing this project

README

        

![GoodLooks Logo](https://github.com/dashcamio/goodlooks/assets/318295/feb1d637-f1b0-48a2-8fd7-d4b855ad93bd)

# Visually Validate Playwright Tests Without Flaky Selectors

Static selectors break with code changes and can't prove that a site "looks good". Is that button really missing or was the `id` changed? Is the site responsive on mobile? Is the correct image showing? These kinds of tests are impossible to validate with selectors alone and take a lot of time to test manually. GoodLooks.ai lets you visually validate your web pages with natural language prompts instead of selectors.

Check out our other products: [TestDriver.ai](https://testdriver.ai/?ref=goodlooks) and [Dashcam.io](https://dashcam.io?ref=goodlooks).

## Quickstart

1. `git clone [email protected]:dashcamio/goodlooks.git`
2. `npm install`
3. `npx playwright test`

Note that these examples use a demo key that gets rotated weekly; you'll want to [create your own API KEY](https://lgtm-main-80a621c.d2.zuplo.dev/docs/routes/~pricing).

# Examples

## Element Visibility

Validate that a cookie banner shows up.

Input Code



![Framer.com Cookie Banner](https://github.com/dashcamio/goodlooks/assets/318295/4a4f02a4-95f8-4ec7-a0cb-f411c5d6776a)


```js
const { test, expect } = require("@playwright/test");

const goodlooks = require("goodlooks");
goodlooks.configure("zpka_c0d0539ada014283bc974f0fd55835ea_2b745cbf");

expect.extend(goodlooks);

test("framer", async ({ page }) => {
await page.goto("https://framer.com/");
await page.waitForTimeout(5000);
await expect(page).goodlooks("A request to enable cookies shows up");
});

```

Result


✅ PASS. The page displays a request to enable cookies with a message stating "We use cookies to personalize content, run ads, and analyze traffic." and an "Okay" button to acknowledge the message.

## Mobile Responsiveness

Ensure a page is rendering mobile view properly.

Input Code



![CNN.com on mobile](https://github.com/dashcamio/goodlooks/assets/318295/277e87fb-4dd7-4a86-a011-02f5fc874342)


```js
const { test, expect, devices } = require("@playwright/test");

const goodlooks = require("goodlooks");
goodlooks.configure("zpka_c0d0539ada014283bc974f0fd55835ea_2b745cbf");

expect.extend(goodlooks);

test("is mobile responsive", async ({ page }) => {
page.setViewportSize(devices["iPhone X"].viewport);
await page.goto("https://cnn.com/");

await expect(page).goodlooks("should be mobile responsive");

});

```

Explanation


✅ PASS. The page appears to be displayed in a mobile-responsive layout. The content is aligned correctly within the confines of a narrow screen typical of mobile devices. The text is legible, the menu collapses into a hamburger icon, and the image is scaled to fit the screen width, indicating that the design adapts to a mobile resolution.

## Application State

Validate that the video player is not playing.

Input Code



![Rick Astley YouTube](https://github.com/dashcamio/goodlooks/assets/318295/ab885bed-fba7-4ae7-b295-98f74c7392fa)


```js
const { test, expect } = require("@playwright/test");

const goodlooks = require("goodlooks");
goodlooks.configure("zpka_c0d0539ada014283bc974f0fd55835ea_2b745cbf");

expect.extend(goodlooks);

test("rickroll", async ({ page }) => {
await page.goto("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
await expect(page).goodlooks("video is not playing");
});

```

Result


✅ PASS. The page shows a video with the play button available and a timeline that is not progressing, indicating that the video is currently not playing.

## Color

Ensure a page renders correct image contents via `img` or `canvas`.

Input Code



![CleanShot 2024-03-08 at 12 46 45](https://github.com/dashcamio/goodlooks/assets/318295/da5c057c-b28d-40fe-8adb-6e7c8f6e1899)


```js
const { test, expect, devices } = require("@playwright/test");

const goodlooks = require("goodlooks");
goodlooks.configure("zpka_c0d0539ada014283bc974f0fd55835ea_2b745cbf");

expect.extend(goodlooks);

test("ycombinator", async ({ page }) => {
await page.goto("https://news.ycombinator.com");
await expect(page).goodlooks(
"there is an orange strip at the top of the page"
);
});

```

Result


✅ PASS. The page has an orange strip at the top, which is consistent with the given condition.

## Image Contents

Ensure a page renders correct image contents via `img` or `canvas`.

Input Code



![Eloquent Javascript](https://github.com/dashcamio/goodlooks/assets/318295/359e6df7-80ac-4cfe-afec-c25d426c57bb)


```js
const { test, expect, devices } = require("@playwright/test");

const goodlooks = require("goodlooks");
goodlooks.configure("zpka_c0d0539ada014283bc974f0fd55835ea_2b745cbf");

expect.extend(goodlooks);

test("correct image appears", async ({ page }) => {
await page.goto("https://eloquentjavascript.net/");
await expect(page).goodlooks("there is bird on this page");
});

```

Result


✅ PASS. There is an illustration of a bird on the left side of the page on the cover of a book titled "Eloquent JavaScript, Fourth Edition."

## Opinionated Image Contents

Ensure a diverse representation of people appears on the page. Of course, this judgement is left up to AI.

Input Code



![CleanShot 2024-03-08 at 11 55 13](https://github.com/dashcamio/goodlooks/assets/318295/bb6e22ec-e1c7-4c99-b08b-e6740224b4cb)


```js
const { test, expect } = require("@playwright/test");
const goodlooks = require("goodlooks");
goodlooks.configure("zpka_c0d0539ada014283bc974f0fd55835ea_2b745cbf");

test("diversity", async ({ page }) => {
await page.goto("https://diversityequityinclusion.com/about/");
await expect(page).goodlooks("diverse people show up");
});
```

Result


✅ PASS. The page includes a collage of images featuring various individuals in different settings and professional environments, indicative of a diverse group of people. This aligns with the theme of "Diversity Equity Inclusion" that is prominently displayed on the page.

# Setup

Install via NPM.

```
npm install goodlooks
```

Use in Playwright tests!

```js
const { test, expect, devices } = require("@playwright/test");
const goodlooks = require("goodlooks");
goodlooks.configure("zpka_c0d0539ada014283bc974f0fd55835ea_2b745cbf");
expect.extend(goodlooks);
```

# Debugging

## It seems like GoodLooks is wrong? I'm sure the element exists that I'm checking for.

Run your playwright tests in UI mode:

```
npx playwright test --ui
```

1. Check the log to see the time frame where the `goodlooks` check is called. Hover over that.
2. A red highlight will appear in the Playwright UI, showing you the GUI state when the screenshot was taken
3. You can also see the debug logs within the Console or Error tabs.
![CleanShot 2024-03-08 at 12 27 49](https://github.com/dashcamio/goodlooks/assets/318295/011ec7ff-e5ce-444e-839a-4c3f74a9da5b)

## What part of the page is checked?

Only the visible part of the page is checked, not the full page. You must scroll to check other page parts.

## What are the limits?

The AI is great at identifying what is in an image, but it's not great at identifying where those things are in relation to other things. For example, don't ask GoodLooks to count items to validate their position on the screen.

## How do I manage my subscription

You can [manage your subscription here](https://lgtm-main-80a621c.d2.zuplo.dev/docs/routes/~subscription).

# Other Projects

- [TestDriver.ai](https://testdriver.ai?ref=goodlooks) - AI QA Agent for GitHub
- [Dashcam.io](https://dashcam.io?ref=goodlooks) - Instant Replay for Software Testing