I'm using Codeception to write acceptance tests for an app that relies on jQuery. I got the WebDriver to open FireFox and login. JavaScript is enabled, and I can do $I->executeJS('return document.getElementById("some-element")'); which returns the element. For the life of me, I can't access jQuery at all. I know it's loaded because the jQuery plugins on the page are working. I need to interact with then.
So far, I've tried two approaches. The first is that I create a hidden div with an ID when the DOM is ready. Then in my test, I do this:
public function foo(AcceptanceTester $I) {
$I->waitForElement('#dom-ready');
$var = $I->executeJS('return jQuery.fn.jquery');
var_dump($var);
}
That var_dump should return the jQuery version. It's returns null.
I've also tried this:
public function foo(AcceptanceTester $I) {
$I->wait(20); // Some really high number of seconds
$var = $I->executeJS("return window.jQuery != undefined && jQuery.active == 0");
var_dump($var);
}
That var_dump should be true. It's always false. I'm totally at a loss. What am I no seeing here?
Here is my acceptance.suite.yaml file
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://site.local/' # put your local url
browser: firefox
capabilities:
javascriptEnabled: true
handlesAlerts: true
webStorageEnabled: true
- \Helper\Acceptance
$shorthand ?return !window.$ || window.$.active == 0- Florent B.JQuerywas self contained in the$namespace. It could also be due to an issue from the geckodriver. Try thisvar w = window.wrappedJSObject || window; return !w.$ || w.$.active < 1;- Florent B.