Skip to content

Commit

Permalink
Add string type assertion test
Browse files Browse the repository at this point in the history
  • Loading branch information
uuf6429 committed Jan 4, 2025
1 parent d909da0 commit 5a53ec5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/Custom/WebDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
namespace Mink\WebdriverClassicDriver\Tests\Custom;

use Behat\Mink\Exception\DriverException;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\RemoteWebElement;
use Facebook\WebDriver\WebDriverOptions;
use Facebook\WebDriver\WebDriverTimeouts;
use Mink\WebdriverClassicDriver\WebdriverClassicDriver;

class WebDriverTest extends TestCase
Expand Down Expand Up @@ -72,4 +76,32 @@ public function testClassicDriverCanProvideBrowserName(): void
$this->driver->getBrowserName()
);
}

public function testThatDriverCatchesUnexpectedAttributeValueType(): void
{
$mockWebDriver = $this->createMock(RemoteWebDriver::class);
$mockWebDriverOptions = $this->createMock(WebDriverOptions::class);
$mockWebDriverTimeouts = $this->createMock(WebDriverTimeouts::class);
$mockElement = $this->createMock(RemoteWebElement::class);
$mockWebDriver->method('manage')->willReturn($mockWebDriverOptions);
$mockWebDriverOptions->method('timeouts')->willReturn($mockWebDriverTimeouts);
$mockWebDriver
->expects($this->once())
->method('findElement')
->willReturn($mockElement);
$mockWebDriver
->expects($this->once())
->method('executeScript')
->with('return arguments[0].getAttribute("some-attribute")', [$mockElement])
->willReturn(['invalid attribute value']);

$driver = new WebdriverClassicDriver('fake browser', [], 'example.com', fn() => $mockWebDriver);

$driver->start();

$this->expectException(DriverException::class);
$this->expectExceptionMessage('The element\'s some-attribute attribute should be a string or at least a scalar value, but received `array` instead');

$driver->getAttribute('//fake', 'some-attribute');
}
}

0 comments on commit 5a53ec5

Please sign in to comment.