-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[6.x] Add assertNotPresent()
assertion
#879
Conversation
assertNotPresent()
assertionassertNotPresent()
assertion
So under what circumstances is something "not present"? When it is in the source but not visible? Some other scenario? |
Hi Taylor, No, something is "not present" when it cannot be found in the source and therefore won't be visible. Currently, there are the following assertions which descriptions from the docs:
To ensure something is not visible I can use:
But there is no method I can see that allows me to ensure an element is not present In my case, I am checking the presence of inputs, some of which may be hidden & replaced by javascript for a WYSIWYG editor. |
|
That was the behaviour I was expecting, but unfortunately, that's not the case. This is the public function assertMissing($selector)
{
$fullSelector = $this->resolver->format($selector);
try {
$missing = ! $this->resolver->findOrFail($selector)->isDisplayed();
} catch (NoSuchElementException $e) {
$missing = true;
}
PHPUnit::assertTrue(
$missing,
"Saw unexpected element [{$fullSelector}]."
);
return $this;
} |
Rather than create a breaking change by modifying |
@GingerNinjaNicko but in the very code you posted, it looks like it catches the exception for a totally missing element and also sets that to $missing = true? |
Ah yes apologies @taylorotwell, I think you were right with your first comment but I got a little confused... The difference is what causes the assertion to fail.
Hopefully I'm making more sense now. |
Maybe |
@SjorsO yeah that might be a good idea... @GingerNinjaNicko could you rename the method to that and put it by the other assertSourceMissing method? |
Eh |
I recently ran into a use case where I needed to ensure an array of inputs would definitely submit on the page, and another array of inputs definitely were not.
assertPresent()
was exactly what I needed, but I could not find an inverse of it.assertMissing()
checked that the input was visible, but some of the inputs are hidden and replaced via JavaScript, so this doesn't work.Therefore, I added an
assertNotPresent()
assertion for this specific use-case.I did think of naming it
assertAbsent()
but think the distinction between this andassertMissing()
could become confusing...This is the relevant part of the test I wanted to write: