A
A
Arx7772015-10-01 15:42:15
PHP
Arx777, 2015-10-01 15:42:15

Why doesn't JQuery work in Codeception Selenium 2.47.1 WebDriver?

Test fails in Codeception Selenium WebDriver

$I = new AcceptanceTester($scenario);
$I->amOnPage('/index.html');
$I->executeJS('return $(window).trigger($.Event("keydown", { keyCode: 39 }));');


Writes an error

[email protected] /v/w/r/test (landing)> php ./vendor/bin/codecept run
Codeception PHP Testing Framework v2.1.2
Powered by PHPUnit 4.8.9 by Sebastian Bergmann and contributors.

Acceptance Tests (2)---------------------------------------------------- --------------
Perform actions and see result (GitHubCept) Ok
WelcomeCept Error
------------------------- -------------------------------------------------- -----

Unit Tests (0) ------------------------------
---------- -----------------------------------

Functional Tests (0)---------- ------------------------------------------------
_ ---------

Time: 11.46 seconds, Memory: 13.50Mb

There was 1 error:

---------
1) WelcomeCept (tests/acceptance//WelcomeCept.php)

[Facebook\WebDriver\Exception\UnknownServerException] $ is not defined
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'localhost', ip: '127.0.0.1', os.name : 'Linux', os.arch: 'amd64', os.version: '4.1.6-200.fc22.x86_64+debug', java.version: '1.8.0_45'
Driver info: driver.version: unknown

Scenario Steps :

2. $I->executeJS("$(window).trigger($.Event("keydown", { keyCode: 39 }));")
1. $I->amOnPage("/index.html")

#1 /var/www/rabota.redcube.loc/test/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:287
#2 /var/www/rabota.redcube.loc/test/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:507
#3 /var/www/rabota.redcube.loc/test/vendor/facebook/webdriver /lib/Remote/RemoteWebDriver.php:286
#4 Codeception\Module\WebDriver->executeJS
#5 /var/www/rabota.redcube.loc/test/tests/_support/_generated/AcceptanceTesterActions.php:2312
#6 /var /www/rabota.redcube.loc/test/tests/acceptance/WelcomeCept.php:32

FAILURES!
Tests: 2, Assertions: 0, Errors: 1.


PS Simple JS code passes the test
PSS jQuery is connected in the browser console everything works fine

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivanq, 2015-10-01
@Arx777

jQuery not included?

A
Arx777, 2015-10-01
@Arx777

Decided this way

$I = new AcceptanceTester($scenario);
$I->amOnPage('/index.html');
$I->executeJS("
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = ' code.jquery.com/jquery-1.8.3.js ';
document .head.appendChild(script);
");
$I->executeJS('$(window).trigger($.Event("keydown", { keyCode: 39 }));');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question