【发布时间】:2020-03-25 15:21:44
【问题描述】:
按照here 的示例,尝试实现一些 Selenium 测试。
测试类代码:
class StackoverflowTest extends \PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp(): void
{
$this->setHost('localhost');
$this->setPort(4444);
$this->setBrowserUrl('https://stackoverflow.com/');
$this->setBrowser('chrome');
parent::setUp();
}
public function onNotSuccessfulTest(Throwable $e): void
{
$filedata = $this->currentScreenshot();
$file = __DIR__ . '/' . time() . '.png';
file_put_contents($file, $filedata);
parent::onNotSuccessfulTest($e);
}
/**
* @test
*/
public function visit_home_page_case_success()
{
$this->url('/');
dump($this->title());
dd($this->byTag('body')->text()); //line 35
}
}
控制台输出:
...
"Stack Overflow - Where Developers Learn, Share, & Build Careers"
...
There was 1 error:
1) ...\StackoverflowTest::visit_home_page_case_success
InvalidArgumentException: Element not found.
...
.../StackoverflowTest.php:35
...
截图:
出了什么问题以及如何与页面元素进行交互?
重复here。
【问题讨论】:
标签: php selenium selenium-webdriver phpunit