我在页面上有一个元素用作显示下拉菜单的按钮。页面上有很多移动部分,在修复一些错误之前,菜单的对齐方式会因按钮而偏离几个像素。我想知道如何为此编写测试,因为这些职位可能会改变。例如:
$this->verifyElementPositionLeft($button,348);
$this->verifyElementPositionLeft($menu,348);
不会工作。我想尝试做的事情看起来像下面这样:
$this->storeElementPositionLeft($button,'buttonLeft');
$this->storeElementPositionLeft($menu,'menuLeft');
$this->assertEquals($buttonLeft,$menuLeft);
但我一定不理解 SeleniumTestCase.php 存储变量的方式,经过进一步调查,这些变量存储为 javascript 变量而不是 PHP;那是对的吗?非常感谢任何帮助理解如何使这项工作或指导更多说明性文档的帮助。
最佳答案
因此,通过 SeleniumRC 命令 getElementPositionLeft,通过查看代码我能够弄清楚这是如何完成的。因此:
$buttonLeft = $this->getElementPositionLeft( $button );
$menuLeft = $this->getElementPositionLeft( $menu );
$this->assertEquals( $buttonLeft, $menuLeft );
phpunit-selenium / PHPUnit / Extensions / SeleniumTestCase / Driver.php
关于javascript - 如何使用 PHP 比较 Selenium WebDriver 中元素的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20861818/