Skip to content

Commit 97673ae

Browse files
committed
Fix type error for element without form
1 parent 7c4f2c0 commit 97673ae

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/Codeception/Lib/InnerBrowser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ protected function getValueAndTextFromField(Crawler $nodes): array|string
802802
return $values;
803803
}
804804

805-
$this->fail("Element {$nodes} is not a form field or does not contain a form field");
805+
$this->fail("Element {$nodes->getNode(0)?->getNodePath()} is not a form field or does not contain a form field");
806806
}
807807

808808
/**
@@ -1539,7 +1539,7 @@ public function grabValueFrom($field): mixed
15391539
return $values;
15401540
}
15411541

1542-
$this->fail("Element {$nodes} is not a form field or does not contain a form field");
1542+
$this->fail("Element {$nodes->getNode(0)?->getNodePath()} is not a form field or does not contain a form field");
15431543
}
15441544

15451545
public function setCookie($name, $val, $params = [])

tests/data/app/view/form/field_values.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@
5454
5555
<input type="submit" name="submit" value="Submit" />
5656
</form>
57+
<button type="submit" name="button_without_form" value="yes" />
5758
</body>
5859
</html>

tests/unit/Codeception/Module/TestsForWeb.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,14 @@ public function testDontSeeInFieldOnTextarea()
633633
$this->module->dontSeeInField('textarea', 'sunset');
634634
$this->module->dontSeeInField('descendant-or-self::textarea[@id="description"]', 'sunset');
635635
}
636+
637+
public function testSeeInFieldOnButtonWithoutFormFails()
638+
{
639+
$this->shouldFail('Element /html/body/button is not a form field or does not contain a form field');
640+
641+
$this->module->amOnPage('/form/field_values');
642+
$this->module->seeInField(['name' => 'button_without_form'], 'yes');
643+
}
636644

637645
public function testSeeInFormFields()
638646
{
@@ -784,6 +792,14 @@ public function testGrabValueFromWithFillField()
784792
$this->assertSame('new value', $result);
785793
}
786794

795+
public function testGrabValueFromOnButtonWithoutFormFails()
796+
{
797+
$this->shouldFail('Element /html/body/button is not a form field or does not contain a form field');
798+
799+
$this->module->amOnPage('/form/field_values');
800+
$this->module->grabValueFrom(['name' => 'button_without_form']);
801+
}
802+
787803
public function testGrabAttributeFrom()
788804
{
789805
$this->module->amOnPage('/search');
@@ -1251,9 +1267,12 @@ public function testSelectTwoSubmitsByCSS()
12511267
$this->assertSame('2', $form['sandwich_select']);
12521268
}
12531269

1254-
protected function shouldFail()
1270+
protected function shouldFail(?string $message = null)
12551271
{
12561272
$this->expectException(AssertionFailedError::class);
1273+
if (null !== $message) {
1274+
$this->expectExceptionMessage($message);
1275+
}
12571276
}
12581277

12591278
/**

0 commit comments

Comments
 (0)