使用PHPUnit的Selenium没有加载页面(Selenium with PHPUnit not loading page)
我正在尝试使用phpunit和phpunit-selenium为php项目制作测试套件。 在我的作曲家文件中,我有
"require-dev": { "phpunit/phpunit": "^5.7", "phpunit/phpunit-selenium": "^3.0" }
安装的phpunit版本是5.7.4我使用selenium-server-standalone-3.0.1.jar作为selenium服务器。 我用java -Dwebdriver.gecko.driver =“C:\ Harlan \ Selenium \ geckodriver.exe”启动服务器-jar selenium-server-standalone-3.0.1.jar
在我的测试课中,我有
require_once dirname(__FILE__) . '/../../vendor/autoload.php'; class UserSubscriptionTest extends PHPUnit_Extensions_Selenium2TestCase { public function setUp() { $this->setHost('localhost'); $this->setPort(4444); $this->setBrowserUrl('http://localhost/cwckids/web/user/login'); $this->setBrowser('firefox'); } public function tearDown() { $this->stop(); } public function testFormSubmissionWithUsername() { $this->byName('login-form[login]')->value('admin'); $this->byName('login-form[password]')->value('mypassword'); $this->byId('login-form')->submit(); $content = $this->byTag('body')->text(); $this->assertEquals('Everything is Good!', $content, 'something wrong!!'); } }
我的问题是firefox浏览器打开但没有加载页面http:// localhost / cwckids / web / user / login
测试立即失败,因为它无法找到元素。 它给出一条消息说无法找到元素:{“method”:“name”,“selector”:“login-form [login]”}
我找不到问题的解决方案。 它有些版本不兼容吗? 我试过几个版本的Firefox和selenium服务器。 我的Firefox版本是50.1.0。 如果是版本不兼容可以有人建议正确版本吗? 谢谢
完整的痕迹
C:\ xampp \ htdocs \ seleniumtest> phpunit tests / acceptance / UserSubscriptionTest.php由Sebastian Bergmann和贡献者提供的PHPUnit 5.7.4。
E 1/1(100%)
时间:6.51秒,内存:9.25MB
有1个错误:
1)UserSubscriptionTest :: testFormSubmissionWithUsername PHPUnit_Extensions_Selenium2TestCase_WebDriverException:无法找到元素:{“method”:“name”,“selector”:“login-form [login]”}有关此错误的文档,请访问: http:// seleniumhq。 org / exceptions / no_such_element.html构建信息:版本:'2.53.1',修订版:'a36b8b1',时间:'2016-06-30 17:37:03'系统信息:主机:'DESKTOP-I0LAEAM',ip :'192.168.8.101',os.name:'Windows 10',os.arch:'amd64',os.version:'10 .0',java.version:'1.8.0_77'驱动程序信息:driver.version:unknown
C:\ xampp \ htdocs \ seleniumtest \ vendor \ phpunit \ phpunit-selenium \ PHPUnit \ Extensions \ Selenium2TestCase \ Driver.php:165 C:\ xampp \ htdocs \ seleniumtest \ vendor \ phpunit \ phpunit-selenium \ PHPUnit \ Extensions \ Selenium2TestCase \ CommandsHolder.php:108 C:\ xampp \ htdocs \ seleniumtest \ vendor \ phpunit \ phpunit-selenium \ PHPUnit \ Extensions \ Selenium2TestCase \ Element \ Accessor.php:134 C:\ xampp \ htdocs \ seleniumtest \ vendor \ phpunit \ phpunit -selenium \ PHPUnit \ Extensions \ Selenium2TestCase \ Element \ Accessor.php:175 C:\ xampp \ htdocs \ seleniumtest \ vendor \ phpunit \ phpunit-selenium \ PHPUnit \ Extensions \ Selenium2TestCase \ Element \ Accessor.php:108 C:\ xampp \ htdocs \ seleniumtest \ vendor \ phpunit \ phpunit-selenium \ PHPUnit \ Extensions \ Selenium2TestCase.php:394 C:\ xampp \ htdocs \ seleniumtest \ tests \ acceptance \ UserSubscriptionTest.php:66 C:\ xampp \ htdocs \ seleniumtest \ tests \ acceptance \ UserSubscriptionTest.php:66 C:\ xampp \ htdocs \ seleniumtest \ vendor \ phpunit \ phpunit-selenium \ PHPUnit \ Extensions \ Selenium2TestCase.php:348 C:\ xampp \ htdocs \ seleniumtest \ vendor \ p hpunit \ PHPUnit的硒\ PHPUnit的\扩展\ Selenium2TestCase.php:314
错误! 测试:1,断言:0,错误:1。
I am trying to make a test suit for a php project using phpunit and phpunit-selenium. In my composer file I have
"require-dev": { "phpunit/phpunit": "^5.7", "phpunit/phpunit-selenium": "^3.0" }
The installed phpunit version is 5.7.4 I am using selenium-server-standalone-3.0.1.jar as the selenium server. I start the server with java -Dwebdriver.gecko.driver="C:\Harlan\Selenium\geckodriver.exe" -jar selenium-server-standalone-3.0.1.jar
In my test class I have
require_once dirname(__FILE__) . '/../../vendor/autoload.php'; class UserSubscriptionTest extends PHPUnit_Extensions_Selenium2TestCase { public function setUp() { $this->setHost('localhost'); $this->setPort(4444); $this->setBrowserUrl('http://localhost/cwckids/web/user/login'); $this->setBrowser('firefox'); } public function tearDown() { $this->stop(); } public function testFormSubmissionWithUsername() { $this->byName('login-form[login]')->value('admin'); $this->byName('login-form[password]')->value('mypassword'); $this->byId('login-form')->submit(); $content = $this->byTag('body')->text(); $this->assertEquals('Everything is Good!', $content, 'something wrong!!'); } }
My problem is that the firefox browser opens up but doesn't load the page http://localhost/cwckids/web/user/login
The test fails immediately because it cannot find the elements. It give a message saying Unable to locate element: {"method":"name","selector":"login-form[login]"}
I couldn't find a solution for the problem. Is it some version incompatibility? I tried with a few versions of Firefox and also selenium server. My Firefox version is 50.1.0. If it is a version incompatibility can someone suggest correct versions? Thanks
The complete trace
C:\xampp\htdocs\seleniumtest>phpunit tests/acceptance/UserSubscriptionTest.php PHPUnit 5.7.4 by Sebastian Bergmann and contributors.
E 1 / 1 (100%)
Time: 6.51 seconds, Memory: 9.25MB
There was 1 error:
1) UserSubscriptionTest::testFormSubmissionWithUsername PHPUnit_Extensions_Selenium2TestCase_WebDriverException: Unable to locate element: {"method":"name","selector":"login-form[login]"} For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03' System info: host: 'DESKTOP-I0LAEAM', ip: '192.168.8.101', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_77' Driver info: driver.version: unknown
C:\xampp\htdocs\seleniumtest\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase\Driver.php:165 C:\xampp\htdocs\seleniumtest\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase\CommandsHolder.php:108 C:\xampp\htdocs\seleniumtest\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase\Element\Accessor.php:134 C:\xampp\htdocs\seleniumtest\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase\Element\Accessor.php:175 C:\xampp\htdocs\seleniumtest\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase\Element\Accessor.php:108 C:\xampp\htdocs\seleniumtest\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase.php:394 C:\xampp\htdocs\seleniumtest\tests\acceptance\UserSubscriptionTest.php:66 C:\xampp\htdocs\seleniumtest\tests\acceptance\UserSubscriptionTest.php:66 C:\xampp\htdocs\seleniumtest\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase.php:348 C:\xampp\htdocs\seleniumtest\vendor\phpunit\phpunit-selenium\PHPUnit\Extensions\Selenium2TestCase.php:314
ERRORS! Tests: 1, Assertions: 0, Errors: 1.
原文:https://stackoverflow.com/questions/41265019
最满意答案
C ++ 03和C ++ 11的ABI没有区别,因此目标文件不是问题。 您的库可以尽可能多地在内部使用C ++ 11,但C ++ 11语法的头文件不能用于C ++ 03项目,编译器会引发错误。
The ABI of C++03 and C++11 doesn't differ, so object files aren't a problem. Your library can use C++11 internally as much as you want, but headers with C++11 syntax can't be used for C++03 projects, the compiler throws errors.
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
如果您使用的是C ++ 0x兼容的编译器和标准库,则无需执行任何操作即可从第一个示例中获得更好的性能。 get_vector(_n, _m)的返回值是一个临时变量, std::vector的移动构造函数(一个构造函数接受右值引用)将自动被调用,而不再需要进一步的工作。 通常,非库编写者不需要直接使用右值引用; 你只会自动获得相当一部分好处。 If you're using a C++0x-compatible compiler and standard library, you get better per ...
-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
C ++ 11“自动”语义(C++11 “auto” semantics)[2023-03-18]
规则很简单:它是你如何声明它。 int i = 5; auto a1 = i; // value auto & a2 = i; // reference 下一个例子证明: #include#include template< typename T > struct A { static void foo(){ std::cout<< "value" << std::endl; } }; template< typename T > s ... -
如何利用移动语义在C ++ 11中获得更好的性能?(How to take advantage of the Move Semantics for a better performance in C++11?)[2022-06-02]
你使用new是一个红旗,尤其是在std::vector 。 std::vector s支持本地移动语义。 他们是一个内存管理课程。 内存管理类的手动内存管理是一个BIG红旗。 遵循0的规则。 =default你的移动构造函数,移动赋值,复制构造函数,析构函数和复制赋值。 从矢量中删除* 。 不要分配它。 用data->替换data-> data. 你应该做的第二件事是改变: MTensor::Tensor1D scalarProduct1D(MTensor::Tensor1D t1, double scal ... -
你不能复制和移动一次,除非你改变你的类的设计,并把它们的构造函数转换成(可能是SFINAE约束的)模板化转发构造函数( Yakk的答案显示了如何 )。 虽然这样做可以在执行rvalues时执行一次移动和不复制,并且在提供了lvalue时执行一次复制和不移动,但在大多数情况下这是一种矫枉过正的行为。 作为基于模板的转发构造函数的替代方法,您可以在基类和派生类中提供两个构造函数:一个用于右值引用,另一个用于左值引用const 。 但是,在大多数情况下,这是一个不必要的复杂情况(并且在参数数量增加时不能很好地扩展 ...
-
我认为它应该编译: std::make_tuple()的结果是一个临时的std::tuple
,它应该移动构造它的成员。 更确切地说, std::tuple 的移动构造函数是默认的,这应该导致成员移动构造。 显然,没有必要将std::make_tuple()的结果std::make_tuple() t 。 如果您选择引入此变量,则返回时不应该使用std::move(t) :当return语句中的表达式是局部变量时,无论如何它都被视为rvalue。 但是,额外的std::move()禁止 ... -
C ++ 11是否使用移动语义来进行复制到分配的优化?(Does C++11 use move semantics to do copy-to-assign optimization?)[2022-12-16]
在将var传递给some_func时,C ++ 11会自动使用移动语义, 不,这是一个复制结构,因为var是一个左值。 该语言不允许编译器执行其他任何操作。 唯一一次隐式移动左值而不是复制左边是从函数返回它时,例如some_func这一行将使用移动构造函数: return var; 并再次重新分配给var,因为var的原始值无论如何都会被销毁? 这将使用Foo的移动赋值运算符,因为它为var分配了一个rvalue。 如果您使用some_func(std::move(var))或者如果您这样写它,则可以避免 ... -
C ++ 11移动语义(C++11 Move Semantics)[2023-02-05]
getTest(1) + getTest(2) + getTest(3)的结果与Test::operator+(const Test&)的返回类型具有相同的类型。 它是Test& ,因此是左值。 operator +通常是非成员重载,它返回临时值: Test operator + (const Test& a, const Test& b) 要么 Test operator + (Test a, const Test& b) 实现operator +=作为成员的加分点,并在非成员operator+的实现 ... -
从前C ++ 11代码调用C ++ 11库时移动语义(Move semantics when calling a C++11 library from pre-C++11 code)[2023-06-19]
C ++ 03和C ++ 11的ABI没有区别,因此目标文件不是问题。 您的库可以尽可能多地在内部使用C ++ 11,但C ++ 11语法的头文件不能用于C ++ 03项目,编译器会引发错误。 The ABI of C++03 and C++11 doesn't differ, so object files aren't a problem. Your library can use C++11 internally as much as you want, but headers with C++11 ...