Giter Site home page Giter Site logo

Comments (3)

JoelEinbinder avatar JoelEinbinder commented on May 22, 2024

I had a conversation with @mxschmitt about this offline. Pasting my parts here:

There are a lot of thought provoking ideas in that library, but I am having trouble coming up with a response that covers all of them.

I think we should discuss them individually.
Some should be built into playwright-runner, some into playwright itself, some stay in external libraries.

Like the first example:

await expect(page).toHaveSelector("#foobar");

This is pretty much equivalent to await page.waitForSelector('#foobar') right?

but then

await expect(page).not.toHaveSelector("#foobar");

makes everything a lot trickier

because is this

expect(await page.$('#foobar')).toBe(null);

or is it

expect(await page.waitForSelector('#foobar').catch(e => null)).toBe(null);

one will always wait the full timeout, making the test slow

The other will pass if the element comes in later. So you could have both
expect(page).toHaveSelector and expect(page).not.toHaveSelector pass!

I don't think the "not" case is very important, but staying within the expect syntax forces us to implement it. What if instead it was in playwright itself as a collection of page.assert methods? Then it would also be clearer that expect is synchronous and page.assert is async.

from playwright-test.

jperl avatar jperl commented on May 22, 2024

Yes page.assert methods would serve the same purpose as expect, I do not have a strong opinion either way about this.

I can think of a few scenarios where .not.toHaveSelector and .not.toHaveText are valuable.

  • After clearing items, to make sure they are gone
  • After dismissing a modal, to make sure it is gone

In both of those I would want the test to auto-wait for the selector to be gone. So the test should only be as slow as the application is to remove those elements.

from playwright-test.

thernstig avatar thernstig commented on May 22, 2024

The text one would be cool to have. An example would be expect(page/element).toHaveText('some text'), taking into account somehow the 3 different kind of text matchers text=example one (case-insensitive, substring matching), text="example 2" (exact matching), text=/^\\s*Some text$/i (regex matching).

Also, I assume the .not.toHaveText('some text') would equal to use waitForSelector('text=some text', {waitFor: 'hidden'})

from playwright-test.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.